reboot.c revision d028235de9ec7664e1c2c904c541a447a768997a
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen * Copyright © 2012 Serge Hallyn <serge.hallyn@ubuntu.com>.
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen * Copyright © 2012 Canonical Ltd.
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen * This program is free software; you can redistribute it and/or
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen * modify it under the terms of the GNU Lesser General Public
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen * License as published by the Free Software Foundation; either
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen * version 2.1 of the License, or (at your option) any later version.
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen * This library is distributed in the hope that it will be useful,
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen * but WITHOUT ANY WARRANTY; without even the implied warranty of
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen * Lesser General Public License for more details.
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen * You should have received a copy of the GNU Lesser General Public
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen * License along with this library; if not, write to the Free Software
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainenint clone(int (*fn)(void *), void *child_stack, int flags, void *arg, ...);
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen void *stack = alloca(stack_size) + stack_size;
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen ret = clone(do_reboot, stack, CLONE_NEWPID | SIGCHLD, &cmd);
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen printf("child process exited but was not signaled\n");
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen printf("signal termination is not the one expected\n");
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen FILE *f = fopen("/proc/sys/kernel/ctrl-alt-del", "r");
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen ret = reboot(v ? LINUX_REBOOT_CMD_CAD_ON : LINUX_REBOOT_CMD_CAD_OFF);
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen if (getuid() != 0) {
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen printf("Your kernel does not have the container reboot patch\n");
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen status = test_reboot(LINUX_REBOOT_CMD_CAD_ON, -1);
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen printf("reboot(LINUX_REBOOT_CMD_CAD_ON) should have failed\n");
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen printf("reboot(LINUX_REBOOT_CMD_CAD_ON) has failed as expected\n");
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen status = test_reboot(LINUX_REBOOT_CMD_RESTART, SIGHUP);
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen printf("reboot(LINUX_REBOOT_CMD_RESTART) succeed\n");
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen status = test_reboot(LINUX_REBOOT_CMD_RESTART2, SIGHUP);
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen printf("reboot(LINUX_REBOOT_CMD_RESTART2) succeed\n");
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen status = test_reboot(LINUX_REBOOT_CMD_HALT, SIGINT);
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen printf("reboot(LINUX_REBOOT_CMD_HALT) succeed\n");
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen status = test_reboot(LINUX_REBOOT_CMD_POWER_OFF, SIGINT);
5806683c1c3f5b1997e92a023c0fe39912d4df5dTimo Sirainen printf("reboot(LINUX_REBOOT_CMD_POWERR_OFF) succeed\n");