1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

s3-printing: Rework how the background process is started

Signed-off-by: Andreas Schneider <asn@samba.org>
This commit is contained in:
Simo Sorce 2011-08-03 17:04:50 -04:00 committed by Andreas Schneider
parent 0a910c9347
commit 9ce6416673
6 changed files with 42 additions and 21 deletions

View File

@ -1609,6 +1609,8 @@ void print_queue_receive(struct messaging_context *msg,
update the internal database from the system print queue for a queue
****************************************************************************/
extern pid_t background_lpq_updater_pid;
static void print_queue_update(struct messaging_context *msg_ctx,
int snum, bool force)
{

View File

@ -156,15 +156,14 @@ static void printing_pause_fd_handler(struct tevent_context *ev,
exit_server_cleanly(NULL);
}
pid_t background_lpq_updater_pid = -1;
/****************************************************************************
main thread of the background lpq updater
****************************************************************************/
static void start_background_queue(struct tevent_context *ev,
struct messaging_context *msg_ctx)
pid_t start_background_queue(struct tevent_context *ev,
struct messaging_context *msg_ctx)
{
pid_t pid;
/* 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.
@ -178,14 +177,14 @@ static void start_background_queue(struct tevent_context *ev,
exit(1);
}
background_lpq_updater_pid = sys_fork();
pid = sys_fork();
if (background_lpq_updater_pid == -1) {
if (pid == -1) {
DEBUG(5,("start_background_queue: background LPQ thread failed to start. %s\n", strerror(errno) ));
exit(1);
}
if(background_lpq_updater_pid == 0) {
if (pid == 0) {
struct tevent_fd *fde;
int ret;
NTSTATUS status;
@ -206,6 +205,10 @@ static void start_background_queue(struct tevent_context *ev,
bq_setup_sig_term_handler();
bq_setup_sig_hup_handler(ev, msg_ctx);
if (!pcap_cache_loaded()) {
pcap_cache_reload(ev, msg_ctx, &reload_printers);
}
if (!printing_subsystem_queue_tasks(ev, msg_ctx)) {
exit(1);
}
@ -242,39 +245,48 @@ static void start_background_queue(struct tevent_context *ev,
}
close(pause_pipe[1]);
}
static bool use_background_queue;
return pid;
}
/* Run before the parent forks */
bool printing_subsystem_init(struct tevent_context *ev_ctx,
struct messaging_context *msg_ctx,
bool background_queue)
{
bool ret = true;
use_background_queue = background_queue;
pid_t pid = -1;
if (!print_backend_init(msg_ctx)) {
return false;
}
/* Publish nt printers, this requires a working winreg pipe */
pcap_cache_reload(ev_ctx, msg_ctx, &reload_printers);
if (background_queue) {
start_background_queue(ev_ctx, msg_ctx);
pid = start_background_queue(ev_ctx, msg_ctx);
} else {
bool ret;
ret = printing_subsystem_queue_tasks(ev_ctx, msg_ctx);
/* Publish nt printers, this requires a working winreg pipe */
pcap_cache_reload(ev_ctx, msg_ctx, &reload_printers);
return ret;
}
return ret;
if (pid == -1) {
return false;
}
background_lpq_updater_pid = pid;
return true;
}
void printing_subsystem_update(struct tevent_context *ev_ctx,
struct messaging_context *msg_ctx)
{
if (use_background_queue) return;
if (background_lpq_updater_pid != -1) return;
pcap_cache_reload(ev_ctx, msg_ctx, &reload_pcap_change_notify);
}

View File

@ -20,10 +20,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
extern pid_t background_lpq_updater_pid;
bool printing_subsystem_init(struct tevent_context *ev_ctx,
struct messaging_context *msg_ctx,
bool background_queue);
void printing_subsystem_update(struct tevent_context *ev_ctx,
struct messaging_context *msg_ctx);
pid_t start_background_queue(struct tevent_context *ev,
struct messaging_context *msg);

View File

@ -23,6 +23,7 @@
#include "messages.h"
#include "include/printing.h"
#include "printing/nt_printing_migrate_internal.h"
#include "printing/pcap.h"
#include "ntdomain.h"
#include "librpc/gen_ndr/srv_winreg.h"
#include "librpc/gen_ndr/srv_spoolss.h"
@ -695,6 +696,9 @@ void start_spoolssd(struct tevent_context *ev_ctx,
spoolss_reopen_logs();
spoolss_prefork_config();
/* Publish nt printers, this requires a working winreg pipe */
pcap_cache_reload(ev_ctx, msg_ctx, &reload_printers);
/* the listening fd must be created before the children are actually
* forked out. */
listen_fd = create_named_pipe_socket(SPOOLSS_PIPE_NAME);

View File

@ -60,6 +60,7 @@ bool logged_ioctl_message = false;
time_t last_smb_conf_reload_time = 0;
time_t last_printer_reload_time = 0;
pid_t background_lpq_updater_pid = -1;
/****************************************************************************
structure to hold a linked list of queued messages.

View File

@ -66,6 +66,8 @@ extern int trans_num;
extern time_t last_smb_conf_reload_time;
extern time_t last_printer_reload_time;
extern pid_t background_lpq_updater_pid;
/****************************************************************************
structure to hold a linked list of queued messages.
for processing.