return 0;
}
-static void pjob_store_notify(const char* sharename, uint32 jobid, struct printjob *old_data,
+static void pjob_store_notify(struct tevent_context *ev,
+ struct messaging_context *msg_ctx,
+ const char* sharename, uint32 jobid,
+ struct printjob *old_data,
struct printjob *new_data)
{
bool new_job = False;
--jerry (i'll feel dirty for this) */
if (new_job) {
- notify_job_submitted(sharename, jobid, new_data->starttime);
- notify_job_username(sharename, jobid, new_data->user);
+ notify_job_submitted(ev, msg_ctx,
+ sharename, jobid, new_data->starttime);
+ notify_job_username(ev, msg_ctx,
+ sharename, jobid, new_data->user);
}
if (new_job || !strequal(old_data->jobname, new_data->jobname))
- notify_job_name(sharename, jobid, new_data->jobname);
+ notify_job_name(ev, msg_ctx,
+ sharename, jobid, new_data->jobname);
/* Job attributes of a new job or attributes that can be
modified. */
if (new_job || !strequal(old_data->jobname, new_data->jobname))
- notify_job_name(sharename, jobid, new_data->jobname);
+ notify_job_name(ev, msg_ctx,
+ sharename, jobid, new_data->jobname);
if (new_job || old_data->status != new_data->status)
- notify_job_status(sharename, jobid, map_to_spoolss_status(new_data->status));
+ notify_job_status(ev, msg_ctx,
+ sharename, jobid,
+ map_to_spoolss_status(new_data->status));
if (new_job || old_data->size != new_data->size)
- notify_job_total_bytes(sharename, jobid, new_data->size);
+ notify_job_total_bytes(ev, msg_ctx,
+ sharename, jobid, new_data->size);
if (new_job || old_data->page_count != new_data->page_count)
- notify_job_total_pages(sharename, jobid, new_data->page_count);
+ notify_job_total_pages(ev, msg_ctx,
+ sharename, jobid, new_data->page_count);
}
/****************************************************************************
Store a job structure back to the database.
****************************************************************************/
-static bool pjob_store(const char* sharename, uint32 jobid, struct printjob *pjob)
+static bool pjob_store(struct tevent_context *ev,
+ struct messaging_context *msg_ctx,
+ const char* sharename, uint32 jobid,
+ struct printjob *pjob)
{
uint32_t tmp;
TDB_DATA old_data, new_data;
{
if ( unpack_pjob( old_data.dptr, old_data.dsize, &old_pjob ) != -1 )
{
- pjob_store_notify( sharename, jobid, &old_pjob , pjob );
+ pjob_store_notify(server_event_context(),
+ msg_ctx,
+ sharename, jobid, &old_pjob,
+ pjob);
talloc_free(old_pjob.devmode);
}
}
else {
/* new job */
- pjob_store_notify( sharename, jobid, NULL, pjob );
+ pjob_store_notify(server_event_context(), msg_ctx,
+ sharename, jobid, NULL, pjob);
}
}
Remove a job structure from the database.
****************************************************************************/
-void pjob_delete(const char* sharename, uint32 jobid)
+static void pjob_delete(struct tevent_context *ev,
+ struct messaging_context *msg_ctx,
+ const char* sharename, uint32 jobid)
{
uint32_t tmp;
struct printjob *pjob;
properly. */
job_status = JOB_STATUS_DELETING|JOB_STATUS_DELETED;
- notify_job_status(sharename, jobid, job_status);
+ notify_job_status(ev, msg_ctx, sharename, jobid, job_status);
/* Remove from printing.tdb */
List a unix job in the print database.
****************************************************************************/
-static void print_unix_job(const char *sharename, print_queue_struct *q, uint32 jobid)
+static void print_unix_job(struct tevent_context *ev,
+ struct messaging_context *msg_ctx,
+ const char *sharename, print_queue_struct *q,
+ uint32 jobid)
{
struct printjob pj, *old_pj;
fstrcpy(pj.user, old_pj ? old_pj->user : q->fs_user);
fstrcpy(pj.queuename, old_pj ? old_pj->queuename : sharename );
- pjob_store(sharename, jobid, &pj);
+ pjob_store(ev, msg_ctx, sharename, jobid, &pj);
}
time_t lpq_time;
const char *lprm_command;
struct printif *print_if;
+ struct tevent_context *ev;
+ struct messaging_context *msg_ctx;
};
/****************************************************************************
if (i == ts->qcount) {
DEBUG(10,("traverse_fn_delete: pjob %u deleted due to !smbjob\n",
(unsigned int)jobid ));
- pjob_delete(ts->sharename, jobid);
+ pjob_delete(ts->ev, ts->msg_ctx,
+ ts->sharename, jobid);
return 0;
}
if (!process_exists_by_pid(pjob.pid)) {
DEBUG(10,("traverse_fn_delete: pjob %u deleted due to !process_exists (%u)\n",
(unsigned int)jobid, (unsigned int)pjob.pid ));
- pjob_delete(ts->sharename, jobid);
+ pjob_delete(ts->ev, ts->msg_ctx,
+ ts->sharename, jobid);
} else
ts->total_jobs++;
return 0;
if ( result != 0 ) {
/* if we can't delete, then reset the job status */
pjob.status = LPQ_QUEUED;
- pjob_store(ts->sharename, jobid, &pjob);
+ pjob_store(ts->ev, ts->msg_ctx,
+ ts->sharename, jobid, &pjob);
}
else {
/* if we deleted the job, the remove the tdb record */
- pjob_delete(ts->sharename, jobid);
+ pjob_delete(ts->ev,
+ ts->msg_ctx,
+ ts->sharename, jobid);
pjob.status = LPQ_DELETED;
}
(unsigned int)jobid,
(unsigned int)pjob.starttime,
(unsigned int)ts->lpq_time ));
- pjob_delete(ts->sharename, jobid);
+ pjob_delete(ts->ev, ts->msg_ctx,
+ ts->sharename, jobid);
} else
ts->total_jobs++;
return 0;
main work for updating the lpq cahe for a printer queue
****************************************************************************/
-static void print_queue_update_internal( const char *sharename,
+static void print_queue_update_internal( struct tevent_context *ev,
+ struct messaging_context *msg_ctx,
+ const char *sharename,
struct printif *current_printif,
char *lpq_command, char *lprm_command )
{
if (jobid == (uint32)-1) {
/* assume its a unix print job */
- print_unix_job(sharename, &queue[i], jobid);
+ print_unix_job(ev, msg_ctx,
+ sharename, &queue[i], jobid);
continue;
}
/* err, somethings wrong. Probably smbd was restarted
with jobs in the queue. All we can do is treat them
like unix jobs. Pity. */
- print_unix_job(sharename, &queue[i], jobid);
+ print_unix_job(ev, msg_ctx,
+ sharename, &queue[i], jobid);
continue;
}
if ( pjob->status != LPQ_DELETING )
pjob->status = queue[i].status;
- pjob_store(sharename, jobid, pjob);
+ pjob_store(ev, msg_ctx, sharename, jobid, pjob);
check_job_changed(sharename, jcdata, jobid);
}
tstruct.sharename = sharename;
tstruct.lprm_command = lprm_command;
tstruct.print_if = current_printif;
+ tstruct.ev = ev;
+ tstruct.msg_ctx = msg_ctx;
tdb_traverse(pdb->tdb, traverse_fn_delete, (void *)&tstruct);
/* do the main work now */
- print_queue_update_internal( sharename, current_printif,
- lpq_command, lprm_command );
+ print_queue_update_internal(server_event_context(),
+ server_messaging_context(),
+ sharename, current_printif,
+ lpq_command, lprm_command);
/* Delete our pid from the db. */
set_updating_pid(sharename, False);
/****************************************************************************
main thread of the background lpq updater
****************************************************************************/
-void start_background_queue(void)
+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
close(pause_pipe[0]);
pause_pipe[0] = -1;
- status = reinit_after_fork(server_messaging_context(),
- server_event_context(),
- procid_self(), true);
+ status = reinit_after_fork(msg_ctx, ev, procid_self(), true);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0,("reinit_after_fork() failed\n"));
}
smbd_setup_sig_term_handler();
- smbd_setup_sig_hup_handler();
+ smbd_setup_sig_hup_handler(ev, msg_ctx);
if (!serverid_register(procid_self(),
FLAG_MSG_GENERAL|FLAG_MSG_SMBD
exit(1);
}
- messaging_register(server_messaging_context(), NULL,
- MSG_PRINTER_UPDATE, print_queue_receive);
+ messaging_register(msg_ctx, NULL, MSG_PRINTER_UPDATE,
+ print_queue_receive);
- fde = tevent_add_fd(server_event_context(),
- server_event_context(),
- pause_pipe[1], TEVENT_FD_READ,
+ fde = tevent_add_fd(ev, ev, pause_pipe[1], TEVENT_FD_READ,
printing_pause_fd_handler,
NULL);
if (!fde) {
}
DEBUG(5,("start_background_queue: background LPQ thread waiting for messages\n"));
- ret = tevent_loop_wait(server_event_context());
+ 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)));
update the internal database from the system print queue for a queue
****************************************************************************/
-static void print_queue_update(int snum, bool force)
+static void print_queue_update(struct messaging_context *msg_ctx,
+ int snum, bool force)
{
fstring key;
fstring sharename;
/* finally send the message */
- messaging_send_buf(server_messaging_context(),
- pid_to_procid(background_lpq_updater_pid),
+ messaging_send_buf(msg_ctx, pid_to_procid(background_lpq_updater_pid),
MSG_PRINTER_UPDATE, (uint8 *)buffer, len);
SAFE_FREE( buffer );
return False;
fstrcpy(pjob->jobname, name);
- return pjob_store(sharename, jobid, pjob);
+ return pjob_store(server_event_context(), server_messaging_context(),
+ sharename, jobid, pjob);
}
/****************************************************************************
/* Set the tdb entry to be deleting. */
pjob->status = LPQ_DELETING;
- pjob_store(sharename, jobid, pjob);
+ pjob_store(server_event_context(), server_messaging_context(),
+ sharename, jobid, pjob);
if (pjob->spooled && pjob->sysjob != -1)
{
if (!pdb)
return False;
- pjob_delete(sharename, jobid);
+ pjob_delete(server_event_context(),
+ server_messaging_context(),
+ sharename, jobid);
/* Ensure we keep a rough count of the number of total jobs... */
tdb_change_int32_atomic(pdb->tdb, "INFO/total_jobs", &njobs, -1);
release_print_db(pdb);
/* force update the database and say the delete failed if the
job still exists */
- print_queue_update(snum, True);
+ print_queue_update(msg_ctx, snum, True);
pjob = print_job_find(sharename, jobid);
if (pjob && (pjob->status != LPQ_DELETING)) {
/* Send a printer notify message */
- notify_job_status(sharename, jobid, JOB_STATUS_PAUSED);
+ notify_job_status(server_event_context(), msg_ctx, sharename, jobid,
+ JOB_STATUS_PAUSED);
/* how do we tell if this succeeded? */
/* Send a printer notify message */
- notify_job_status(sharename, jobid, JOB_STATUS_QUEUED);
+ notify_job_status(server_event_context(), msg_ctx, sharename, jobid,
+ JOB_STATUS_QUEUED);
return True;
}
if (return_code>0) {
pjob->size += size;
- pjob_store(sharename, jobid, pjob);
+ pjob_store(server_event_context(), server_messaging_context(),
+ sharename, jobid, pjob);
}
return return_code;
}
Determine the number of jobs in a queue.
****************************************************************************/
-int print_queue_length(int snum, print_status_struct *pstatus)
+int print_queue_length(struct messaging_context *msg_ctx, int snum,
+ print_status_struct *pstatus)
{
const char* sharename = lp_const_servicename( snum );
print_status_struct status;
/* make sure the database is up to date */
if (print_cache_expired(lp_const_servicename(snum), True))
- print_queue_update(snum, False);
+ print_queue_update(msg_ctx, snum, False);
/* also fetch the queue status */
memset(&status, 0, sizeof(status));
}
/* Insure the maximum queue size is not violated */
- *njobs = print_queue_length(snum, NULL);
+ *njobs = print_queue_length(msg_ctx, snum, NULL);
if (*njobs > lp_maxprintjobs(snum)) {
DEBUG(3, ("print_job_checks: Queue %s number of jobs (%d) "
"larger than max printjobs per queue (%d).\n",
goto fail;
}
- pjob_store(sharename, jobid, &pjob);
+ pjob_store(server_event_context(), msg_ctx, sharename, jobid, &pjob);
/* Update the 'jobs changed' entry used by print_queue_status. */
add_to_jobs_changed(pdb, jobid);
fail:
if (jobid != -1) {
- pjob_delete(sharename, jobid);
+ pjob_delete(server_event_context(), msg_ctx, sharename, jobid);
}
release_print_db(pdb);
return;
pjob->page_count++;
- pjob_store(sharename, jobid, pjob);
+ pjob_store(server_event_context(), server_messaging_context(),
+ sharename, jobid, pjob);
}
/****************************************************************************
error.
****************************************************************************/
-NTSTATUS print_job_end(int snum, uint32 jobid, enum file_close_type close_type)
+NTSTATUS print_job_end(struct messaging_context *msg_ctx, int snum,
+ uint32 jobid, enum file_close_type close_type)
{
const char* sharename = lp_const_servicename(snum);
struct printjob *pjob;
DEBUG(5,("print_job_end: canceling spool of %s (%s)\n",
pjob->filename, pjob->size ? "deleted" : "zero length" ));
unlink(pjob->filename);
- pjob_delete(sharename, jobid);
+ pjob_delete(server_event_context(), msg_ctx, sharename, jobid);
return NT_STATUS_OK;
}
pjob->spooled = True;
pjob->status = LPQ_QUEUED;
- pjob_store(sharename, jobid, pjob);
+ pjob_store(server_event_context(), msg_ctx, sharename, jobid, pjob);
/* make sure the database is up to date */
if (print_cache_expired(lp_const_servicename(snum), True))
- print_queue_update(snum, False);
+ print_queue_update(msg_ctx, snum, False);
return NT_STATUS_OK;
/* Still need to add proper error return propagation! 010122:JRR */
pjob->fd = -1;
unlink(pjob->filename);
- pjob_delete(sharename, jobid);
+ pjob_delete(server_event_context(), msg_ctx, sharename, jobid);
return status;
}
Get a snapshot of jobs in the system without traversing.
****************************************************************************/
-static bool get_stored_queue_info(struct tdb_print_db *pdb, int snum, int *pcount, print_queue_struct **ppqueue)
+static bool get_stored_queue_info(struct messaging_context *msg_ctx,
+ struct tdb_print_db *pdb, int snum,
+ int *pcount, print_queue_struct **ppqueue)
{
TDB_DATA data, cgdata;
print_queue_struct *queue = NULL;
/* make sure the database is up to date */
if (print_cache_expired(lp_const_servicename(snum), True))
- print_queue_update(snum, False);
+ print_queue_update(msg_ctx, snum, False);
*pcount = 0;
*ppqueue = NULL;
set queue = NULL and status = NULL if you just want to update the cache
****************************************************************************/
-int print_queue_status(int snum,
+int print_queue_status(struct messaging_context *msg_ctx, int snum,
print_queue_struct **ppqueue,
print_status_struct *status)
{
/* make sure the database is up to date */
if (print_cache_expired(lp_const_servicename(snum), True))
- print_queue_update(snum, False);
+ print_queue_update(msg_ctx, snum, False);
/* return if we are done */
if ( !ppqueue || !status )
* of entries, and then only retrieve the queue if necessary.
*/
- if (!get_stored_queue_info(pdb, snum, &count, ppqueue)) {
+ if (!get_stored_queue_info(msg_ctx, pdb, snum, &count, ppqueue)) {
release_print_db(pdb);
return 0;
}
/* Send a printer notify message */
- notify_printer_status(snum, PRINTER_STATUS_PAUSED);
+ notify_printer_status(server_event_context(), msg_ctx, snum,
+ PRINTER_STATUS_PAUSED);
return WERR_OK;
}
/* make sure the database is up to date */
if (print_cache_expired(lp_const_servicename(snum), True))
- print_queue_update(snum, True);
+ print_queue_update(msg_ctx, snum, True);
/* Send a printer notify message */
- notify_printer_status(snum, PRINTER_STATUS_OK);
+ notify_printer_status(server_event_context(), msg_ctx, snum,
+ PRINTER_STATUS_OK);
return WERR_OK;
}
Purge a queue - implemented by deleting all jobs that we can delete.
****************************************************************************/
-WERROR print_queue_purge(struct auth_serversupplied_info *server_info, int snum)
+WERROR print_queue_purge(struct auth_serversupplied_info *server_info,
+ struct messaging_context *msg_ctx, int snum)
{
print_queue_struct *queue;
print_status_struct status;
bool can_job_admin;
/* Force and update so the count is accurate (i.e. not a cached count) */
- print_queue_update(snum, True);
+ print_queue_update(msg_ctx, snum, True);
can_job_admin = print_access_check(server_info,
- smbd_messaging_context(),
+ msg_ctx,
snum,
JOB_ACCESS_ADMINISTER);
- njobs = print_queue_status(snum, &queue, &status);
+ njobs = print_queue_status(msg_ctx, snum, &queue, &status);
if ( can_job_admin )
become_root();
unbecome_root();
/* update the cache */
- print_queue_update( snum, True );
+ print_queue_update(msg_ctx, snum, True);
SAFE_FREE(queue);