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>
18 #include <linux/vs_network.h>
20 #include <asm/uaccess.h>
21 #include <asm/unistd.h>
24 char vshelper_path[255] = "/sbin/vshelper";
27 int do_vshelper(char *name, char *argv[], char *envp[], int sync)
31 if ((ret = call_usermodehelper(name, argv, envp, sync))) {
33 "%s: (%s %s) returned %s with %d\n",
34 name, argv[1], argv[2],
35 sync?"sync":"async", ret);
37 vxdprintk(VXD_CBIT(switch, 4),
38 "%s: (%s %s) returned %s with %d",
39 name, argv[1], argv[2], sync?"sync":"async", ret);
44 * vshelper path is set via /proc/sys
45 * invoked by vserver sys_reboot(), with
46 * the following arguments
48 * argv [0] = vshelper_path;
49 * argv [1] = action: "restart", "halt", "poweroff", ...
50 * argv [2] = context identifier
52 * envp [*] = type-specific parameters
55 long vs_reboot(unsigned int cmd, void * arg)
57 char id_buf[8], cmd_buf[16];
58 char uid_buf[16], pid_buf[16];
61 char *argv[] = {vshelper_path, NULL, id_buf, 0};
62 char *envp[] = {"HOME=/", "TERM=linux",
63 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
64 uid_buf, pid_buf, cmd_buf, 0};
66 snprintf(id_buf, sizeof(id_buf)-1, "%d", vx_current_xid());
68 snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
69 snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current->uid);
70 snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
73 case LINUX_REBOOT_CMD_RESTART:
77 case LINUX_REBOOT_CMD_HALT:
81 case LINUX_REBOOT_CMD_POWER_OFF:
85 case LINUX_REBOOT_CMD_SW_SUSPEND:
93 #ifndef CONFIG_VSERVER_LEGACY
94 ret = do_vshelper(vshelper_path, argv, envp, 1);
96 ret = do_vshelper(vshelper_path, argv, envp, 0);
98 return (ret) ? -EPERM : 0;
103 * argv [0] = vshelper_path;
104 * argv [1] = action: "startup", "shutdown"
105 * argv [2] = context identifier
107 * envp [*] = type-specific parameters
110 long vs_state_change(struct vx_info *vxi, unsigned int cmd)
112 char id_buf[8], cmd_buf[16];
113 char *argv[] = {vshelper_path, NULL, id_buf, 0};
114 char *envp[] = {"HOME=/", "TERM=linux",
115 "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
117 if (!vx_info_flags(vxi, VXF_STATE_HELPER, 0))
120 snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
121 snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
128 argv[1] = "shutdown";
134 do_vshelper(vshelper_path, argv, envp, 1);
140 * argv [0] = vshelper_path;
141 * argv [1] = action: "netup", "netdown"
142 * argv [2] = context identifier
144 * envp [*] = type-specific parameters
147 long vs_net_change(struct nx_info *nxi, unsigned int cmd)
149 char id_buf[8], cmd_buf[16];
150 char *argv[] = {vshelper_path, NULL, id_buf, 0};
151 char *envp[] = {"HOME=/", "TERM=linux",
152 "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
154 if (!nx_info_flags(nxi, NXF_STATE_HELPER, 0))
157 snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
158 snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
171 do_vshelper(vshelper_path, argv, envp, 1);