2 * linux/kernel/vserver/helper.c
4 * Virtual Context Support
6 * Copyright (C) 2004-2005 Herbert Pƶtzl
12 #include <linux/config.h>
13 #include <linux/errno.h>
14 #include <linux/reboot.h>
15 #include <linux/kmod.h>
16 #include <linux/sched.h>
17 #include <linux/vs_context.h>
19 #include <asm/uaccess.h>
20 #include <asm/unistd.h>
23 char vshelper_path[255] = "/sbin/vshelper";
27 * vshelper path is set via /proc/sys
28 * invoked by vserver sys_reboot(), with
29 * the following arguments
31 * argv [0] = vshelper_path;
32 * argv [1] = action: "restart", "halt", "poweroff", ...
33 * argv [2] = context identifier
35 * envp [*] = type-specific parameters
38 long vs_reboot(unsigned int cmd, void * arg)
40 char id_buf[8], cmd_buf[16];
41 char uid_buf[16], pid_buf[16];
43 char *argv[] = {vshelper_path, NULL, id_buf, 0};
44 char *envp[] = {"HOME=/", "TERM=linux",
45 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
46 uid_buf, pid_buf, cmd_buf, 0};
48 snprintf(id_buf, sizeof(id_buf)-1, "%d", vx_current_xid());
50 snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
51 snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current->uid);
52 snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
55 case LINUX_REBOOT_CMD_RESTART:
59 case LINUX_REBOOT_CMD_HALT:
63 case LINUX_REBOOT_CMD_POWER_OFF:
67 case LINUX_REBOOT_CMD_SW_SUSPEND:
76 /* maybe we should wait ? */
77 if (call_usermodehelper(*argv, argv, envp, 1)) {
79 "vs_reboot(): failed to exec (%s %s %s)\n",
80 vshelper_path, argv[1], argv[2]);
86 long vs_context_state(unsigned int cmd)
88 char id_buf[8], cmd_buf[32];
90 char *argv[] = {vshelper_path, NULL, id_buf, NULL, 0};
91 char *envp[] = {"HOME=/", "TERM=linux",
92 "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
94 snprintf(id_buf, sizeof(id_buf)-1, "%d", vx_current_xid());
95 snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
98 case VS_CONTEXT_CREATED:
101 case VS_CONTEXT_DESTROY:
102 argv[1] = "shutdown";
108 if (call_usermodehelper(*argv, argv, envp, 1)) {
110 "vs_context_state(): failed to exec (%s %s %s %s)\n",
111 vshelper_path, argv[1], argv[2], argv[3]);