2 Unix SMB/Netbios implementation.
4 Copyright (C) Simo Sorce 2010
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "librpc/gen_ndr/messaging.h"
21 #include "include/printing.h"
22 #include "rpc_server/rpc_server.h"
24 #define SPOOLSS_PIPE_NAME "spoolss"
27 static void spoolss_reopen_logs(void)
32 ret = asprintf(&lfile, "%s.spoolssd", lp_logfile());
34 lp_set_logfile(lfile);
40 static void smb_conf_updated(struct messaging_context *msg,
43 struct server_id server_id,
46 DEBUG(10, ("Got message saying smb.conf was updated. Reloading.\n"));
47 change_to_root_user();
49 spoolss_reopen_logs();
52 static void spoolss_sig_term_handler(struct tevent_context *ev,
53 struct tevent_signal *se,
59 exit_server_cleanly("termination signal");
62 static void spoolss_setup_sig_term_handler(void)
64 struct tevent_signal *se;
66 se = tevent_add_signal(server_event_context(),
67 server_event_context(),
69 spoolss_sig_term_handler,
72 exit_server("failed to setup SIGTERM handler");
76 static void spoolss_sig_hup_handler(struct tevent_context *ev,
77 struct tevent_signal *se,
83 change_to_root_user();
84 DEBUG(1,("Reloading printers after SIGHUP\n"));
85 reload_printers(server_messaging_context());
86 spoolss_reopen_logs();
89 static void spoolss_setup_sig_hup_handler(void)
91 struct tevent_signal *se;
93 se = tevent_add_signal(server_event_context(),
94 server_event_context(),
96 spoolss_sig_hup_handler,
99 exit_server("failed to setup SIGHUP handler");
103 void start_spoolssd(void)
109 DEBUG(1, ("Forking SPOOLSS Daemon\n"));
114 DEBUG(0, ("Failed to fork SPOOLSS [%s], aborting ...\n",
125 close_low_fds(false);
127 status = reinit_after_fork(server_messaging_context(),
128 server_event_context(),
129 procid_self(), true);
130 if (!NT_STATUS_IS_OK(status)) {
131 DEBUG(0,("reinit_after_fork() failed\n"));
132 smb_panic("reinit_after_fork() failed");
135 spoolss_reopen_logs();
137 spoolss_setup_sig_term_handler();
138 spoolss_setup_sig_hup_handler();
140 if (!serverid_register(procid_self(),
141 FLAG_MSG_GENERAL|FLAG_MSG_SMBD
142 |FLAG_MSG_PRINT_GENERAL)) {
146 if (!locking_init()) {
150 messaging_register(server_messaging_context(), NULL,
151 MSG_PRINTER_UPDATE, print_queue_receive);
152 messaging_register(server_messaging_context(), NULL,
153 MSG_SMB_CONF_UPDATED, smb_conf_updated);
155 if (!setup_named_pipe_socket(SPOOLSS_PIPE_NAME, server_event_context())) {
160 ret = tevent_loop_wait(server_event_context());
162 /* should not be reached */
163 DEBUG(0,("background_queue: tevent_loop_wait() exited with %d - %s\n",
164 ret, (ret == 0) ? "out of events" : strerror(errno)));