added /usr/local/[s]bin to uml exec path
[strongswan.git] / src / dumm / patches / mconsole-exec-2.6.26.patch
1 --- a/arch/um/drivers/mconsole_kern.c   2008-04-17 04:49:44.000000000 +0200
2 +++ b/arch/um/drivers/mconsole_kern.c   2008-07-09 14:41:42.000000000 +0200
3 @@ -4,6 +4,7 @@
4   * Licensed under the GPL
5   */
6  
7 +#include "linux/kmod.h"
8  #include <linux/console.h>
9  #include <linux/ctype.h>
10  #include <linux/interrupt.h>
11 @@ -18,6 +19,7 @@
12  #include <linux/utsname.h>
13  #include <linux/workqueue.h>
14  #include <linux/mutex.h>
15 +#include <linux/file.h>
16  #include <asm/uaccess.h>
17  
18  #include "init.h"
19 @@ -199,6 +201,44 @@
20  }
21  #endif
22  
23 +void mconsole_exec(struct mc_request *req)
24 +{
25 +       int res, len;
26 +       struct file *out;
27 +       char buf[MCONSOLE_MAX_DATA];
28 +
29 +       char *envp[] = {
30 +               "HOME=/", "TERM=linux",
31 +               "PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin",
32 +               NULL
33 +       };
34 +       char *argv[] = {
35 +               "/bin/sh", "-c",
36 +               req->request.data + strlen("exec "),
37 +               NULL
38 +       };
39 +       res = call_usermodehelper_pipe("/bin/sh", argv, envp, NULL, &out);
40 +       
41 +       if (res < 0) {
42 +               mconsole_reply(req, "call_usermodehelper_pipe failed", 1, 0);
43 +               return;
44 +       }
45 +       
46 +       for (;;) {
47 +               len = out->f_op->read(out, buf, sizeof(buf), 0);
48 +               if (len < 0) {
49 +                       mconsole_reply(req, "reading output failed", 1, 0);
50 +                       break;
51 +               }
52 +               if (len == 0) {
53 +                       mconsole_reply_len(req, buf, len, 0, 0);
54 +                       break;
55 +               }
56 +               mconsole_reply_len(req, buf, len, 0, 1);
57 +       }
58 +       fput(out);
59 +}
60 +
61  void mconsole_proc(struct mc_request *req)
62  {
63         char path[64];
64 @@ -270,6 +310,7 @@
65      stop - pause the UML; it will do nothing until it receives a 'go' \n\
66      go - continue the UML after a 'stop' \n\
67      log <string> - make UML enter <string> into the kernel log\n\
68 +    exec <string> - pass <string> to /bin/sh -c synchronously\n\
69      proc <file> - returns the contents of the UML's /proc/<file>\n\
70      stack <pid> - returns the stack of the specified pid\n\
71  "
72 --- a/arch/um/drivers/mconsole_user.c   2008-05-21 18:34:47.000000000 +0200
73 +++ b/arch/um/drivers/mconsole_user.c   2008-07-07 13:47:13.000000000 +0200
74 @@ -32,6 +32,7 @@
75         { "stop", mconsole_stop, MCONSOLE_PROC },
76         { "go", mconsole_go, MCONSOLE_INTR },
77         { "log", mconsole_log, MCONSOLE_INTR },
78 +       { "exec", mconsole_exec, MCONSOLE_PROC },
79         { "proc", mconsole_proc, MCONSOLE_PROC },
80         { "stack", mconsole_stack, MCONSOLE_INTR },
81  };
82 --- a/arch/um/include/mconsole.h        2008-04-17 04:49:44.000000000 +0200
83 +++ b/arch/um/include/mconsole.h        2008-07-07 13:46:56.000000000 +0200
84 @@ -85,6 +85,7 @@
85  extern void mconsole_stop(struct mc_request *req);
86  extern void mconsole_go(struct mc_request *req);
87  extern void mconsole_log(struct mc_request *req);
88 +extern void mconsole_exec(struct mc_request *req);
89  extern void mconsole_proc(struct mc_request *req);
90  extern void mconsole_stack(struct mc_request *req);
91  
92 --- a/kernel/kmod.c     2008-05-21 18:34:56.000000000 +0200
93 +++ b/kernel/kmod.c     2008-07-08 13:50:37.000000000 +0200
94 @@ -125,6 +125,7 @@
95         enum umh_wait wait;
96         int retval;
97         struct file *stdin;
98 +       struct file *stdout;
99         void (*cleanup)(char **argv, char **envp);
100  };
101  
102 @@ -160,8 +161,26 @@
103                 FD_SET(0, fdt->open_fds);
104                 FD_CLR(0, fdt->close_on_exec);
105                 spin_unlock(&f->file_lock);
106 -
107 -               /* and disallow core files too */
108 +       }
109 +       if (sub_info->stdout) {
110 +               struct files_struct *f = current->files;
111 +               struct fdtable *fdt;
112 +               
113 +               sys_close(1);
114 +               sys_close(2);
115 +               get_file(sub_info->stdout);
116 +               fd_install(1, sub_info->stdout);
117 +               fd_install(2, sub_info->stdout);
118 +               spin_lock(&f->file_lock);
119 +               fdt = files_fdtable(f);
120 +               FD_SET(1, fdt->open_fds);
121 +               FD_CLR(1, fdt->close_on_exec);
122 +               FD_SET(2, fdt->open_fds);
123 +               FD_CLR(2, fdt->close_on_exec);
124 +               spin_unlock(&f->file_lock);
125 +       }
126 +       if (sub_info->stdin || sub_info->stdout) {
127 +               /* disallow core files */
128                 current->signal->rlim[RLIMIT_CORE] = (struct rlimit){0, 0};
129         }
130  
131 @@ -433,6 +452,29 @@
132  }
133  EXPORT_SYMBOL(call_usermodehelper_stdinpipe);
134  
135 +int call_usermodehelper_stdoutpipe(struct subprocess_info *sub_info,
136 +                                 struct file **filp)
137 +{
138 +       struct file *f;
139 +
140 +       f = create_write_pipe();
141 +       if (IS_ERR(f))
142 +               return PTR_ERR(f);
143 +       sub_info->stdout = f;
144 +
145 +       f = create_read_pipe(f);
146 +       if (IS_ERR(f)) {
147 +               free_write_pipe(sub_info->stdout);
148 +               sub_info->stdout = NULL;
149 +               return PTR_ERR(f);
150 +       }
151 +       *filp = f;
152 +
153 +       return 0;
154 +}
155 +EXPORT_SYMBOL(call_usermodehelper_stdoutpipe);
156 +
157 +
158  /**
159   * call_usermodehelper_exec - start a usermode application
160   * @sub_info: information about the subprocessa
161 @@ -489,7 +531,7 @@
162   * lower-level call_usermodehelper_* functions.
163   */
164  int call_usermodehelper_pipe(char *path, char **argv, char **envp,
165 -                            struct file **filp)
166 +                            struct file **in, struct file **out)
167  {
168         struct subprocess_info *sub_info;
169         int ret;
170 @@ -498,9 +540,17 @@
171         if (sub_info == NULL)
172                 return -ENOMEM;
173  
174 -       ret = call_usermodehelper_stdinpipe(sub_info, filp);
175 -       if (ret < 0)
176 -               goto out;
177 +       if (in) {
178 +               ret = call_usermodehelper_stdinpipe(sub_info, in);
179 +               if (ret < 0)
180 +                       goto out;
181 +       }
182 +
183 +       if (out) {
184 +               ret = call_usermodehelper_stdoutpipe(sub_info, out);
185 +               if (ret < 0)
186 +                       goto out;
187 +       }
188  
189         return call_usermodehelper_exec(sub_info, UMH_WAIT_EXEC);
190  
191 --- a/include/linux/kmod.h      2008-04-17 04:49:44.000000000 +0200
192 +++ b/include/linux/kmod.h      2008-07-08 10:29:29.000000000 +0200
193 @@ -93,6 +93,6 @@
194  
195  struct file;
196  extern int call_usermodehelper_pipe(char *path, char *argv[], char *envp[],
197 -                                   struct file **filp);
198 +                                   struct file **in, struct file **out);
199  
200  #endif /* __LINUX_KMOD_H__ */
201 --- a/fs/exec.c 2008-06-05 14:00:42.000000000 +0200
202 +++ b/fs/exec.c 2008-07-08 10:28:33.000000000 +0200
203 @@ -1737,7 +1737,7 @@
204  
205                 /* SIGPIPE can happen, but it's just never processed */
206                 if (call_usermodehelper_pipe(corename+1, helper_argv, NULL,
207 -                               &file)) {
208 +                               &file, NULL)) {
209                         printk(KERN_INFO "Core dump to %s pipe failed\n",
210                                corename);
211                         goto fail_unlock;