/*
- * "$Id: main.c 5216 2006-03-02 17:47:53Z mike $"
+ * "$Id: main.c 177 2006-06-21 00:20:03Z jlovell $"
*
* Scheduler main loop for the Common UNIX Printing System (CUPS).
*
* main() - Main entry for the CUPS scheduler.
* cupsdClosePipe() - Close a pipe as necessary.
* cupsdOpenPipe() - Create a pipe which is closed on exec.
- * cupsdCatchChildSignals() - Catch SIGCHLD signals...
* cupsdHoldSignals() - Hold child and termination signals.
- * cupsdIgnoreChildSignals() - Ignore SIGCHLD signals...
* cupsdReleaseSignals() - Release signals for delivery.
* cupsdSetString() - Set a string value.
* cupsdSetStringf() - Set a formatted string value.
#endif /* HAVE_LAUNCHD */
break;
+ case 'p' : /* Stop immediately for profiling */
+ puts("Warning: -p option is for internal testing use only!");
+ stop_scheduler = 1;
+ fg = 1;
+ break;
+
default : /* Unknown option */
_cupsLangPrintf(stderr, _("cupsd: Unknown option \"%c\" - "
"aborting!\n"), *opt);
*/
#ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
+ sigset(SIGCHLD, sigchld_handler);
sigset(SIGHUP, sighup_handler);
sigset(SIGPIPE, SIG_IGN);
sigset(SIGTERM, sigterm_handler);
#elif defined(HAVE_SIGACTION)
memset(&action, 0, sizeof(action));
+ sigemptyset(&action.sa_mask);
+ sigaddset(&action.sa_mask, SIGTERM);
+ sigaddset(&action.sa_mask, SIGCHLD);
+ action.sa_handler = sigchld_handler;
+ sigaction(SIGCHLD, &action, NULL);
+
sigemptyset(&action.sa_mask);
sigaddset(&action.sa_mask, SIGHUP);
action.sa_handler = sighup_handler;
action.sa_handler = sigterm_handler;
sigaction(SIGTERM, &action, NULL);
#else
+ signal(SIGCLD, sigchld_handler); /* No, SIGCLD isn't a typo... */
signal(SIGHUP, sighup_handler);
signal(SIGPIPE, SIG_IGN);
signal(SIGTERM, sigterm_handler);
kill(i, SIGUSR1);
}
+#ifdef __APPLE__
/*
* Start power management framework...
*/
cupsdStartSystemMonitor();
-
- /*
- * Catch signals...
- */
-
- cupsdCatchChildSignals();
+#endif /* __APPLE__ */
/*
* Start any pending print jobs...
sptr += strlen(sptr);
}
- cupsdLogMessage(CUPSD_LOG_EMERG, s);
+ cupsdLogMessage(CUPSD_LOG_EMERG, "%s", s);
strcpy(s, "OutputSet =");
slen = 11;
sptr += strlen(sptr);
}
- cupsdLogMessage(CUPSD_LOG_EMERG, s);
+ cupsdLogMessage(CUPSD_LOG_EMERG, "%s", s);
for (i = 0, con = (cupsd_client_t *)cupsArrayFirst(Clients);
con;
mem.fsmblks + mem.fordblks);
#endif /* HAVE_MALLINFO */
- string_count = _cups_sp_statistics(&alloc_bytes, &total_bytes);
+ string_count = _cupsStrStatistics(&alloc_bytes, &total_bytes);
cupsdLogMessage(CUPSD_LOG_DEBUG2,
"stringpool: " CUPS_LLFMT " strings, "
CUPS_LLFMT " allocated, " CUPS_LLFMT " total bytes",
}
/*
- * Update the root certificate once every 5 minutes...
+ * Update the root certificate once every 5 minutes if we have client
+ * connections...
*/
if ((current_time - RootCertTime) >= RootCertDuration && RootCertDuration &&
- !RunUser)
+ !RunUser && cupsArrayCount(Clients))
{
/*
* Update the root certificate...
* accumulated. Don't send these more than once a second...
*/
- if (LastEvent && (time(NULL) - LastEventTime) > 1)
+ if (LastEvent)
{
#ifdef HAVE_NOTIFY_POST
if (LastEvent & CUPSD_EVENT_PRINTER_CHANGED)
#endif /* HAVE_NOTIFY_POST */
/*
- * Reset the accumulated events and notification time...
+ * Reset the accumulated events...
*/
- LastEventTime = time(NULL);
LastEvent = CUPSD_EVENT_NONE;
}
}
cupsdFreeAllJobs();
+#ifdef __APPLE__
cupsdStopSystemMonitor();
+#endif /* __APPLE__ */
#ifdef HAVE_LAUNCHD
/*
*/
if (pipe(fds))
+ {
+ fds[0] = -1;
+ fds[1] = -1;
+
return (-1);
+ }
/*
* Set the "close on exec" flag on each end of the pipe...
{
close(fds[0]);
close(fds[1]);
+
+ fds[0] = -1;
+ fds[1] = -1;
+
return (-1);
}
{
close(fds[0]);
close(fds[1]);
+
+ fds[0] = -1;
+ fds[1] = -1;
+
return (-1);
}
}
-/*
- * 'cupsdCatchChildSignals()' - Catch SIGCHLD signals...
- */
-
-void
-cupsdCatchChildSignals(void)
-{
-#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
- struct sigaction action; /* Actions for POSIX signals */
-#endif /* HAVE_SIGACTION && !HAVE_SIGSET */
-
-
-#ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
- sigset(SIGCHLD, sigchld_handler);
-#elif defined(HAVE_SIGACTION)
- memset(&action, 0, sizeof(action));
-
- sigemptyset(&action.sa_mask);
- sigaddset(&action.sa_mask, SIGTERM);
- sigaddset(&action.sa_mask, SIGCHLD);
- action.sa_handler = sigchld_handler;
- sigaction(SIGCHLD, &action, NULL);
-#else
- signal(SIGCLD, sigchld_handler); /* No, SIGCLD isn't a typo... */
-#endif /* HAVE_SIGSET */
-}
-
-
/*
* 'cupsdClearString()' - Clear a string.
*/
{
if (s && *s)
{
- free(*s);
+ _cupsStrFree(*s);
*s = NULL;
}
}
}
-/*
- * 'cupsdIgnoreChildSignals()' - Ignore SIGCHLD signals...
- *
- * We don't really ignore them, we set the signal handler to SIG_DFL,
- * since some OS's rely on signals for the wait4() function to work.
- */
-
-void
-cupsdIgnoreChildSignals(void)
-{
-#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
- struct sigaction action; /* Actions for POSIX signals */
-#endif /* HAVE_SIGACTION && !HAVE_SIGSET */
-
-
-#ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
- sigset(SIGCHLD, SIG_DFL);
-#elif defined(HAVE_SIGACTION)
- memset(&action, 0, sizeof(action));
-
- sigemptyset(&action.sa_mask);
- sigaddset(&action.sa_mask, SIGCHLD);
- action.sa_handler = SIG_DFL;
- sigaction(SIGCHLD, &action, NULL);
-#else
- signal(SIGCLD, SIG_DFL); /* No, SIGCLD isn't a typo... */
-#endif /* HAVE_SIGSET */
-}
-
-
/*
* 'cupsdReleaseSignals()' - Release signals for delivery.
*/
return;
if (*s)
- free(*s);
+ _cupsStrFree(*s);
if (v)
- *s = strdup(v);
+ *s = _cupsStrAlloc(v);
else
*s = NULL;
}
vsnprintf(v, sizeof(v), f, ap);
va_end(ap);
- *s = strdup(v);
+ *s = _cupsStrAlloc(v);
}
else
*s = NULL;
if (olds)
- free(olds);
+ _cupsStrFree(olds);
}
ld_resp, /* Launch data response */
ld_array, /* Launch data array */
ld_sockets, /* Launch data sockets dictionary */
- ld_runatload, /* Run-at-load setting */
tmp; /* Launch data */
cupsd_listener_t *lis; /* Listeners array */
http_addr_t addr; /* Address variable */
socklen_t addrlen; /* Length of address */
- bool runatload; /* Run-at-load setting value */
cupsdLogMessage(CUPSD_LOG_DEBUG, "launchd_checkin: pid=%d", (int)getpid());
exit(EXIT_FAILURE);
}
- /*
- * Get the "run-at-load" setting...
- */
-
- if ((ld_runatload =
- launch_data_dict_lookup(ld_resp, LAUNCH_JOBKEY_RUNATLOAD)) != NULL &&
- launch_data_get_type(ld_runatload) == LAUNCH_DATA_BOOL)
- runatload = launch_data_get_bool(ld_runatload);
- else
- {
- errno = launch_data_get_errno(ld_resp);
- cupsdLogMessage(CUPSD_LOG_ERROR,
- "launchd_checkin: Unable to find Run-at-load setting: %s",
- strerror(errno));
- exit(EXIT_FAILURE);
- }
-
- cupsdLogMessage(CUPSD_LOG_DEBUG, "launchd_checkin: Run-at-load=%s",
- runatload ? "true" : "false");
-
/*
* Get the sockets dictionary...
*/
{
if (launch_data_get_type(ld_array) == LAUNCH_DATA_ARRAY)
{
- tmp = launch_data_array_get_index(ld_array, 0);
-
- if (launch_data_get_type(tmp) == LAUNCH_DATA_FD)
+ if ((tmp = launch_data_array_get_index(ld_array, 0)))
{
- if (BrowseSocket != -1)
- close(BrowseSocket);
-
- BrowseSocket = launch_data_get_fd(tmp);
- }
- else
- cupsdLogMessage(CUPSD_LOG_WARN,
- "launchd_checkin: BrowseSocket not a fd!");
+ if (launch_data_get_type(tmp) == LAUNCH_DATA_FD)
+ {
+ if (BrowseSocket != -1)
+ close(BrowseSocket);
+
+ BrowseSocket = launch_data_get_fd(tmp);
+ }
+ else
+ cupsdLogMessage(CUPSD_LOG_WARN,
+ "launchd_checkin: BrowseSocket not a fd!");
+ }
+ else
+ cupsdLogMessage(CUPSD_LOG_WARN,
+ "launchd_checkin: BrowseSockets is an empty array!");
}
else
cupsdLogMessage(CUPSD_LOG_WARN,
if (fds || cupsArrayCount(Clients) > 50)
return (1);
- /*
- * If we had a recent event notification, timeout in 1 second...
- */
-
- if (LastEvent)
- return (1);
-
/*
* Otherwise, check all of the possible events that we need to wake for...
*/
/*
- * End of "$Id: main.c 5216 2006-03-02 17:47:53Z mike $".
+ * End of "$Id: main.c 177 2006-06-21 00:20:03Z jlovell $".
*/