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";
26 int do_vshelper(char *name, char *argv[], char *envp[], int sync)
30 if ((ret = call_usermodehelper(name, argv, envp, sync))) {
32 "%s: (%s %s) returned %s with %d\n",
33 name, argv[1], argv[2],
34 sync?"sync":"async", ret);
36 vxdprintk(VXD_CBIT(switch, 1),
37 "%s: (%s %s) returned %s with %d",
38 name, argv[1], argv[2], sync?"sync":"async", ret);
43 * vshelper path is set via /proc/sys
44 * invoked by vserver sys_reboot(), with
45 * the following arguments
47 * argv [0] = vshelper_path;
48 * argv [1] = action: "restart", "halt", "poweroff", ...
49 * argv [2] = context identifier
51 * envp [*] = type-specific parameters
54 long vs_reboot(unsigned int cmd, void * arg)
56 char id_buf[8], cmd_buf[16];
57 char uid_buf[16], pid_buf[16];
59 char *argv[] = {vshelper_path, NULL, id_buf, 0};
60 char *envp[] = {"HOME=/", "TERM=linux",
61 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
62 uid_buf, pid_buf, cmd_buf, 0};
64 snprintf(id_buf, sizeof(id_buf)-1, "%d", vx_current_xid());
66 snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
67 snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current->uid);
68 snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
71 case LINUX_REBOOT_CMD_RESTART:
75 case LINUX_REBOOT_CMD_HALT:
79 case LINUX_REBOOT_CMD_POWER_OFF:
83 case LINUX_REBOOT_CMD_SW_SUSPEND:
91 if (do_vshelper(vshelper_path, argv, envp, 1))
98 * argv [0] = vshelper_path;
99 * argv [1] = action: "startup", "shutdown"
100 * argv [2] = context identifier
102 * envp [*] = type-specific parameters
105 long vs_state_change(struct vx_info *vxi, unsigned int cmd)
107 char id_buf[8], cmd_buf[16];
108 char *argv[] = {vshelper_path, NULL, id_buf, 0};
109 char *envp[] = {"HOME=/", "TERM=linux",
110 "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
112 snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
113 snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
120 argv[1] = "shutdown";
126 do_vshelper(vshelper_path, argv, envp, 1);