Commit 67d47486 authored by Gerald Carter's avatar Gerald Carter Committed by Gerald (Jerry) Carter
Browse files

r799: BUG 1259 -- add 'printcap cache time' patch from Lars

(This used to be commit fac90741139b953d0e88d050dd457657f0b9c9f3)
parent 96c6bf93
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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)
+27 −1
Original line number Diff line number Diff line
@@ -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;
		}
	}
}

/****************************************************************************
+24 −0
Original line number Diff line number Diff line
@@ -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);
		}
	}
}