Added Tim's changes to lock DB during update.
authorJeremy Allison <jra@samba.org>
Fri, 10 Nov 2000 22:05:08 +0000 (22:05 +0000)
committerJeremy Allison <jra@samba.org>
Fri, 10 Nov 2000 22:05:08 +0000 (22:05 +0000)
Jeremy.
(This used to be commit f25b5798b8610de9748ae90ea1bf813b125f517d)

source3/printing/printing.c

index 77e32d5bf0ce090792a21dd71974a8a550c26258..95bcf2a2762471acdc499460137394a74ab4a712 100644 (file)
@@ -128,7 +128,7 @@ static BOOL print_job_store(int jobid, struct printjob *pjob)
        d.dptr = (void *)pjob;
        d.dsize = sizeof(*pjob);
 
-       return (0 == tdb_store(tdb, print_key(jobid), d, TDB_REPLACE));
+       return (tdb_store(tdb, print_key(jobid), d, TDB_REPLACE) == 0);
 }
 
 /****************************************************************************
@@ -170,6 +170,7 @@ static int print_run_command(int snum,char *command,
        ret = smbrun(syscmd,outfile,False);
 
        DEBUG(3,("Running the command `%s' gave %d\n",syscmd,ret));
+
        return ret;
 }
 
@@ -318,8 +319,7 @@ static void print_queue_update(int snum)
        slprintf(tmp_file, sizeof(tmp_file), "%s/smblpq.%d", path, local_pid);
 
        unlink(tmp_file);
-       print_run_command(snum, cmd, tmp_file,
-                         NULL);
+       print_run_command(snum, cmd, tmp_file, NULL);
 
        numlines = 0;
        qlines = file_lines_load(tmp_file, &numlines);
@@ -342,6 +342,14 @@ static void print_queue_update(int snum)
        }
        file_lines_free(qlines);
 
+       DEBUG(3, ("%d job%s in queue for %s\n", qcount, (qcount != 1) ?
+               "s" : "", lp_servicename(snum)));
+
+       /* Lock the queue for the database update */
+
+       slprintf(keystr, sizeof(keystr) - 1, "LOCK/%s", lp_servicename(snum));
+       tdb_lock_bystring(tdb, keystr);
+
        /*
          any job in the internal database that is marked as spooled
          and doesn't exist in the system queue is considered finished
@@ -396,6 +404,11 @@ static void print_queue_update(int snum)
        key.dsize = strlen(keystr);
        tdb_store(tdb, key, data, TDB_REPLACE); 
 
+       /* Unlock for database update */
+
+       slprintf(keystr, sizeof(keystr) - 1, "LOCK/%s", lp_servicename(snum));
+       tdb_unlock_bystring(tdb, keystr);
+
        /*
         * Update the cache time again. We want to do this call
         * as little as possible...
@@ -678,9 +691,11 @@ 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()) {
+               DEBUG(3, ("print cache expired\n"));
                return True;
        }
        return False;