patch-2.0.2 linux/kernel/fork.c

Next file: linux/net/ipv4/af_inet.c
Previous file: linux/kernel/exit.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.0.1/linux/kernel/fork.c linux/kernel/fork.c
@@ -160,22 +160,33 @@
 static inline int copy_files(unsigned long clone_flags, struct task_struct * tsk)
 {
 	int i;
+	struct files_struct *oldf, *newf;
+	struct file **old_fds, **new_fds;
 
+	oldf = current->files;
 	if (clone_flags & CLONE_FILES) {
-		current->files->count++;
+		oldf->count++;
 		return 0;
 	}
-	tsk->files = kmalloc(sizeof(*tsk->files), GFP_KERNEL);
-	if (!tsk->files)
+
+	newf = kmalloc(sizeof(*newf), GFP_KERNEL);
+	tsk->files = newf;
+	if (!newf)
 		return -1;
-	tsk->files->count = 1;
-	memcpy(&tsk->files->close_on_exec, &current->files->close_on_exec,
-		sizeof(tsk->files->close_on_exec));
-	for (i = 0; i < NR_OPEN; i++) {
-		struct file * f = current->files->fd[i];
+			
+	newf->count = 1;
+	newf->close_on_exec = oldf->close_on_exec;
+	newf->open_fds = oldf->open_fds;
+
+	old_fds = oldf->fd;
+	new_fds = newf->fd;
+	for (i = NR_OPEN; i != 0; i--) {
+		struct file * f = *old_fds;
+		old_fds++;
+		*new_fds = f;
+		new_fds++;
 		if (f)
 			f->f_count++;
-		tsk->files->fd[i] = f;
 	}
 	return 0;
 }

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov