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

git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1152 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Lennart Poettering 2006-07-26 18:28:31 +00:00
parent f5d29acdeb
commit b2ad9a9753

View file

@ -31,6 +31,14 @@
#include <signal.h> #include <signal.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.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/module.h>
#include <pulsecore/core.h> #include <pulsecore/core.h>
@ -51,8 +59,8 @@ PA_MODULE_USAGE("")
#define MAX_MODULES 10 #define MAX_MODULES 10
#define BUF_MAX 2048 #define BUF_MAX 2048
#undef PA_GCONF_HELPER /* #undef PA_GCONF_HELPER */
#define PA_GCONF_HELPER "/home/lennart/projects/pulseaudio/src/gconf-helper" /* #define PA_GCONF_HELPER "/home/lennart/projects/pulseaudio/src/gconf-helper" */
struct module_info { struct module_info {
char *name; char *name;
@ -271,7 +279,15 @@ static void io_event_cb(
struct userdata *u = userdata; 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) { static int start_client(const char *n, pid_t *pid) {
@ -296,6 +312,7 @@ static int start_client(const char *n, pid_t *pid) {
return pipe_fds[0]; return pipe_fds[0];
} else { } else {
int max_fd, i;
/* child */ /* child */
@ -305,6 +322,39 @@ static int start_client(const char *n, pid_t *pid) {
if (pipe_fds[1] != 1) if (pipe_fds[1] != 1)
close(pipe_fds[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); execl(n, n, NULL);
_exit(1); _exit(1);
} }