1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15#include <sys/reboot.h> 16#include <sys/syscall.h> 17#include <unistd.h> 18#include <sched.h> 19 20#include "init_cmdexecutor.h" 21#include "init_module_engine.h" 22 23#define REBOOT_MAGIC1 0xfee1dead 24#define REBOOT_MAGIC2 672274793 25#define REBOOT_CMD_RESTART2 0xA1B2C3D4 26static int DoRebootLoader(int id, const char *name, int argc, const char **argv) 27{ 28 // by job to stop service and unmount 29 DoJobNow("reboot"); 30 syscall(__NR_reboot, REBOOT_MAGIC1, REBOOT_MAGIC2, REBOOT_CMD_RESTART2, "loader"); 31 return 0; 32} 33 34MODULE_CONSTRUCTOR(void) 35{ 36 AddRebootCmdExecutor("loader", DoRebootLoader); 37}