diff options
author | jlovell <jlovell@a1ca3aef-8c08-0410-bb20-df032aa958be> | 2007-04-02 15:56:16 +0000 |
---|---|---|
committer | jlovell <jlovell@a1ca3aef-8c08-0410-bb20-df032aa958be> | 2007-04-02 15:56:16 +0000 |
commit | c0e1af835b65e53b4506f37f235c7cdc820dffa8 (patch) | |
tree | 02074fc1df79e914b7a6777ab1e6e9e6da1e79ad /scheduler | |
parent | f42414bf8a43f4c1b464bf1de9d357edba4fd439 (diff) | |
download | cups-c0e1af835b65e53b4506f37f235c7cdc820dffa8.tar.gz |
Load cups into easysw/current.
git-svn-id: svn+ssh://src.apple.com/svn/cups/easysw/current@303 a1ca3aef-8c08-0410-bb20-df032aa958be
Diffstat (limited to 'scheduler')
-rw-r--r-- | scheduler/classes.c | 27 | ||||
-rw-r--r-- | scheduler/conf.c | 13 | ||||
-rw-r--r-- | scheduler/job.c | 16 | ||||
-rw-r--r-- | scheduler/printers.c | 25 | ||||
-rw-r--r-- | scheduler/select.c | 66 |
5 files changed, 118 insertions, 29 deletions
diff --git a/scheduler/classes.c b/scheduler/classes.c index 63a818bfd..6e1080005 100644 --- a/scheduler/classes.c +++ b/scheduler/classes.c @@ -1,5 +1,5 @@ /* - * "$Id: classes.c 6318 2007-03-06 04:36:55Z mike $" + * "$Id: classes.c 6423 2007-04-02 13:05:19Z mike $" * * Printer class routines for the Common UNIX Printing System (CUPS). * @@ -266,6 +266,14 @@ cupsdFindAvailablePrinter( } /* + * Make sure that the last printer is also a valid index into the printer + * array. If not, reset the last printer to 0... + */ + + if (c->last_printer >= c->num_printers) + c->last_printer = 0; + + /* * Loop through the printers in the class and return the first idle * printer... We keep track of the last printer that we used so that * a "round robin" type of scheduling is realized (otherwise the first @@ -674,7 +682,20 @@ cupsdLoadAllClasses(void) else if (!strcasecmp(line, "OpPolicy")) { if (value) - cupsdSetString(&p->op_policy, value); + { + cupsd_policy_t *pol; /* Policy */ + + + if ((pol = cupsdFindPolicy(value)) != NULL) + { + cupsdSetString(&p->op_policy, value); + p->op_policy_ptr = pol; + } + else + cupsdLogMessage(CUPSD_LOG_ERROR, + "Bad policy \"%s\" on line %d of classes.conf", + value, linenum); + } else { cupsdLogMessage(CUPSD_LOG_ERROR, @@ -924,5 +945,5 @@ cupsdUpdateImplicitClasses(void) /* - * End of "$Id: classes.c 6318 2007-03-06 04:36:55Z mike $". + * End of "$Id: classes.c 6423 2007-04-02 13:05:19Z mike $". */ diff --git a/scheduler/conf.c b/scheduler/conf.c index 04a58bd4d..8c12d6322 100644 --- a/scheduler/conf.c +++ b/scheduler/conf.c @@ -1,5 +1,5 @@ /* - * "$Id: conf.c 6365 2007-03-19 20:56:57Z mike $" + * "$Id: conf.c 6409 2007-03-28 18:02:59Z mike $" * * Configuration routines for the Common UNIX Printing System (CUPS). * @@ -1165,7 +1165,7 @@ check_permissions(const char *filename, /* I - File/directory name */ { if (errno == ENOENT && create_dir) { - cupsdLogMessage(CUPSD_LOG_ERROR, "Creating missing directory \"%s\"", + cupsdLogMessage(CUPSD_LOG_DEBUG, "Creating missing directory \"%s\"", filename); if (mkdir(filename, mode)) @@ -1204,9 +1204,9 @@ check_permissions(const char *filename, /* I - File/directory name */ if (dir_created || fileinfo.st_uid != user || fileinfo.st_gid != group) { - cupsdLogMessage(CUPSD_LOG_WARN, "Repairing ownership of \"%s\"", filename); + cupsdLogMessage(CUPSD_LOG_DEBUG, "Repairing ownership of \"%s\"", filename); - if (chown(filename, user, group)) + if (chown(filename, user, group) && !getuid()) { cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to change ownership of \"%s\" - %s", filename, @@ -1217,7 +1217,8 @@ check_permissions(const char *filename, /* I - File/directory name */ if (dir_created || (fileinfo.st_mode & 07777) != mode) { - cupsdLogMessage(CUPSD_LOG_WARN, "Repairing access permissions of \"%s\"", filename); + cupsdLogMessage(CUPSD_LOG_DEBUG, "Repairing access permissions of \"%s\"", + filename); if (chmod(filename, mode)) { @@ -3348,5 +3349,5 @@ read_policy(cups_file_t *fp, /* I - Configuration file */ /* - * End of "$Id: conf.c 6365 2007-03-19 20:56:57Z mike $". + * End of "$Id: conf.c 6409 2007-03-28 18:02:59Z mike $". */ diff --git a/scheduler/job.c b/scheduler/job.c index aa94e5b00..caa318079 100644 --- a/scheduler/job.c +++ b/scheduler/job.c @@ -1,5 +1,5 @@ /* - * "$Id: job.c 6399 2007-03-26 14:27:48Z mike $" + * "$Id: job.c 6424 2007-04-02 13:09:06Z mike $" * * Job management routines for the Common UNIX Printing System (CUPS). * @@ -202,12 +202,11 @@ cupsdCancelJob(cupsd_job_t *job, /* I - Job to cancel */ case IPP_JOB_COMPLETED : /* - * Clear the printer's state_message and state_reasons and move on... + * Clear the printer's printer-state-message and move on... */ printer->state_message[0] = '\0'; - cupsdSetPrinterReasons(printer, ""); cupsdSetPrinterState(printer, IPP_PRINTER_IDLE, 0); cupsdAddEvent(CUPSD_EVENT_JOB_COMPLETED, printer, job, @@ -376,11 +375,12 @@ cupsdCheckJobs(void) pclass = printer; - if (!(pclass->type & CUPS_PRINTER_REMOTE) && - pclass->state != IPP_PRINTER_STOPPED) - printer = cupsdFindAvailablePrinter(job->dest); - else + if (pclass->state == IPP_PRINTER_STOPPED) printer = NULL; + else if (pclass->type & CUPS_PRINTER_REMOTE) + break; + else + printer = cupsdFindAvailablePrinter(printer->name); } if (!printer && !pclass) @@ -3536,5 +3536,5 @@ update_job(cupsd_job_t *job) /* I - Job to check */ /* - * End of "$Id: job.c 6399 2007-03-26 14:27:48Z mike $". + * End of "$Id: job.c 6424 2007-04-02 13:09:06Z mike $". */ diff --git a/scheduler/printers.c b/scheduler/printers.c index 9d10c837e..831d6008d 100644 --- a/scheduler/printers.c +++ b/scheduler/printers.c @@ -1,5 +1,5 @@ /* - * "$Id: printers.c 6383 2007-03-21 20:01:20Z mike $" + * "$Id: printers.c 6429 2007-04-02 13:44:52Z mike $" * * Printer routines for the Common UNIX Printing System (CUPS). * @@ -1194,7 +1194,20 @@ cupsdLoadAllPrinters(void) else if (!strcasecmp(line, "OpPolicy")) { if (value) - cupsdSetString(&p->op_policy, value); + { + cupsd_policy_t *pol; /* Policy */ + + + if ((pol = cupsdFindPolicy(value)) != NULL) + { + cupsdSetString(&p->op_policy, value); + p->op_policy_ptr = pol; + } + else + cupsdLogMessage(CUPSD_LOG_ERROR, + "Bad policy \"%s\" on line %d of printers.conf", + value, linenum); + } else { cupsdLogMessage(CUPSD_LOG_ERROR, @@ -2504,6 +2517,9 @@ cupsdSetPrinterReasons( (p->num_reasons - i) * sizeof(char *)); i --; + + if (!strcmp(reason, "paused") && p->state == IPP_PRINTER_STOPPED) + cupsdSetPrinterState(p, IPP_PRINTER_IDLE, 1); } } else if (p->num_reasons < (int)(sizeof(p->reasons) / sizeof(p->reasons[0]))) @@ -2520,6 +2536,9 @@ cupsdSetPrinterReasons( { p->reasons[i] = strdup(reason); p->num_reasons ++; + + if (!strcmp(reason, "paused") && p->state != IPP_PRINTER_STOPPED) + cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, 1); } } } @@ -3686,5 +3705,5 @@ write_irix_state(cupsd_printer_t *p) /* I - Printer to update */ /* - * End of "$Id: printers.c 6383 2007-03-21 20:01:20Z mike $". + * End of "$Id: printers.c 6429 2007-04-02 13:44:52Z mike $". */ diff --git a/scheduler/select.c b/scheduler/select.c index 960b0a37d..0e3b13813 100644 --- a/scheduler/select.c +++ b/scheduler/select.c @@ -1,5 +1,5 @@ /* - * "$Id: select.c 6376 2007-03-21 06:39:10Z mike $" + * "$Id: select.c 6428 2007-04-02 13:38:11Z mike $" * * Select abstraction functions for the Common UNIX Printing System (CUPS). * @@ -91,16 +91,17 @@ * * 0. Common Stuff * a. CUPS array of file descriptor to callback functions - * and data. - * b. cupsdStartSelect() creates the array - * c. cupsdStopSelect() destroys the array and all elements. + * and data + temporary array of removed fd's. + * b. cupsdStartSelect() creates the arrays + * c. cupsdStopSelect() destroys the arrays and all elements. * d. cupsdAddSelect() adds to the array and allocates a * new callback element. - * e. cupsdRemoveSelect() removes from the array and frees - * the callback element. + * e. cupsdRemoveSelect() removes from the active array and + * adds to the inactive array. * f. _cupsd_fd_t provides a reference-counted structure for * tracking file descriptors that are monitored. - * + * g. cupsdDoSelect() frees all inactive FDs. + * * 1. select() O(n) * a. Input/Output fd_set variables, copied to working * copies and then used with select(). @@ -217,6 +218,10 @@ typedef struct _cupsd_fd_s */ static cups_array_t *cupsd_fds = NULL; +#if defined(HAVE_EPOLL) || defined(HAVE_KQUEUE) +static cups_array_t *cupsd_inactive_fds = NULL; +static int cupsd_in_select = 0; +#endif /* HAVE_EPOLL || HAVE_KQUEUE */ #ifdef HAVE_EPOLL static int cupsd_epoll_fd = -1; @@ -432,6 +437,8 @@ cupsdDoSelect(long timeout) /* I - Timeout in seconds */ "cupsdDoSelect: polling %d fds for %ld seconds...", cupsArrayCount(cupsd_fds), timeout); + cupsd_in_select = 1; + if (timeout >= 0 && timeout < 86400) nfds = epoll_wait(cupsd_epoll_fd, cupsd_epoll_events, MaxFDs, timeout * 1000); @@ -445,6 +452,9 @@ cupsdDoSelect(long timeout) /* I - Timeout in seconds */ { fdptr = (_cupsd_fd_t *)event->data.ptr; + if (cupsArrayFind(cupsd_inactive_fds, fdptr)) + continue; + retain_fd(fdptr); if (fdptr->read_cb && (event->events & (EPOLLIN | EPOLLERR | EPOLLHUP))) @@ -474,6 +484,8 @@ cupsdDoSelect(long timeout) /* I - Timeout in seconds */ "cupsdDoSelect: polling %d fds for %ld seconds...", cupsArrayCount(cupsd_fds), timeout); + cupsd_in_select = 1; + if (timeout >= 0 && timeout < 86400) { ktimeout.tv_sec = timeout; @@ -495,6 +507,9 @@ cupsdDoSelect(long timeout) /* I - Timeout in seconds */ { fdptr = (_cupsd_fd_t *)event->udata; + if (cupsArrayFind(cupsd_inactive_fds, fdptr)) + continue; + cupsdLogMessage(CUPSD_LOG_DEBUG2, "event->filter=%d, event->ident=%d", event->filter, (int)event->ident); @@ -702,6 +717,22 @@ cupsdDoSelect(long timeout) /* I - Timeout in seconds */ #endif /* HAVE_EPOLL */ +#if defined(HAVE_EPOLL) || defined(HAVE_KQUEUE) + /* + * Release all inactive file descriptors... + */ + + cupsd_in_select = 0; + + for (fdptr = (_cupsd_fd_t *)cupsArrayFirst(cupsd_inactive_fds); + fdptr; + fdptr = (_cupsd_fd_t *)cupsArrayNext(cupsd_inactive_fds)) + { + cupsArrayRemove(cupsd_inactive_fds, fdptr); + release_fd(fdptr); + } +#endif /* HAVE_EPOLL || HAVE_KQUEUE */ + /* * Return the number of file descriptors handled... */ @@ -810,10 +841,18 @@ cupsdRemoveSelect(int fd) /* I - File descriptor */ #endif /* HAVE_EPOLL */ /* - * Remove the file descriptor for from the FD array... + * Remove the file descriptor from the active array and add to the + * inactive array (or release, if we don't need the inactive array...) */ cupsArrayRemove(cupsd_fds, fdptr); + +#if defined(HAVE_EPOLL) || defined(HAVE_KQUEUE) + if (cupsd_in_select) + cupsArrayAdd(cupsd_inactive_fds, fdptr); + else +#endif /* HAVE_EPOLL || HAVE_KQUEUE */ + release_fd(fdptr); } @@ -827,6 +866,10 @@ cupsdStartSelect(void) { cupsd_fds = cupsArrayNew((cups_array_func_t)compare_fds, NULL); +#if defined(HAVE_EPOLL) || defined(HAVE_KQUEUE) + cupsd_inactive_fds = cupsArrayNew((cups_array_func_t)compare_fds, NULL); +#endif /* HAVE_EPOLL || HAVE_KQUEUE */ + #ifdef HAVE_EPOLL cupsd_epoll_fd = epoll_create(MaxFDs); cupsd_epoll_events = calloc(MaxFDs, sizeof(struct epoll_event)); @@ -864,6 +907,11 @@ cupsdStopSelect(void) cupsArrayDelete(cupsd_fds); cupsd_fds = NULL; +#if defined(HAVE_EPOLL) || defined(HAVE_KQUEUE) + cupsArrayDelete(cupsd_inactive_fds); + cupsd_inactive_fds = NULL; +#endif /* HAVE_EPOLL || HAVE_KQUEUE */ + #ifdef HAVE_EPOLL if (cupsd_epoll_events) { @@ -944,5 +992,5 @@ find_fd(int fd) /* I - File descriptor */ /* - * End of "$Id: select.c 6376 2007-03-21 06:39:10Z mike $". + * End of "$Id: select.c 6428 2007-04-02 13:38:11Z mike $". */ |