Linux Headquarters
[ Register ]
[ About us ] [ Home Page ]

Advertisement
[ Kernel ] [ Documentation ] [ Links ] [ Books ]

Advertisement

Kernel v2.4.20-pre1-ac1 /kernel/exit.c

Filename:/kernel/exit.c
Lines Added:87
Lines Deleted:41
Also changed in: (Previous) 2.4.19-ac4  2.4.19-ac3  2.4.19-ac2  2.4.19-ac1  2.4.19  2.4.19-rc5-ac1 
(Following) 2.4.20-pre1-ac2  2.4.20-pre1-ac3  2.4.20-pre2-ac1  2.4.20-pre2-ac2  2.4.20-pre2-ac3  2.4.20-pre2-ac4 

Location
[  2.4.20-pre1-ac1
  [  kernel
     o  exit.c

Patch

diff -u --new-file --recursive --exclude-from /usr/src/exclude linux.20pre1/kernel/exit.c linux.20pre1-ac1/kernel/exit.c
--- linux.20pre1/kernel/exit.c   2002-08-06 15:40:34.000000000 +0100
+++ linux.20pre1-ac1/kernel/exit.c   2002-08-06 15:41:51.000000000 +0100
@@ -28,49 +28,22 @@
 
 static void release_task(struct task_struct * p)
 {
-   if (p != current) {
+   if (p == current)
+      BUG();
 #ifdef CONFIG_SMP
-      /*
-       * Wait to make sure the process isn't on the
-       * runqueue (active on some other CPU still)
-       */
-      for (;;) {
-         task_lock(p);
-         if (!task_has_cpu(p))
-            break;
-         task_unlock(p);
-         do {
-            cpu_relax();
-            barrier();
-         } while (task_has_cpu(p));
-      }
-      task_unlock(p);
+   wait_task_inactive(p);
 #endif
-      atomic_dec(&p->user->processes);
-      free_uid(p->user);
-      unhash_process(p);
-
-      release_thread(p);
-      current->cmin_flt += p->min_flt + p->cmin_flt;
-      current->cmaj_flt += p->maj_flt + p->cmaj_flt;
-      current->cnswap += p->nswap + p->cnswap;
-      /*
-       * Potentially available timeslices are retrieved
-       * here - this way the parent does not get penalized
-       * for creating too many processes.
-       *
-       * (this cannot be used to artificially 'generate'
-       * timeslices, because any timeslice recovered here
-       * was given away by the parent in the first place.)
-       */
-      current->counter += p->counter;
-      if (current->counter >= MAX_COUNTER)
-         current->counter = MAX_COUNTER;
-      p->pid = 0;
-      free_task_struct(p);
-   } else {
-      printk("task releasing itself\n");
-   }
+   atomic_dec(&p->user->processes);
+   free_uid(p->user);
+   unhash_process(p);
+
+   release_thread(p);
+   current->cmin_flt += p->min_flt + p->cmin_flt;
+   current->cmaj_flt += p->maj_flt + p->cmaj_flt;
+   current->cnswap += p->nswap + p->cnswap;
+   sched_exit(p);
+   p->pid = 0;
+   free_task_struct(p);
 }
 
 /*
@@ -150,6 +123,79 @@
    return retval;
 }
 
+/**
+ * reparent_to_init() - Reparent the calling kernel thread to the init task.
+ *
+ * If a kernel thread is launched as a result of a system call, or if
+ * it ever exits, it should generally reparent itself to init so that
+ * it is correctly cleaned up on exit.
+ *
+ * The various task state such as scheduling policy and priority may have
+ * been inherited from a user process, so we reset them to sane values here.
+ *
+ * NOTE that reparent_to_init() gives the caller full capabilities.
+ */
+void reparent_to_init(void)
+{
+   write_lock_irq(&tasklist_lock);
+
+   /* Reparent to init */
+   REMOVE_LINKS(current);
+   current->p_pptr = child_reaper;
+   current->p_opptr = child_reaper;
+   SET_LINKS(current);
+
+   /* Set the exit signal to SIGCHLD so we signal init on exit */
+   current->exit_signal = SIGCHLD;
+
+   current->ptrace = 0;
+   if ((current->policy == SCHED_OTHER) && (task_nice(current) < 0))
+      set_user_nice(current, 0);
+   /* cpus_allowed? */
+   /* rt_priority? */
+   /* signals? */
+   current->cap_effective = CAP_INIT_EFF_SET;
+   current->cap_inheritable = CAP_INIT_INH_SET;
+   current->cap_permitted = CAP_FULL_SET;
+   current->keep_capabilities = 0;
+   memcpy(current->rlim, init_task.rlim, sizeof(*(current->rlim)));
+   current->user = INIT_USER;
+
+   write_unlock_irq(&tasklist_lock);
+}
+
+/*
+ *   Put all the gunge required to become a kernel thread without
+ *   attached user resources in one place where it belongs.
+ */
+
+void daemonize(void)
+{
+   struct fs_struct *fs;
+
+
+   /*
+    * If we were started as result of loading a module, close all of the
+    * user space pages.  We don't need them, and if we didn't close them
+    * they would be locked into memory.
+    */
+   exit_mm(current);
+
+   current->session = 1;
+   current->pgrp = 1;
+   current->tty = NULL;
+
+   /* Become as one with the init task */
+
+   exit_fs(current);   /* current->fs->count--; */
+   fs = init_task.fs;
+   current->fs = fs;
+   atomic_inc(&fs->count);
+    exit_files(current);
+   current->files = init_task.files;
+   atomic_inc(¤t->files->count);
+}
+
 /*
  * When we die, we re-parent all our children.
  * Try to give them to another thread in our thread


Comments: webmaster (at) linuxhq.com.
Advertising: banners (at) linuxhq.com.
Compilation ©1998-2008 Linux Headquarters, Inc.