[pulseaudio-commits] r1152 - /trunk/src/modules/gconf/module-gconf.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Wed Jul 26 11:28:34 PDT 2006


Author: lennart
Date: Wed Jul 26 20:28:31 2006
New Revision: 1152

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1152&root=pulseaudio&view=rev
Log:
add some protection that the gconf helper process will be killed when the daemon process dies. make sure the gconf helper process doesn't keep open file descriptors belonging to the daemon; if gconf helper path

Modified:
    trunk/src/modules/gconf/module-gconf.c

Modified: trunk/src/modules/gconf/module-gconf.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/gconf/module-gconf.c?rev=1152&root=pulseaudio&r1=1151&r2=1152&view=diff
==============================================================================
--- trunk/src/modules/gconf/module-gconf.c (original)
+++ trunk/src/modules/gconf/module-gconf.c Wed Jul 26 20:28:31 2006
@@ -31,6 +31,14 @@
 #include <signal.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <fcntl.h>
+
+#ifdef HAVE_SYS_PRCTL_H
+#include <sys/prctl.h>
+#endif
+#ifdef HAVE_SYS_RESOURCE_H
+#include <sys/resource.h>
+#endif
 
 #include <pulsecore/module.h>
 #include <pulsecore/core.h>
@@ -51,8 +59,8 @@
 #define MAX_MODULES 10
 #define BUF_MAX 2048
 
-#undef PA_GCONF_HELPER
-#define PA_GCONF_HELPER "/home/lennart/projects/pulseaudio/src/gconf-helper"
+/* #undef PA_GCONF_HELPER */
+/* #define PA_GCONF_HELPER "/home/lennart/projects/pulseaudio/src/gconf-helper" */
 
 struct module_info {
     char *name;
@@ -271,7 +279,15 @@
 
     struct userdata *u = userdata;
 
-    handle_event(u);
+    if (handle_event(u) < 0) {
+        
+        if (u->io_event) {
+            u->core->mainloop->io_free(u->io_event);
+            u->io_event = NULL;
+        }
+            
+        pa_module_unload_request(u->module);
+    }
 }
 
 static int start_client(const char *n, pid_t *pid) {
@@ -296,7 +312,8 @@
 
         return pipe_fds[0];
     } else {
-
+        int max_fd, i;
+        
         /* child */
 
         close(pipe_fds[0]);
@@ -304,6 +321,39 @@
 
         if (pipe_fds[1] != 1)
             close(pipe_fds[1]);
+
+        close(0);
+        open("/dev/null", O_RDONLY);
+
+        close(2);
+        open("/dev/null", O_WRONLY);
+
+        max_fd = 1024;
+        
+#ifdef HAVE_SYS_RESOURCE_H
+        {
+            struct rlimit r;
+            if (getrlimit(RLIMIT_NOFILE, &r) == 0)
+                max_fd = r.rlim_max;
+        }
+#endif
+                
+        for (i = 3; i < max_fd; i++)
+            close(i);
+
+#ifdef PR_SET_PDEATHSIG
+        /* On Linux we can use PR_SET_PDEATHSIG to have the helper
+        process killed when the daemon dies abnormally. On non-Linux
+        machines the client will die as soon as it writes data to
+        stdout again (SIGPIPE) */
+
+        prctl(PR_SET_PDEATHSIG, SIGTERM, 0, 0, 0);
+#endif
+
+#ifdef SIGPIPE
+        /* Make sure that SIGPIPE kills the child process */
+        signal(SIGPIPE, SIG_DFL);
+#endif
 
         execl(n, n, NULL);
         _exit(1);




More information about the pulseaudio-commits mailing list