summaryrefslogtreecommitdiff
path: root/source3/printing
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2000-10-11 02:26:27 +0000
committerJeremy Allison <jra@samba.org>2000-10-11 02:26:27 +0000
commit26a4a34d36aff371b2b03506b4e7544847dd1d69 (patch)
treefc0140994809e9b828cb26c9bfcf807d52d2e384 /source3/printing
parente9270d61fc8ddaecd8eb1d2c0a9ce8eba13b1194 (diff)
downloadsamba-26a4a34d36aff371b2b03506b4e7544847dd1d69.tar.gz
samba-26a4a34d36aff371b2b03506b4e7544847dd1d69.tar.bz2
samba-26a4a34d36aff371b2b03506b4e7544847dd1d69.zip
Fix for growing printing.tdb by adding check on job creation.
This also updates the printing.tdb db version to 2. Jeremy. (This used to be commit 13395514c632341e7be36eb9589011bb0949b075)
Diffstat (limited to 'source3/printing')
-rw-r--r--source3/printing/printing.c67
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)
{