This patch fixes a problem that smbd process for LPQ thread is orphaned if the parent smbd is aborted. See also: https://bugzilla.samba.org/show_bug.cgi?id=5688 -- fumiyas, 2008-12-09 diff -rup samba-3.2.4/source/printing/printing.c samba-3.2.4.osstech/source/printing/printing.c --- samba-3.2.4/source/printing/printing.c 2008-09-18 15:49:02.000000000 +0900 +++ samba-3.2.4.osstech/source/printing/printing.c 2008-12-09 18:53:14.000000000 +0900 @@ -1394,7 +1394,23 @@ main thread of the background lpq update ****************************************************************************/ void start_background_queue(void) { + static int pause_pipe[2] = {-1, -1}; + DEBUG(3,("start_background_queue: Starting background LPQ thread\n")); + + if (pause_pipe[0] >= 0) { + close(pause_pipe[0]); + pause_pipe[0] = -1; + } + if (pause_pipe[1] >= 0) { + close(pause_pipe[1]); + pause_pipe[1] = -1; + } + if (pipe(pause_pipe) == -1) { + DEBUG(5,("start_background_queue: cannot create pipe. %s\n", strerror(errno) )); + exit(1); + } + background_lpq_updater_pid = sys_fork(); if (background_lpq_updater_pid == -1) { @@ -1406,6 +1422,9 @@ void start_background_queue(void) /* Child. */ DEBUG(5,("start_background_queue: background LPQ thread started\n")); + close(pause_pipe[0]); + pause_pipe[0] = -1; + if (!reinit_after_fork(smbd_messaging_context(), true)) { DEBUG(0,("reinit_after_fork() failed\n")); smb_panic("reinit_after_fork() failed"); @@ -1423,7 +1442,17 @@ void start_background_queue(void) DEBUG(5,("start_background_queue: background LPQ thread waiting for messages\n")); while (1) { - pause(); + fd_set pause_fds; + int pause_select; + + FD_ZERO(&pause_fds); + FD_SET(pause_pipe[1], &pause_fds); + pause_select = sys_select(pause_pipe[1]+1, &pause_fds, NULL, NULL, NULL); + /* pause_pipe[0] is closed, i.e. parent smbd and + children are aborted. */ + if (pause_select == 1) { + exit_server_cleanly(NULL); + } /* check for some essential signals first */ @@ -1449,6 +1478,9 @@ void start_background_queue(void) 0); } } + + close(pause_pipe[1]); + pause_pipe[1] = -1; } /**************************************************************************** samba-3.2.4.osstech/source/printingだけに発見: printing.c.old