2 * linux/kernel/vserver/helper.c
4 * Virtual Context Support
6 * Copyright (C) 2004 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
34 * argv [3] = additional argument (restart2)
36 * envp [*] = type-specific parameters
39 long vs_reboot(unsigned int cmd, void * arg)
41 char id_buf[8], cmd_buf[32];
42 char uid_buf[32], pid_buf[32];
45 char *argv[] = {vshelper_path, NULL, id_buf, NULL, 0};
46 char *envp[] = {"HOME=/", "TERM=linux",
47 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
48 uid_buf, pid_buf, cmd_buf, 0};
50 snprintf(id_buf, sizeof(id_buf)-1, "%d", vx_current_xid());
52 snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
53 snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current->uid);
54 snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
57 case LINUX_REBOOT_CMD_RESTART:
61 case LINUX_REBOOT_CMD_HALT:
65 case LINUX_REBOOT_CMD_POWER_OFF:
69 case LINUX_REBOOT_CMD_SW_SUSPEND:
73 case LINUX_REBOOT_CMD_RESTART2:
74 if (strncpy_from_user(&buffer[0], (char *)arg, sizeof(buffer) - 1) < 0)
82 /* maybe we should wait ? */
83 if (call_usermodehelper(*argv, argv, envp, 0)) {
85 "vs_reboot(): failed to exec (%s %s %s %s)\n",
86 vshelper_path, argv[1], argv[2], argv[3]);
92 long vs_context_state(unsigned int cmd)
94 char id_buf[8], cmd_buf[32];
96 char *argv[] = {vshelper_path, NULL, id_buf, NULL, 0};
97 char *envp[] = {"HOME=/", "TERM=linux",
98 "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
100 snprintf(id_buf, sizeof(id_buf)-1, "%d", vx_current_xid());
101 snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
104 case VS_CONTEXT_CREATED:
107 case VS_CONTEXT_DESTROY:
108 argv[1] = "shutdown";
114 if (call_usermodehelper(*argv, argv, envp, 1)) {
116 "vs_context_state(): failed to exec (%s %s %s %s)\n",
117 vshelper_path, argv[1], argv[2], argv[3]);