2 * TUX - Integrated Application Protocols Layer and Object Cache
4 * Copyright (C) 2000, 2001, Ingo Molnar <mingo@redhat.com>
6 * cgi.c: user-space CGI (and other) code execution.
9 #define __KERNEL_SYSCALLS__
10 #define __KERNEL_SYSCALLS_NO_ERRNO__
14 /****************************************************************
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2, or (at your option)
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 ****************************************************************/
31 static int exec_usermode(char *program_path, char *argv[], char *envp[])
35 err = tux_chroot(tux_cgiroot);
37 printk(KERN_ERR "TUX: CGI chroot returned %d, /proc/sys/net/tux/cgiroot is probably set up incorrectly! Aborting CGI execution.\n", err);
41 /* Allow execve args to be in kernel space. */
44 for (i = 3; i < current->files->max_fds; i++ )
45 if (current->files->fd[i])
48 err = __exec_usermodehelper(program_path, argv, envp);
54 static inline long tux_dup(unsigned int fildes)
57 struct file * file = fget(fildes);
64 static int exec_helper (void * data)
66 exec_param_t *param = data;
70 sprintf(current->comm,"doexec - %d", current->pid);
72 if (!tux_cgi_inherit_cpu) {
75 cpus_and(map, cpu_online_map, tux_cgi_cpu_mask);
77 if (!(cpus_empty(map)))
78 set_cpus_allowed(current, map);
80 set_cpus_allowed(current, cpu_online_map);
86 Dprintk("doing exec(%s).\n", param->command);
91 Dprintk("{%s} ", *tmp);
98 Dprintk("{%s} ", *tmp);
103 * Set up stdin, stdout and stderr of the external
106 if (param->pipe_fds) {
116 // do not close on exec.
117 spin_lock(¤t->files->file_lock);
118 FD_CLR(0, current->files->close_on_exec);
119 FD_CLR(1, current->files->close_on_exec);
120 FD_CLR(2, current->files->close_on_exec);
121 spin_unlock(¤t->files->file_lock);
123 ret = exec_usermode(param->command, param->argv, param->envp);
125 Dprintk("bug: exec() returned %d.\n", ret);
127 Dprintk("exec()-ed successfully!\n");
131 pid_t tux_exec_process (char *command, char **argv,
132 char **envp, int pipe_fds,
133 exec_param_t *param, int wait)
135 exec_param_t param_local;
137 struct k_sigaction *ka;
139 ka = current->sighand->action + SIGCHLD-1;
140 ka->sa.sa_handler = SIG_IGN;
143 param = ¶m_local;
145 param->command = command;
148 param->pipe_fds = pipe_fds;
151 pid = kernel_thread(exec_helper, (void*) param, CLONE_SIGHAND|SIGCHLD);
152 Dprintk("kernel thread created PID %d.\n", pid);
154 printk(KERN_ERR "TUX: could not create new CGI kernel thread due to %d... retrying.\n", pid);
155 current->state = TASK_UNINTERRUPTIBLE;
156 schedule_timeout(HZ);