mirror of
https://github.com/samba-team/samba.git
synced 2025-01-12 09:18:10 +03:00
Fix for updating of print queues changed from a local box. Essentially,
this makes sure that the change messages sent to ourselves are handled synchronously w.r.t. other smb packets incoming. Jeremy.
This commit is contained in:
parent
b456274a7b
commit
78a1307445
@ -63,6 +63,8 @@ static pid_t local_pid;
|
||||
#define PRINT_SPOOL_PREFIX "smbprn."
|
||||
#define PRINT_DATABASE_VERSION 2
|
||||
|
||||
static int get_queue_status(int, print_status_struct *);
|
||||
|
||||
/****************************************************************************
|
||||
initialise the printing backend. Called once at startup.
|
||||
Does not survive a fork
|
||||
@ -315,6 +317,7 @@ static void print_queue_update(int snum)
|
||||
int numlines, i, qcount;
|
||||
print_queue_struct *queue = NULL;
|
||||
print_status_struct status;
|
||||
print_status_struct old_status;
|
||||
struct printjob *pjob;
|
||||
struct traverse_struct tstruct;
|
||||
fstring keystr, printer_name;
|
||||
@ -409,13 +412,26 @@ static void print_queue_update(int snum)
|
||||
|
||||
safe_free(tstruct.queue);
|
||||
|
||||
/* store the queue status structure */
|
||||
status.qcount = qcount;
|
||||
/*
|
||||
* Get the old print status. We will use this to compare the
|
||||
* number of jobs. If they have changed we need to send a
|
||||
* "changed" message to the smbds.
|
||||
*/
|
||||
|
||||
if( qcount != get_queue_status(snum, &old_status)) {
|
||||
DEBUG(10,("print_queue_update: queue status change %d jobs -> %d jobs for printer %s\n",
|
||||
old_status.qcount, qcount, printer_name ));
|
||||
message_send_all(MSG_PRINTER_NOTIFY, printer_name, strlen(printer_name) + 1, False);
|
||||
}
|
||||
|
||||
/* store the new queue status structure */
|
||||
slprintf(keystr, sizeof(keystr), "STATUS/%s", printer_name);
|
||||
data.dptr = (void *)&status;
|
||||
data.dsize = sizeof(status);
|
||||
key.dptr = keystr;
|
||||
key.dsize = strlen(keystr);
|
||||
|
||||
status.qcount = qcount;
|
||||
data.dptr = (void *)&status;
|
||||
data.dsize = sizeof(status);
|
||||
tdb_store(tdb, key, data, TDB_REPLACE);
|
||||
|
||||
/* Unlock for database update */
|
||||
@ -712,6 +728,29 @@ static BOOL print_cache_expired(int snum)
|
||||
return False;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Get the queue status - do not update if db is out of date.
|
||||
****************************************************************************/
|
||||
|
||||
static int get_queue_status(int snum, print_status_struct *status)
|
||||
{
|
||||
fstring keystr;
|
||||
TDB_DATA data, key;
|
||||
|
||||
ZERO_STRUCTP(status);
|
||||
slprintf(keystr, sizeof(keystr), "STATUS/%s", lp_servicename(snum));
|
||||
key.dptr = keystr;
|
||||
key.dsize = strlen(keystr);
|
||||
data = tdb_fetch(tdb, key);
|
||||
if (data.dptr) {
|
||||
if (data.dsize == sizeof(print_status_struct)) {
|
||||
memcpy(status, data.dptr, sizeof(print_status_struct));
|
||||
}
|
||||
free(data.dptr);
|
||||
}
|
||||
return status->qcount;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Determine the number of jobs in a queue.
|
||||
****************************************************************************/
|
||||
@ -726,18 +765,7 @@ static int print_queue_length(int snum)
|
||||
if (print_cache_expired(snum)) print_queue_update(snum);
|
||||
|
||||
/* also fetch the queue status */
|
||||
ZERO_STRUCTP(&status);
|
||||
slprintf(keystr, sizeof(keystr), "STATUS/%s", lp_servicename(snum));
|
||||
key.dptr = keystr;
|
||||
key.dsize = strlen(keystr);
|
||||
data = tdb_fetch(tdb, key);
|
||||
if (data.dptr) {
|
||||
if (data.dsize == sizeof(status)) {
|
||||
memcpy(&status, data.dptr, sizeof(status));
|
||||
}
|
||||
free(data.dptr);
|
||||
}
|
||||
return status.qcount;
|
||||
return get_queue_status(snum, &status);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
|
@ -5922,7 +5922,7 @@ BOOL make_spoolss_q_reply_rrpcn(SPOOL_Q_REPLY_RRPCN *q_u, POLICY_HND *hnd,
|
||||
********************************************************************/
|
||||
BOOL spoolss_io_q_reply_rrpcn(char *desc, SPOOL_Q_REPLY_RRPCN *q_u, prs_struct *ps, int depth)
|
||||
{
|
||||
prs_debug(ps, depth, desc, "spoolss_io_q_replycloseprinter");
|
||||
prs_debug(ps, depth, desc, "spoolss_io_q_reply_rrpcn");
|
||||
depth++;
|
||||
|
||||
if(!prs_align(ps))
|
||||
|
@ -131,9 +131,6 @@ static void async_processing(fd_set *fds, char *buffer, int buffer_len)
|
||||
reload_services(False);
|
||||
reload_after_sighup = False;
|
||||
}
|
||||
|
||||
/* check for any pending internal messages */
|
||||
message_dispatch();
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -166,6 +163,15 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout)
|
||||
|
||||
smb_read_error = 0;
|
||||
|
||||
again:
|
||||
|
||||
/*
|
||||
* Note that this call must be before processing any SMB
|
||||
* messages as we need to synchronously process any messages
|
||||
* we may have sent to ourselves from the previous SMB.
|
||||
*/
|
||||
message_dispatch();
|
||||
|
||||
/*
|
||||
* Check to see if we already have a message on the smb queue.
|
||||
* If so - copy and return it.
|
||||
@ -187,7 +193,6 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout)
|
||||
* Setup the select read fd set.
|
||||
*/
|
||||
|
||||
again:
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(smbd_server_fd(),&fds);
|
||||
maxfd = setup_oplock_select_set(&fds);
|
||||
|
@ -218,7 +218,7 @@ BOOL stat_cache_lookup(connection_struct *conn, char *name, char *dirpath,
|
||||
*/
|
||||
BOOL reset_stat_cache( void )
|
||||
{
|
||||
static BOOL initialised;
|
||||
static BOOL initialised = False;
|
||||
if (!lp_stat_cache()) return True;
|
||||
|
||||
if (!initialised) {
|
||||
|
Loading…
Reference in New Issue
Block a user