18d6344f9Sopenharmony_ci/*
28d6344f9Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
38d6344f9Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
48d6344f9Sopenharmony_ci * you may not use this file except in compliance with the License.
58d6344f9Sopenharmony_ci * You may obtain a copy of the License at
68d6344f9Sopenharmony_ci *
78d6344f9Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
88d6344f9Sopenharmony_ci *
98d6344f9Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
108d6344f9Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
118d6344f9Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
128d6344f9Sopenharmony_ci * See the License for the specific language governing permissions and
138d6344f9Sopenharmony_ci * limitations under the License.
148d6344f9Sopenharmony_ci */
158d6344f9Sopenharmony_ci#include <sys/reboot.h>
168d6344f9Sopenharmony_ci#include <sys/syscall.h>
178d6344f9Sopenharmony_ci#include <unistd.h>
188d6344f9Sopenharmony_ci#include <sched.h>
198d6344f9Sopenharmony_ci
208d6344f9Sopenharmony_ci#include "init_cmdexecutor.h"
218d6344f9Sopenharmony_ci#include "init_module_engine.h"
228d6344f9Sopenharmony_ci
238d6344f9Sopenharmony_ci#define REBOOT_MAGIC1       0xfee1dead
248d6344f9Sopenharmony_ci#define REBOOT_MAGIC2       672274793
258d6344f9Sopenharmony_ci#define REBOOT_CMD_RESTART2 0xA1B2C3D4
268d6344f9Sopenharmony_cistatic int DoRebootLoader(int id, const char *name, int argc, const char **argv)
278d6344f9Sopenharmony_ci{
288d6344f9Sopenharmony_ci    // by job to stop service and unmount
298d6344f9Sopenharmony_ci    DoJobNow("reboot");
308d6344f9Sopenharmony_ci    syscall(__NR_reboot, REBOOT_MAGIC1, REBOOT_MAGIC2, REBOOT_CMD_RESTART2, "loader");
318d6344f9Sopenharmony_ci    return 0;
328d6344f9Sopenharmony_ci}
338d6344f9Sopenharmony_ci
348d6344f9Sopenharmony_ciMODULE_CONSTRUCTOR(void)
358d6344f9Sopenharmony_ci{
368d6344f9Sopenharmony_ci    AddRebootCmdExecutor("loader", DoRebootLoader);
378d6344f9Sopenharmony_ci}