summaryrefslogtreecommitdiff
path: root/source3/printing/printing.c
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2011-08-01 16:50:51 -0400
committerGünther Deschner <gd@samba.org>2011-08-02 15:28:03 +0200
commit2e8a85ec72f2b23cc2b64caa129429971c2fa8c0 (patch)
treee82a80a21b2236fcf8f1b6d6cc6b666e9c18f816 /source3/printing/printing.c
parentac8096e69d7357bac5430cde1d713a04acf58b57 (diff)
downloadsamba-2e8a85ec72f2b23cc2b64caa129429971c2fa8c0.tar.gz
samba-2e8a85ec72f2b23cc2b64caa129429971c2fa8c0.tar.bz2
samba-2e8a85ec72f2b23cc2b64caa129429971c2fa8c0.zip
s3:smbd - Move printing queue stuff
This way we can properly deal with pcap updates in the background queue process if it is enabled (on by default) and not perform these actions in the main smbd process. Signed-off-by: Günther Deschner <gd@samba.org>
Diffstat (limited to 'source3/printing/printing.c')
-rw-r--r--source3/printing/printing.c114
1 files changed, 1 insertions, 113 deletions
diff --git a/source3/printing/printing.c b/source3/printing/printing.c
index 9dbd516940..f1e2aeb265 100644
--- a/source3/printing/printing.c
+++ b/source3/printing/printing.c
@@ -28,6 +28,7 @@
#include "../librpc/gen_ndr/netlogon.h"
#include "printing/notify.h"
#include "printing/pcap.h"
+#include "printing/queue_process.h"
#include "serverid.h"
#include "smbd/smbd.h"
#include "auth.h"
@@ -1599,119 +1600,6 @@ void print_queue_receive(struct messaging_context *msg,
return;
}
-static void printing_pause_fd_handler(struct tevent_context *ev,
- struct tevent_fd *fde,
- uint16_t flags,
- void *private_data)
-{
- /*
- * If pause_pipe[1] is closed it means the parent smbd
- * and children exited or aborted.
- */
- exit_server_cleanly(NULL);
-}
-
-extern struct child_pid *children;
-extern int num_children;
-
-static void add_child_pid(pid_t pid)
-{
- struct child_pid *child;
-
- child = SMB_MALLOC_P(struct child_pid);
- if (child == NULL) {
- DEBUG(0, ("Could not add child struct -- malloc failed\n"));
- return;
- }
- child->pid = pid;
- DLIST_ADD(children, child);
- num_children += 1;
-}
-
-static pid_t background_lpq_updater_pid = -1;
-
-/****************************************************************************
-main thread of the background lpq updater
-****************************************************************************/
-void start_background_queue(struct tevent_context *ev,
- struct messaging_context *msg_ctx)
-{
- /* Use local variables for this as we don't
- * need to save the parent side of this, just
- * ensure it closes when the process exits.
- */
- int pause_pipe[2];
-
- DEBUG(3,("start_background_queue: Starting background LPQ thread\n"));
-
- 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) {
- DEBUG(5,("start_background_queue: background LPQ thread failed to start. %s\n", strerror(errno) ));
- exit(1);
- }
-
- /* Track the printing pid along with other smbd children */
- add_child_pid(background_lpq_updater_pid);
-
- if(background_lpq_updater_pid == 0) {
- struct tevent_fd *fde;
- int ret;
- NTSTATUS status;
-
- /* Child. */
- DEBUG(5,("start_background_queue: background LPQ thread started\n"));
-
- close(pause_pipe[0]);
- pause_pipe[0] = -1;
-
- status = reinit_after_fork(msg_ctx, ev, procid_self(), true);
-
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0,("reinit_after_fork() failed\n"));
- smb_panic("reinit_after_fork() failed");
- }
-
- smbd_setup_sig_term_handler();
- smbd_setup_sig_hup_handler(ev, msg_ctx);
-
- if (!serverid_register(procid_self(),
- FLAG_MSG_GENERAL|FLAG_MSG_SMBD
- |FLAG_MSG_PRINT_GENERAL)) {
- exit(1);
- }
-
- if (!locking_init()) {
- exit(1);
- }
-
- messaging_register(msg_ctx, NULL, MSG_PRINTER_UPDATE,
- print_queue_receive);
-
- fde = tevent_add_fd(ev, ev, pause_pipe[1], TEVENT_FD_READ,
- printing_pause_fd_handler,
- NULL);
- if (!fde) {
- DEBUG(0,("tevent_add_fd() failed for pause_pipe\n"));
- smb_panic("tevent_add_fd() failed for pause_pipe");
- }
-
- DEBUG(5,("start_background_queue: background LPQ thread waiting for messages\n"));
- ret = tevent_loop_wait(ev);
- /* should not be reached */
- DEBUG(0,("background_queue: tevent_loop_wait() exited with %d - %s\n",
- ret, (ret == 0) ? "out of events" : strerror(errno)));
- exit(1);
- }
-
- close(pause_pipe[1]);
-}
-
/****************************************************************************
update the internal database from the system print queue for a queue
****************************************************************************/