Re: [patch] khttpd doesn't detach from the files of its parent

From: Alexander Viro (viro@math.psu.edu)
Date: Wed Oct 18 2000 - 13:14:32 EST


On Wed, 18 Oct 2000, Arjan van de Ven wrote:

> In article <Pine.GSO.4.21.0010181359460.14437-100000@weyl.math.psu.edu> you wrote:
>
> > It should, unless you want to open any files in the thread itself.
>
> Oh damn. kHTTPd does need to open files later on......
>
> Reading the code to exit_files() suggests I actually need put_files_struct()
> instead. Is that function for "public" use? (it isn't static)

put_files_struct() is a destructor, so it won't help here. The following
patch may be of use, though (warning: it's cut-and-paste, so spaces may be
wrong). Linus, what do you think about it? It's "create an empty
files_struct and replace the task->files with it" - thing we can't do via
clone() and may want to (khttpd does).

diff -urN rc10-3-a/include/linux/sched.h rc10-3-b/include/linux/sched.h
--- rc10-3-a/include/linux/sched.h Mon Oct 16 11:44:36 2000
+++ rc10-3-b/include/linux/sched.h Wed Oct 18 17:25:20 2000
@@ -729,6 +729,7 @@
 extern void exit_sighand(struct task_struct *);

 extern void daemonize(void);
+extern int new_files(struct task_struct *);

 extern int do_execve(char *, char **, char **, struct pt_regs *);
 extern int do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long);
diff -urN rc10-3-a/kernel/fork.c rc10-3-b/kernel/fork.c
--- rc10-3-a/kernel/fork.c Tue Sep 12 09:10:59 2000
+++ rc10-3-b/kernel/fork.c Wed Oct 18 17:20:35 2000
@@ -391,6 +391,38 @@
        return i;
 }

+int new_files(struct task_struct * tsk)
+{
+ struct files_struct *oldf, *newf;
+
+ error = -ENOMEM;
+ newf = kmem_cache_alloc(files_cachep, SLAB_KERNEL);
+ if (!newf)
+ goto out;
+
+ atomic_set(&newf->count, 1);
+
+ newf->file_lock = RW_LOCK_UNLOCKED;
+ newf->next_fd = 0;
+ newf->max_fds = NR_OPEN_DEFAULT;
+ newf->max_fdset = __FD_SETSIZE;
+ newf->close_on_exec = &newf->close_on_exec_init;
+ newf->open_fds = &newf->open_fds_init;
+ newf->fd = &newf->fd_array[0];
+ memset(newf->fds, 0, NR_OPEN_DEFAULT * sizeof(struct file *));
+ memset(newf->open_fds->fds_bits, 0, __FD_SETSIZE/8);
+ memset(newf->close_on_exec->fds_bits, 0, __FD_SETSIZE/8);
+
+ task_lock(tsk);
+ oldf = tsk->files;
+ tsk->files = newf;
+ task_unlock(tsk);
+ put_files_struct(oldf);
+ error = 0;
+out:
+ return error;
+}
+
 static int copy_files(unsigned long clone_flags, struct task_struct * tsk)
 {
        struct files_struct *oldf, *newf;
diff -urN rc10-3-a/kernel/ksyms.c rc10-3-b/kernel/ksyms.c
--- rc10-3-a/kernel/ksyms.c Sun Oct 15 10:05:24 2000
+++ rc10-3-b/kernel/ksyms.c Wed Oct 18 17:25:37 2000
@@ -94,6 +94,7 @@
 EXPORT_SYMBOL(exit_files);
 EXPORT_SYMBOL(exit_fs);
 EXPORT_SYMBOL(exit_sighand);
+EXPORT_SYMBOL(new_files);

 /* internal kernel memory management */
 EXPORT_SYMBOL(__alloc_pages);

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Mon Oct 23 2000 - 21:00:13 EST