BUG 1259 -- add 'printcap cache time' patch from Lars
authorjerry <jerry@0c0555d6-39d7-0310-84fc-f1cc0bd64818>
Thu, 20 May 2004 16:23:17 +0000 (16:23 +0000)
committerjerry <jerry@0c0555d6-39d7-0310-84fc-f1cc0bd64818>
Thu, 20 May 2004 16:23:17 +0000 (16:23 +0000)
git-svn-id: svn+ssh://svn.samba.org/data/svn/samba/branches/SAMBA_3_0@799 0c0555d6-39d7-0310-84fc-f1cc0bd64818

source/param/loadparm.c
source/smbd/process.c
source/smbd/service.c

index b5bd14cdde2c597b883bd52ab0e8bb1ec8512a7d..6376e4aa9172f16721797babaecf1176d3858909 100644 (file)
@@ -249,6 +249,7 @@ typedef struct
        BOOL bNullPasswords;
        BOOL bObeyPamRestrictions;
        BOOL bLoadPrinters;
+       int PrintcapCacheTime;
        BOOL bLargeReadwrite;
        BOOL bReadRaw;
        BOOL bWriteRaw;
@@ -945,6 +946,7 @@ static struct parm_struct parm_table[] = {
        {"max reported print jobs", P_INTEGER, P_LOCAL, &sDefault.iMaxReportedPrintJobs, NULL, NULL, FLAG_ADVANCED | FLAG_PRINT}, 
        {"max print jobs", P_INTEGER, P_LOCAL, &sDefault.iMaxPrintJobs, NULL, NULL, FLAG_ADVANCED | FLAG_PRINT}, 
        {"load printers", P_BOOL, P_GLOBAL, &Globals.bLoadPrinters, NULL, NULL, FLAG_ADVANCED | FLAG_PRINT}, 
+       {"printcap cache time", P_INTEGER, P_GLOBAL, &Globals.PrintcapCacheTime, NULL, NULL, FLAG_ADVANCED | FLAG_PRINT}, 
        {"printcap name", P_STRING, P_GLOBAL, &Globals.szPrintcapname, NULL, NULL, FLAG_ADVANCED | FLAG_PRINT}, 
        {"printcap", P_STRING, P_GLOBAL, &Globals.szPrintcapname, NULL, NULL, FLAG_HIDE}, 
        {"printable", P_BOOL, P_LOCAL, &sDefault.bPrint_ok, NULL, NULL, FLAG_ADVANCED | FLAG_PRINT}, 
@@ -1362,6 +1364,7 @@ static void init_globals(void)
        Globals.AlgorithmicRidBase = BASE_RID;
 
        Globals.bLoadPrinters = True;
+       Globals.PrintcapCacheTime = 0;
        /* Was 65535 (0xFFFF). 0x4101 matches W2K and causes major speed improvements... */
        /* Discovered by 2 days of pain by Don McCall @ HP :-). */
        Globals.max_xmit = 0x4104;
@@ -1614,6 +1617,7 @@ FN_GLOBAL_STRING(lp_configfile, &Globals.szConfigFile)
 FN_GLOBAL_STRING(lp_smb_passwd_file, &Globals.szSMBPasswdFile)
 FN_GLOBAL_STRING(lp_private_dir, &Globals.szPrivateDir)
 FN_GLOBAL_STRING(lp_serverstring, &Globals.szServerString)
+FN_GLOBAL_INTEGER(lp_printcap_cache_time, &Globals.PrintcapCacheTime)
 FN_GLOBAL_STRING(lp_printcapname, &Globals.szPrintcapname)
 FN_GLOBAL_STRING(lp_enumports_cmd, &Globals.szEnumPortsCommand)
 FN_GLOBAL_STRING(lp_addprinter_cmd, &Globals.szAddPrinterCommand)
index d0dfc6dd7dbb01c2c9d5783f45b7898c2411959f..283b791afd0603e262d11218a50dbd8f4ed3d381 100644 (file)
@@ -1078,15 +1078,41 @@ static int setup_select_timeout(void)
 void check_reload(int t)
 {
        static time_t last_smb_conf_reload_time = 0;
+       static time_t last_load_printers_reload_time = 0;
+       time_t printcap_cache_time = (time_t)lp_printcap_cache_time();
 
-       if(last_smb_conf_reload_time == 0)
+       if(last_smb_conf_reload_time == 0) {
                last_smb_conf_reload_time = t;
+               /* Our printing subsystem might not be ready at smbd start up.
+                  Then no printer is available till the first printers check
+                  is performed.  A lower initial interval circumvents this. */
+               if ( printcap_cache_time > 60 )
+                       last_load_printers_reload_time = t - printcap_cache_time + 60;
+               else
+                       last_load_printers_reload_time = t;
+       }
 
        if (reload_after_sighup || (t >= last_smb_conf_reload_time+SMBD_RELOAD_CHECK)) {
                reload_services(True);
                reload_after_sighup = False;
                last_smb_conf_reload_time = t;
        }
+
+       /* 'printcap cache time = 0' disable the feature */
+       
+       if ( printcap_cache_time != 0 )
+       { 
+               /* see if it's time to reload or if the clock has been set back */
+               
+               if ( (t >= last_load_printers_reload_time+printcap_cache_time) 
+                       || (t-last_load_printers_reload_time  < 0) ) 
+               {
+                       DEBUG( 3,( "Printcap cache time expired.\n"));
+                       remove_stale_printers();
+                       load_printers();
+                       last_load_printers_reload_time = t;
+               }
+       }
 }
 
 /****************************************************************************
index 04cade9577965fdc43d2ebc4f184fa3c76044145..c74537c299e14c67a78863281095661338afc63a 100644 (file)
@@ -826,3 +826,27 @@ void close_cnum(connection_struct *conn, uint16 vuid)
 
        conn_free(conn);
 }
+
+/****************************************************************************
+ Remove stale printers
+****************************************************************************/
+
+void remove_stale_printers( void )
+{
+       int snum, iNumServices, printersServiceNum;
+       const char *pname;
+
+       iNumServices = lp_numservices();
+       printersServiceNum = lp_servicenumber( PRINTERS_NAME);
+       for( snum = 0; snum < iNumServices; snum++) {
+               /* Never remove PRINTERS_NAME */
+               if ( snum == printersServiceNum)
+                       continue;
+               pname = lp_printername( snum);
+               /* Is snum a print service and still in the printing subsystem? */
+               if ( lp_print_ok( snum) && !pcap_printername_ok( pname, NULL)) {
+                       DEBUG( 3, ( "Removing printer: %s\n", pname));
+                       lp_killservice( snum);
+               }
+       }
+}