Re: 1.5.x Shutdown

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <linux/unistd.h>
 #include <malloc.h>
 #include <stdarg.h>
+#include <stdlib.h>
 #include <sys/resource.h>
 #include <sys/syscall.h>
 #include <sys/time.h>
@@ -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)
_______________________________________________
vdr mailing list
vdr@xxxxxxxxxxx
http://www.linuxtv.org/cgi-bin/mailman/listinfo/vdr

[Index of Archives]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Util Linux NG]     [Xfree86]     [Big List of Linux Books]     [Fedora Users]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux