From patchwork Tue May 29 19:22:51 2007 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Udo Richter X-Patchwork-Id: 12468 Received: from mail.gmx.net ([213.165.64.20]) by www.linuxtv.org with smtp (Exim 4.63) (envelope-from ) id 1Ht7Hx-00050c-Sz for vdr@linuxtv.org; Tue, 29 May 2007 21:23:25 +0200 Received: (qmail invoked by alias); 29 May 2007 19:22:53 -0000 Received: from Qa0a6.q.pppool.de (EHLO localhost) [89.53.160.166] by mail.gmx.net (mp057) with SMTP; 29 May 2007 21:22:53 +0200 X-Authenticated: #1417946 X-Provags-ID: V01U2FsdGVkX191MAI7kHh1IBi2kMpmIf0WEr7/oD4AiGAYuE2ljE wDgymy75wen8tr Message-ID: <465C7D8B.3070508@gmx.de> Date: Tue, 29 May 2007 21:22:51 +0200 From: Udo Richter User-Agent: Thunderbird 2.0.0.0 (Windows/20070326) MIME-Version: 1.0 To: Chris , VDR Mailing List References: <95097215.20070523170659@p-lost.franken.de> <465B3184.9000507@gmx.de> <1531283438.20070529040604@p-lost.franken.de> In-Reply-To: <1531283438.20070529040604@p-lost.franken.de> X-Y-GMX-Trusted: 0 Subject: Re: [vdr] 1.5.x Shutdown X-BeenThere: vdr@linuxtv.org X-Mailman-Version: 2.1.9 Precedence: list Reply-To: VDR Mailing List List-Id: VDR Mailing List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 May 2007 19:23:26 -0000 Status: O X-Status: X-Keywords: X-UID: 13052 Chris wrote: > If I use an 'empty' shutdown script that just starts with "#!/bin/sh" or > bash or whatever, the script itself becomes a zombie. And if I use a script > with just an empty line, "sh" becomes the zombie. So in either way, > something is wrong and it can not be the script's fault. I've checked this again, and you really have to care about processes even in their own process group. After some research, I think the double-fork trick is the best way to fix this: Make the script a grandchild of VDR and let the intermediate child do an instant wait-friendly exit. This makes the script an orphan that does not get a zombie any more. A patch is attached. > waitpid( -1, &dummy, WNOHANG) called at some place later should do the > trick. Or waitpid() explicitly for the child's PID, if we want to store > the PID anywhere. If the script may run longer than VDR, then VDR cannot wait for it. Thats the problem. Cheers, Udo --- thread.c.bak 2007-05-29 21:07:27.000000000 +0200 +++ thread.c 2007-05-29 21:12:56.000000000 +0200 @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -507,7 +508,7 @@ if (pid > 0) { // parent process int status = 0; - if (!Detached && waitpid(pid, &status, 0) < 0) { + if (waitpid(pid, &status, 0) < 0) { LOG_ERROR; return -1; } @@ -515,6 +516,9 @@ } else { // child process if (Detached) { + // Fork again and let first child die + // Grandchild stays alive without parent + if (fork() > 0) exit(0); // Start a new session pid_t sid = setsid(); if (sid < 0)