diff options
Diffstat (limited to 'source3/printing/printing.c')
-rw-r--r-- | source3/printing/printing.c | 67 |
1 files changed, 50 insertions, 17 deletions
diff --git a/source3/printing/printing.c b/source3/printing/printing.c index d71ea25d0d..d856023567 100644 --- a/source3/printing/printing.c +++ b/source3/printing/printing.c @@ -60,7 +60,7 @@ static pid_t local_pid; #define UNIX_JOB_START PRINT_MAX_JOBID #define PRINT_SPOOL_PREFIX "smbprn." -#define PRINT_DATABASE_VERSION 1 +#define PRINT_DATABASE_VERSION 2 /**************************************************************************** initialise the printing backend. Called once at startup. @@ -381,6 +381,7 @@ static void print_queue_update(int snum) safe_free(tstruct.queue); /* store the queue status structure */ + status.qcount = qcount; slprintf(keystr, sizeof(keystr), "STATUS/%s", lp_servicename(snum)); data.dptr = (void *)&status; data.dsize = sizeof(status); @@ -628,6 +629,49 @@ int print_job_write(int jobid, const char *buf, int size) return write(fd, buf, size); } +/**************************************************************************** + Check if the print queue has been updated recently enough. +****************************************************************************/ + +static BOOL print_cache_expired(int snum) +{ + fstring key; + time_t t2, t = time(NULL); + slprintf(key, sizeof(key), "CACHE/%s", lp_servicename(snum)); + t2 = tdb_fetch_int(tdb, key); + if (t2 == ((time_t)-1) || (t - t2) >= lp_lpqcachetime()) { + return True; + } + return False; +} + +/**************************************************************************** + Determine the number of jobs in a queue. +****************************************************************************/ + +static int print_queue_length(int snum) +{ + fstring keystr; + TDB_DATA data, key; + print_status_struct status; + + /* make sure the database is up to date */ + 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; +} /*************************************************************************** start spooling a job - return the jobid @@ -670,6 +714,11 @@ int print_job_start(struct current_user *user, int snum, char *jobname) return -1; } + if (print_queue_length(snum) > lp_maxprintjobs(snum)) { + errno = ENOSPC; + return -1; + } + /* create the database entry */ ZERO_STRUCT(pjob); pjob.pid = local_pid; @@ -822,22 +871,6 @@ BOOL print_job_end(int jobid) return True; } -/**************************************************************************** - Check if the print queue has been updated recently enough. -****************************************************************************/ - -static BOOL print_cache_expired(int snum) -{ - fstring key; - time_t t2, t = time(NULL); - slprintf(key, sizeof(key), "CACHE/%s", lp_servicename(snum)); - t2 = tdb_fetch_int(tdb, key); - if (t2 == ((time_t)-1) || (t - t2) >= lp_lpqcachetime()) { - return True; - } - return False; -} - /* utility fn to enumerate the print queue */ static int traverse_fn_queue(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, void *state) { |