public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Udo A. Steinberg" <reality@delusion.de>
To: Andrew Morton <akpm@zip.com.au>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>,
	Linux Kernel <linux-kernel@vger.kernel.org>
Subject: Re: Linux 2.4.8-ac5
Date: Wed, 15 Aug 2001 03:37:50 +0200	[thread overview]
Message-ID: <3B79D26E.CD912961@delusion.de> (raw)
In-Reply-To: <20010814221556.A7704@lightning.swansea.linux.org.uk> <3B79B43D.B9350226@delusion.de> <3B79C3A9.52562F71@zip.com.au>

Andrew Morton wrote:
> 
> Interesting that kpnpbiosd has a ppid of zero, whereas keventd, which
> is started a few statements later has a ppid of one.  hmmm..

[...]

> I bet this ancient reparent-kernel-thread-to-init patch fixes it.  It always
> does.

It does indeed. Nice work, Andrew - works like a charm. Formerly the kpnpbios
thread never exited, which is why the problem never showed, now it exits ok.
I've rediffed your patch against 2.4.8-ac5, because I was getting rejects -
in case Alan wants to apply it to his tree.

Regards,
Udo.

--- linux-vanilla/kernel/sched.c        Wed Aug 15 03:19:24 2001
+++ linux-2.4.8-ac/kernel/sched.c       Wed Aug 15 03:06:31 2001
@@ -35,6 +35,7 @@
 extern void timer_bh(void);
 extern void tqueue_bh(void);
 extern void immediate_bh(void);
+extern struct task_struct *child_reaper;
 
 /*
  * scheduler variables
@@ -1227,32 +1228,53 @@
 /*
  *     Put all the gunge required to become a kernel thread without
  *     attached user resources in one place where it belongs.
+ *
+ *     Kernel 2.4.4-pre3, akpm: reparent the caller
+ *     to init and set the exit signal to SIGCHLD so the thread
+ *     will be properly reaped if it exits.
  */
 
 void daemonize(void)
 {
        struct fs_struct *fs;
-
+       struct task_struct *this_task = current;
 
        /*
         * 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);
+       exit_mm(this_task);
 
-       current->session = 1;
-       current->pgrp = 1;
+       this_task->session = 1;
+       this_task->pgrp = 1;
 
        /* Become as one with the init task */

-       exit_fs(current);       /* current->fs->count--; */
+       exit_fs(this_task);             /* this_task->fs->count--; */
        fs = init_task.fs;
-       current->fs = fs;
+       this_task->fs = fs;
        atomic_inc(&fs->count);
-       exit_files(current);
-       current->files = init_task.files;
-       atomic_inc(&current->files->count);
+       exit_files(this_task);          /* this_task->files->count-- */
+       this_task->files = init_task.files;
+       atomic_inc(&this_task->files->count);
+
+       write_lock_irq(&tasklist_lock);
+
+       /* Reparent to init */
+       REMOVE_LINKS(this_task);
+       this_task->p_pptr = child_reaper;
+       this_task->p_opptr = child_reaper;
+       SET_LINKS(this_task);
+
+       /* Set the exit signal to SIGCHLD so we signal init on exit */
+       if (this_task->exit_signal != 0) {
+               printk(KERN_ERR "task %s' exit_signal %d in daemonize()\n",
+                       this_task->comm, this_task->exit_signal);
+       }
+       this_task->exit_signal = SIGCHLD;
+
+       write_unlock_irq(&tasklist_lock);
 }
 
 void __init init_idle(void)

  reply	other threads:[~2001-08-15  1:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-14 21:15 Linux 2.4.8-ac5 Alan Cox
2001-08-14 23:29 ` Udo A. Steinberg
2001-08-15  0:34   ` Andrew Morton
2001-08-15  1:37     ` Udo A. Steinberg [this message]
2001-08-15 18:09       ` Andrew Morton
2001-08-15  1:36   ` Nathan Walp
2001-08-15 15:00   ` Eli Carter
2001-08-15  7:13 ` Paul
2001-08-15  8:37   ` Rik van Riel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3B79D26E.CD912961@delusion.de \
    --to=reality@delusion.de \
    --cc=akpm@zip.com.au \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox