From 53510eaed6fc626e2f3f19147e75955dac9f7aa3 Mon Sep 17 00:00:00 2001 From: mike Date: Thu, 10 Apr 2003 20:15:55 +0000 Subject: [PATCH] Mirror 1.1.x changes. git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/branches/branch-1.2@3589 7a7537e8-13f0-0310-91df-b6672ffda945 --- CHANGES-1.1.txt | 12 ++- conf/cupsd.conf.in | 23 ++++- scheduler/client.c | 8 +- scheduler/conf.c | 203 +++++++++++++++++++++++++-------------------- scheduler/cupsd.h | 15 +++- scheduler/job.c | 31 +++++-- scheduler/job.h | 7 +- scheduler/log.c | 18 ++-- scheduler/main.c | 42 ++-------- scheduler/server.c | 30 ++++--- 10 files changed, 231 insertions(+), 158 deletions(-) diff --git a/CHANGES-1.1.txt b/CHANGES-1.1.txt index 11cd9ff2a..df6fed685 100644 --- a/CHANGES-1.1.txt +++ b/CHANGES-1.1.txt @@ -3,6 +3,12 @@ CHANGES-1.1.txt CHANGES IN CUPS V1.1.19 + - The scheduler now supports fast-reloads of the + cupsd.conf file when it is updated via HTTP. + - The scheduler always changed the ownership of log + files; it now only does so if they are not in the /dev + directory (i.e. don't want to change the ownership and + permissions of /dev/null...) - Added libpaper support (patch from Jeff Licquia) - Added a new istring() rule for MIME types files that does a case-insensitive comparison of strings. @@ -11,8 +17,10 @@ CHANGES IN CUPS V1.1.19 no "lp" queue) is sent. - The scheduler now supports fax queues identified by a "*cupsFax: True" attribute in the PPD file. When a job - can't be sent, it is held for 5 minutes while other - jobs are attempted. + can't be sent, it is held for 5 minutes by default + while other jobs are attempted. The FaxRetryLimit and + FaxRetryInterval directives control the number of + retries and the time between retries. - The scheduler now preserves the default options of PPD files when modifying/upgrading an existing PPD file. When installing a new printer, the scheduler sets the diff --git a/conf/cupsd.conf.in b/conf/cupsd.conf.in index c13037963..e8bea0ae6 100644 --- a/conf/cupsd.conf.in +++ b/conf/cupsd.conf.in @@ -1,5 +1,5 @@ # -# "$Id: cupsd.conf.in,v 1.2.2.10 2003/04/05 03:39:28 mike Exp $" +# "$Id: cupsd.conf.in,v 1.2.2.11 2003/04/10 20:15:48 mike Exp $" # # Sample configuration file for the Common UNIX Printing System (CUPS) # scheduler. @@ -274,6 +274,25 @@ LogLevel info #ServerRoot @CUPS_SERVERROOT@ +######## +######## Fax Support +######## + +# +# FaxRetryLimit: the number of times a fax job is retried. +# The default is 5 times. +# + +#FaxRetryLimit 5 + +# +# FaxRetryInterval: the number of seconds between fax job retries. +# The default is 300 seconds/5 minutes. +# + +#FaxRetryInterval 300 + + ######## ######## Encryption Support ######## @@ -780,5 +799,5 @@ Allow From 127.0.0.1 # -# End of "$Id: cupsd.conf.in,v 1.2.2.10 2003/04/05 03:39:28 mike Exp $". +# End of "$Id: cupsd.conf.in,v 1.2.2.11 2003/04/10 20:15:48 mike Exp $". # diff --git a/scheduler/client.c b/scheduler/client.c index 45e8a58ec..b3cd8e856 100644 --- a/scheduler/client.c +++ b/scheduler/client.c @@ -1,5 +1,5 @@ /* - * "$Id: client.c,v 1.91.2.57 2003/04/08 03:48:07 mike Exp $" + * "$Id: client.c,v 1.91.2.58 2003/04/10 20:15:49 mike Exp $" * * Client routines for the Common UNIX Printing System (CUPS) scheduler. * @@ -2884,7 +2884,9 @@ install_conf_file(client_t *con) /* I - Connection */ */ if (strcmp(con->uri, "/admin/conf/cupsd.conf") == 0) - NeedReload = TRUE; + NeedReload = RELOAD_CUPSD; + else + NeedReload = RELOAD_ALL; /* * Return that the file was created successfully... @@ -3342,5 +3344,5 @@ CDSAWriteFunc(SSLConnectionRef connection, /* I - SSL/TLS connection */ /* - * End of "$Id: client.c,v 1.91.2.57 2003/04/08 03:48:07 mike Exp $". + * End of "$Id: client.c,v 1.91.2.58 2003/04/10 20:15:49 mike Exp $". */ diff --git a/scheduler/conf.c b/scheduler/conf.c index 04ea785b2..ab1a5f1cf 100644 --- a/scheduler/conf.c +++ b/scheduler/conf.c @@ -1,5 +1,5 @@ /* - * "$Id: conf.c,v 1.77.2.37 2003/04/10 14:13:52 mike Exp $" + * "$Id: conf.c,v 1.77.2.38 2003/04/10 20:15:51 mike Exp $" * * Configuration routines for the Common UNIX Printing System (CUPS). * @@ -128,6 +128,8 @@ static var_t variables[] = { "DefaultLanguage", &DefaultLanguage, VAR_STRING }, { "DocumentRoot", &DocumentRoot, VAR_STRING }, { "ErrorLog", &ErrorLog, VAR_STRING }, + { "FaxRetryLimit", &FaxRetryLimit, VAR_INTEGER }, + { "FaxRetryInterval", &FaxRetryInterval, VAR_INTEGER }, { "FileDevice", &FileDevice, VAR_BOOLEAN }, { "FilterLimit", &FilterLimit, VAR_INTEGER }, { "FilterNice", &FilterNice, VAR_INTEGER }, @@ -220,6 +222,8 @@ ReadConfiguration(void) struct passwd *user; /* Default user */ struct group *group; /* Default group */ int run_user; /* User that will be running cupsd */ + char *old_serverroot, /* Old ServerRoot */ + *old_requestroot; /* Old RequestRoot */ /* @@ -229,38 +233,17 @@ ReadConfiguration(void) StopServer(); /* - * Free all memory... + * Save the old root paths... */ - FreeAllJobs(); - DeleteAllClasses(); - DeleteAllLocations(); - DeleteAllPrinters(); - - DefaultPrinter = NULL; - - if (Devices) - { - ippDelete(Devices); - Devices = NULL; - } + SetString(&old_serverroot, ServerRoot); + SetString(&old_requestroot, RequestRoot); - if (PPDs) - { - ippDelete(PPDs); - PPDs = NULL; - } - - if (MimeDatabase != NULL) - mimeDelete(MimeDatabase); - - if (NumMimeTypes) - { - for (i = 0; i < NumMimeTypes; i ++) - free((void *)MimeTypes[i]); + /* + * Reset the server configuration data... + */ - free(MimeTypes); - } + DeleteAllLocations(); if (NumBrowsers > 0) { @@ -294,12 +277,6 @@ ReadConfiguration(void) NumListeners = 0; } - /* - * Reset the current configuration to the defaults... - */ - - NeedReload = FALSE; - /* * String options... */ @@ -330,14 +307,7 @@ ReadConfiguration(void) #ifdef HAVE_SSL # ifdef HAVE_CDSASSL - if (ServerCertificatesArray) - { - CFRelease(ServerCertificatesArray); - ServerCertificatesArray = NULL; - } - SetString(&ServerCertificate, "/var/root/Library/Keychains/CUPS"); - # else SetString(&ServerCertificate, "ssl/server.crt"); SetString(&ServerKey, "ssl/server.key"); @@ -408,6 +378,8 @@ ReadConfiguration(void) ConfigFilePerm = 0640; LogFilePerm = 0644; + FaxRetryLimit = 5; + FaxRetryInterval = 300; FileDevice = FALSE; FilterLevel = 0; FilterLimit = 0; @@ -492,8 +464,7 @@ ReadConfiguration(void) * Log the configuration file that was used... */ - LogMessage(L_DEBUG, "ReadConfiguration() ConfigurationFile=\"%s\"", - ConfigurationFile); + LogMessage(L_INFO, "Loaded configuration file \"%s\"", ConfigurationFile); /* * Update all relative filenames to include the full path from ServerRoot... @@ -637,75 +608,129 @@ ReadConfiguration(void) MaxClientsPerHost); /* - * Read the MIME type and conversion database... + * If we are doing a full reload or the server root has changed, flush + * the jobs, printers, etc. and start from scratch... */ - snprintf(temp, sizeof(temp), "%s/filter", ServerBin); + if (NeedReload == RELOAD_ALL || + !old_serverroot || !ServerRoot || strcmp(old_serverroot, ServerRoot) || + !old_requestroot || !RequestRoot || strcmp(old_requestroot, RequestRoot)) + { + LogMessage(L_INFO, "Full reload is required."); - MimeDatabase = mimeNew(); - mimeMerge(MimeDatabase, ServerRoot, temp); + /* + * Free all memory... + */ - /* - * Create a list of MIME types for the document-format-supported - * attribute... - */ + FreeAllJobs(); + DeleteAllClasses(); + DeleteAllPrinters(); - NumMimeTypes = MimeDatabase->num_types; - if (!mimeType(MimeDatabase, "application", "octet-stream")) - NumMimeTypes ++; + DefaultPrinter = NULL; - MimeTypes = calloc(NumMimeTypes, sizeof(const char *)); + if (Devices) + { + ippDelete(Devices); + Devices = NULL; + } - for (i = 0; i < MimeDatabase->num_types; i ++) - { - snprintf(type, sizeof(type), "%s/%s", MimeDatabase->types[i]->super, - MimeDatabase->types[i]->type); + if (PPDs) + { + ippDelete(PPDs); + PPDs = NULL; + } - MimeTypes[i] = strdup(type); - } + if (MimeDatabase != NULL) + mimeDelete(MimeDatabase); - if (i < NumMimeTypes) - MimeTypes[i] = strdup("application/octet-stream"); + if (NumMimeTypes) + { + for (i = 0; i < NumMimeTypes; i ++) + free((void *)MimeTypes[i]); - /* - * Load banners... - */ + free(MimeTypes); + } - snprintf(temp, sizeof(temp), "%s/banners", DataDir); - LoadBanners(temp); + /* + * Read the MIME type and conversion database... + */ - /* - * Load printers and classes... - */ + snprintf(temp, sizeof(temp), "%s/filter", ServerBin); - LoadAllPrinters(); - LoadAllClasses(); + MimeDatabase = mimeNew(); + mimeMerge(MimeDatabase, ServerRoot, temp); - /* - * Load devices and PPDs... - */ + /* + * Create a list of MIME types for the document-format-supported + * attribute... + */ - snprintf(temp, sizeof(temp), "%s/model", DataDir); - LoadPPDs(temp); + NumMimeTypes = MimeDatabase->num_types; + if (!mimeType(MimeDatabase, "application", "octet-stream")) + NumMimeTypes ++; - snprintf(temp, sizeof(temp), "%s/backend", ServerBin); - LoadDevices(temp); + MimeTypes = calloc(NumMimeTypes, sizeof(const char *)); -#ifdef HAVE_CDSASSL - ServerCertificatesArray = CDSAGetServerCerts(); -#endif /* HAVE_CDSASSL */ + for (i = 0; i < MimeDatabase->num_types; i ++) + { + snprintf(type, sizeof(type), "%s/%s", MimeDatabase->types[i]->super, + MimeDatabase->types[i]->type); + + MimeTypes[i] = strdup(type); + } + + if (i < NumMimeTypes) + MimeTypes[i] = strdup("application/octet-stream"); + + /* + * Load banners... + */ + + snprintf(temp, sizeof(temp), "%s/banners", DataDir); + LoadBanners(temp); + + /* + * Load printers and classes... + */ + + LoadAllPrinters(); + LoadAllClasses(); + + /* + * Load devices and PPDs... + */ + + snprintf(temp, sizeof(temp), "%s/model", DataDir); + LoadPPDs(temp); + + snprintf(temp, sizeof(temp), "%s/backend", ServerBin); + LoadDevices(temp); + + /* + * Load queued jobs... + */ + + LoadAllJobs(); + + LogMessage(L_INFO, "Full reload complete."); + } + else + LogMessage(L_INFO, "Partial reload complete."); /* - * Startup the server... + * Reset the reload state... */ - StartServer(); + NeedReload = RELOAD_NONE; + + ClearString(&old_serverroot); + ClearString(&old_requestroot); /* - * Load queued jobs... + * Startup the server and return... */ - LoadAllJobs(); + StartServer(); return (1); } @@ -2266,5 +2291,5 @@ CDSAGetServerCerts(void) /* - * End of "$Id: conf.c,v 1.77.2.37 2003/04/10 14:13:52 mike Exp $". + * End of "$Id: conf.c,v 1.77.2.38 2003/04/10 20:15:51 mike Exp $". */ diff --git a/scheduler/cupsd.h b/scheduler/cupsd.h index bacb81803..eadd01deb 100644 --- a/scheduler/cupsd.h +++ b/scheduler/cupsd.h @@ -1,5 +1,5 @@ /* - * "$Id: cupsd.h,v 1.28.2.18 2003/03/31 16:48:27 mike Exp $" + * "$Id: cupsd.h,v 1.28.2.19 2003/04/10 20:15:52 mike Exp $" * * Main header file for the Common UNIX Printing System (CUPS) scheduler. * @@ -167,6 +167,15 @@ typedef struct direct DIRENT; #endif +/* + * Reload types... + */ + +#define RELOAD_NONE 0 /* No reload needed */ +#define RELOAD_ALL 1 /* Reload everything */ +#define RELOAD_CUPSD 2 /* Reload only cupsd.conf */ + + /* * Globals... */ @@ -176,7 +185,7 @@ VAR int MaxFDs, /* Maximum number of files */ VAR fd_set *InputSet, /* Input files for select() */ *OutputSet; /* Output files for select() */ -VAR int NeedReload VALUE(TRUE); +VAR int NeedReload VALUE(RELOAD_ALL); /* Need to load configuration? */ VAR char *TZ VALUE(NULL); /* Timezone configuration */ @@ -205,5 +214,5 @@ extern void StopServer(void); /* - * End of "$Id: cupsd.h,v 1.28.2.18 2003/03/31 16:48:27 mike Exp $". + * End of "$Id: cupsd.h,v 1.28.2.19 2003/04/10 20:15:52 mike Exp $". */ diff --git a/scheduler/job.c b/scheduler/job.c index 61f15f3b0..f2379df29 100644 --- a/scheduler/job.c +++ b/scheduler/job.c @@ -1,5 +1,5 @@ /* - * "$Id: job.c,v 1.124.2.63 2003/04/08 03:48:13 mike Exp $" + * "$Id: job.c,v 1.124.2.64 2003/04/10 20:15:53 mike Exp $" * * Job management routines for the Common UNIX Printing System (CUPS). * @@ -891,6 +891,7 @@ RestartJob(int id) /* I - Job ID */ if (job->state->values[0].integer == IPP_JOB_STOPPED || JobFiles) { + job->tries = 0; job->state->values[0].integer = IPP_JOB_PENDING; SaveJob(id); CheckJobs(); @@ -2377,11 +2378,31 @@ UpdateJob(job_t *job) /* I - Job to check */ else if (job->dtype & CUPS_PRINTER_FAX) { /* - * Hold the current job for 5 minutes... + * See how many times we've tried to send the job; if more than + * the limit, cancel the job. */ - job->state->values[0].integer = IPP_JOB_HELD; - job->hold_until = time(NULL) + 300; + job->tries ++; + + if (job->tries >= FaxRetryLimit) + { + /* + * Too many tries... + */ + + LogMessage(L_ERROR, "Canceling fax job %d since it could not be sent after %d tries.", + job->id, FaxRetryLimit); + CancelJob(job->id, 0); + } + else + { + /* + * Try again in N seconds... + */ + + job->state->values[0].integer = IPP_JOB_HELD; + job->hold_until = time(NULL) + FaxRetryInterval; + } CheckJobs(); } @@ -2729,5 +2750,5 @@ start_process(const char *command, /* I - Full path to command */ /* - * End of "$Id: job.c,v 1.124.2.63 2003/04/08 03:48:13 mike Exp $". + * End of "$Id: job.c,v 1.124.2.64 2003/04/10 20:15:53 mike Exp $". */ diff --git a/scheduler/job.h b/scheduler/job.h index 1057ae527..e5f3bcd94 100644 --- a/scheduler/job.h +++ b/scheduler/job.h @@ -1,5 +1,5 @@ /* - * "$Id: job.h,v 1.25.2.10 2003/03/30 21:49:21 mike Exp $" + * "$Id: job.h,v 1.25.2.11 2003/04/10 20:15:54 mike Exp $" * * Print job definitions for the Common UNIX Printing System (CUPS) scheduler. * @@ -60,6 +60,7 @@ typedef struct job_str printer_t *printer; /* Printer this job is assigned to */ char *buffer; /* Status buffer */ int bufused; /* Amount of buffer in use */ + int tries; /* Number of tries for this job */ } job_t; @@ -78,6 +79,8 @@ VAR int NumJobs VALUE(0), /* Number of jobs in queue */ ActiveJobs VALUE(0); /* Number of active jobs */ VAR job_t *Jobs VALUE(NULL); /* List of current jobs */ VAR int NextJobId VALUE(1); /* Next job ID to use */ +VAR int FaxRetryLimit VALUE(5), /* Max number of tries */ + FaxRetryInterval VALUE(300); /* Seconds between retries */ /* @@ -109,5 +112,5 @@ extern void UpdateJob(job_t *job); /* - * End of "$Id: job.h,v 1.25.2.10 2003/03/30 21:49:21 mike Exp $". + * End of "$Id: job.h,v 1.25.2.11 2003/04/10 20:15:54 mike Exp $". */ diff --git a/scheduler/log.c b/scheduler/log.c index 9ef867b41..2c0c52af2 100644 --- a/scheduler/log.c +++ b/scheduler/log.c @@ -1,5 +1,5 @@ /* - * "$Id: log.c,v 1.19.2.11 2003/03/30 20:01:47 mike Exp $" + * "$Id: log.c,v 1.19.2.12 2003/04/10 20:15:54 mike Exp $" * * Log file routines for the Common UNIX Printing System (CUPS). * @@ -445,8 +445,11 @@ check_log_file(cups_file_t **log, /* IO - Log file */ if ((*log = cupsFileOpen(filename, "a")) == NULL) return (0); - fchown(cupsFileNumber(*log), User, Group); - fchmod(cupsFileNumber(*log), LogFilePerm); + if (strncmp(filename, "/dev/", 5)) + { + fchown(cupsFileNumber(*log), User, Group); + fchmod(cupsFileNumber(*log), LogFilePerm); + } } /* @@ -470,8 +473,11 @@ check_log_file(cups_file_t **log, /* IO - Log file */ if ((*log = cupsFileOpen(filename, "a")) == NULL) return (0); - fchown(cupsFileNumber(*log), User, Group); - fchmod(cupsFileNumber(*log), LogFilePerm); + if (strncmp(filename, "/dev/", 5)) + { + fchown(cupsFileNumber(*log), User, Group); + fchmod(cupsFileNumber(*log), LogFilePerm); + } } return (1); @@ -479,5 +485,5 @@ check_log_file(cups_file_t **log, /* IO - Log file */ /* - * End of "$Id: log.c,v 1.19.2.11 2003/03/30 20:01:47 mike Exp $". + * End of "$Id: log.c,v 1.19.2.12 2003/04/10 20:15:54 mike Exp $". */ diff --git a/scheduler/main.c b/scheduler/main.c index 0059f5365..015783a13 100644 --- a/scheduler/main.c +++ b/scheduler/main.c @@ -1,5 +1,5 @@ /* - * "$Id: main.c,v 1.57.2.41 2003/03/30 20:01:48 mike Exp $" + * "$Id: main.c,v 1.57.2.42 2003/04/10 20:15:54 mike Exp $" * * Scheduler main loop for the Common UNIX Printing System (CUPS). * @@ -992,7 +992,7 @@ sighup_handler(int sig) /* I - Signal number */ { (void)sig; - NeedReload = TRUE; + NeedReload = RELOAD_ALL; #ifdef HAVE_SIGSET sigset(SIGHUP, sighup_handler); @@ -1026,39 +1026,9 @@ sigterm_handler(int sig) /* I - Signal */ * Close all network clients and stop all jobs... */ - CloseAllClients(); - StopListening(); - StopPolling(); - StopBrowsing(); - - if (Clients != NULL) - free(Clients); - - FreeAllJobs(); - - if (AccessFile != NULL) - cupsFileClose(AccessFile); - - if (ErrorFile != NULL) - cupsFileClose(ErrorFile); + StopServer(); - if (PageFile != NULL) - cupsFileClose(PageFile); - - DeleteAllLocations(); - - DeleteAllClasses(); - - if (Devices) - ippDelete(Devices); - - if (PPDs) - ippDelete(PPDs); - - DeleteAllPrinters(); - - if (MimeDatabase != NULL) - mimeDelete(MimeDatabase); + StopAllJobs(); #ifdef __sgi /* @@ -1094,11 +1064,11 @@ sigusr1_handler(int sig) /* I - Signal */ static void usage(void) { - fputs("Usage: cupsd [-c config-file] [-f]\n", stderr); + fputs("Usage: cupsd [-c config-file] [-f] [-F]\n", stderr); exit(1); } /* - * End of "$Id: main.c,v 1.57.2.41 2003/03/30 20:01:48 mike Exp $". + * End of "$Id: main.c,v 1.57.2.42 2003/04/10 20:15:54 mike Exp $". */ diff --git a/scheduler/server.c b/scheduler/server.c index 3e895884f..c28ee7b8a 100644 --- a/scheduler/server.c +++ b/scheduler/server.c @@ -1,5 +1,5 @@ /* - * "$Id: server.c,v 1.2.2.11 2003/03/30 20:01:49 mike Exp $" + * "$Id: server.c,v 1.2.2.12 2003/04/10 20:15:55 mike Exp $" * * Server start/stop routines for the Common UNIX Printing System (CUPS). * @@ -77,6 +77,8 @@ StartServer(void) */ gnutls_global_init(); +#elif defined(HAVE_CDSASSL) + ServerCertificatesArray = CDSAGetServerCerts(); #endif /* HAVE_LIBSSL */ /* @@ -120,7 +122,17 @@ StopServer(void) Clients = NULL; } - StopAllJobs(); +#if defined(HAVE_SSL) && defined(HAVE_CDSASSL) + /* + * Free all of the certificates... + */ + + if (ServerCertificatesArray) + { + CFRelease(ServerCertificatesArray); + ServerCertificatesArray = NULL; + } +#endif /* HAVE_SSL && HAVE_CDSASSL */ /* * Close the pipe for CGI processes... @@ -131,6 +143,11 @@ StopServer(void) close(CGIPipes[0]); close(CGIPipes[1]); + LogMessage(L_DEBUG2, "StopServer: Removing fd %d from InputSet...", + CGIPipes[0]); + + FD_CLR(CGIPipes[0], InputSet); + CGIPipes[0] = -1; CGIPipes[1] = -1; } @@ -159,16 +176,9 @@ StopServer(void) PageFile = NULL; } - - /* - * Clear the input and output sets... - */ - - memset(InputSet, 0, SetSize); - memset(OutputSet, 0, SetSize); } /* - * End of "$Id: server.c,v 1.2.2.11 2003/03/30 20:01:49 mike Exp $". + * End of "$Id: server.c,v 1.2.2.12 2003/04/10 20:15:55 mike Exp $". */ -- 2.39.2