| | 284 | | static void process_exec(PROCESS_REC *rec, const char *cmd) |
| | 285 | | { |
| | 286 | | const char *shell_args[4] = { "/bin/sh", "-c", NULL, NULL };
|
| | 287 | | char **args; |
| | 288 | | int in[2], out[2]; |
| | 289 | | int n; |
| | 290 | | |
| | 291 | | if (pipe(in) == -1) |
| | 292 | | return; |
| | 293 | | if (pipe(out) == -1) |
| | 294 | | return; |
| | 295 | | |
| | 296 | | shell_args[2] = cmd; |
| | 297 | | rec->pid = fork(); |
| | 298 | | if (rec->pid == -1) { |
| | 299 | | |
| | 300 | | close(in[0]); close(in[1]); |
| | 301 | | close(out[0]); close(out[1]); |
| | 302 | | return; |
| | 303 | | } |
| | 304 | | |
| | 305 | | if (rec->pid != 0) { |
| | 306 | | |
| | 307 | | GIOChannel *outio = g_io_channel_unix_new(in[1]); |
| | 308 | | |
| | 309 | | rec->in = g_io_channel_unix_new(out[0]); |
| | 310 | | rec->out = net_sendbuffer_create(outio, 0); |
| | 311 | | |
| | 312 | | close(out[1]); |
| | 313 | | close(in[0]); |
| | 314 | | pidwait_add(rec->pid); |
| | 315 | | return; |
| | 316 | | } |
| | 317 | | |
| | 318 | | |
| | 319 | | setsid(); |
| | 320 | | setuid(getuid()); |
| | 321 | | setgid(getgid()); |
| | 322 | | signal(SIGINT, SIG_IGN);
|
| | 323 | | signal(SIGQUIT, SIG_DFL);
|
| | 324 | | |
| | 325 | | putenv("TERM=tty"); |
| | 326 | | |
| | 327 | | |
| | 328 | | dup2(in[0], STDIN_FILENO);
|
| | 329 | | dup2(out[1], STDOUT_FILENO);
|
| allocated and leaked | 330 | | dup2(out[1], STDERR_FILENO);
|
| | 331 | | |
| | 332 | | |
| | 333 | | for (n = 3; n < 256; n++) |