2 * "$Id: main.c 7925 2008-09-10 17:47:26Z mike $"
4 * Main loop for the CUPS scheduler.
6 * Copyright 2007-2011 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * "LICENSE" which should have been included with this file. If this
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * main() - Main entry for the CUPS scheduler.
18 * cupsdAddString() - Copy and add a string to an array.
19 * cupsdCheckProcess() - Tell the main loop to check for dead children.
20 * cupsdClearString() - Clear a string.
21 * cupsdFreeStrings() - Free an array of strings.
22 * cupsdHoldSignals() - Hold child and termination signals.
23 * cupsdReleaseSignals() - Release signals for delivery.
24 * cupsdSetString() - Set a string value.
25 * cupsdSetStringf() - Set a formatted string value.
26 * launchd_checkin() - Check-in with launchd and collect the listening
28 * launchd_checkout() - Update the launchd KeepAlive file as needed.
29 * parent_handler() - Catch USR1/CHLD signals...
30 * process_children() - Process all dead children...
31 * select_timeout() - Calculate the select timeout value.
32 * sigchld_handler() - Handle 'child' signals from old processes.
33 * sighup_handler() - Handle 'hangup' signals to reconfigure the
35 * sigterm_handler() - Handle 'terminate' signals that stop the scheduler.
36 * usage() - Show scheduler usage.
40 * Include necessary headers...
45 #include <sys/resource.h>
52 # define CUPS_KEEPALIVE CUPS_CACHEDIR "/org.cups.cupsd"
53 /* Name of the launchd KeepAlive file */
54 # ifndef LAUNCH_JOBKEY_KEEPALIVE
55 # define LAUNCH_JOBKEY_KEEPALIVE "KeepAlive"
56 # endif /* !LAUNCH_JOBKEY_KEEPALIVE */
57 # ifndef LAUNCH_JOBKEY_PATHSTATE
58 # define LAUNCH_JOBKEY_PATHSTATE "PathState"
59 # endif /* !LAUNCH_JOBKEY_PATHSTATE */
60 # ifndef LAUNCH_JOBKEY_SERVICEIPC
61 # define LAUNCH_JOBKEY_SERVICEIPC "ServiceIPC"
62 # endif /* !LAUNCH_JOBKEY_SERVICEIPC */
63 #endif /* HAVE_LAUNCH_H */
65 #if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
67 #endif /* HAVE_MALLOC_H && HAVE_MALLINFO */
70 #endif /* HAVE_NOTIFY_H */
78 static void launchd_checkin(void);
79 static void launchd_checkout(void);
80 #endif /* HAVE_LAUNCHD */
81 static void parent_handler(int sig
);
82 static void process_children(void);
83 static void sigchld_handler(int sig
);
84 static void sighup_handler(int sig
);
85 static void sigterm_handler(int sig
);
86 static long select_timeout(int fds
);
87 static void usage(int status
) __attribute__((noreturn
));
94 static int parent_signal
= 0;
95 /* Set to signal number from child */
96 static int holdcount
= 0; /* Number of times "hold" was called */
97 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
98 static sigset_t holdmask
; /* Old POSIX signal mask */
99 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
100 static int dead_children
= 0;
102 static int stop_scheduler
= 0;
103 /* Should the scheduler stop? */
107 * 'main()' - Main entry for the CUPS scheduler.
110 int /* O - Exit status */
111 main(int argc
, /* I - Number of command-line args */
112 char *argv
[]) /* I - Command-line arguments */
114 int i
; /* Looping var */
115 char *opt
; /* Option character */
116 int fg
; /* Run in the foreground */
117 int fds
; /* Number of ready descriptors */
118 cupsd_client_t
*con
; /* Current client */
119 cupsd_job_t
*job
; /* Current job */
120 cupsd_listener_t
*lis
; /* Current listener */
121 time_t current_time
, /* Current time */
122 activity
, /* Client activity timer */
123 browse_time
, /* Next browse send time */
124 senddoc_time
, /* Send-Document time */
125 expire_time
, /* Subscription expire time */
126 report_time
, /* Malloc/client/job report time */
127 event_time
; /* Last event notification time */
128 long timeout
; /* Timeout for cupsdDoSelect() */
129 struct rlimit limit
; /* Runtime limit */
130 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
131 struct sigaction action
; /* Actions for POSIX signals */
132 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
134 cups_file_t
*fp
; /* Fake lpsched lock file */
135 struct stat statbuf
; /* Needed for checking lpsched FIFO */
137 int run_as_child
= 0;
138 /* Needed for background fork/exec */
140 int use_sysman
= !getuid();
141 /* Use system management functions? */
143 time_t netif_time
= 0; /* Time since last network update */
144 #endif /* __APPLE__ */
146 int launchd_idle_exit
;
147 /* Idle exit on select timeout? */
148 #endif /* HAVE_LAUNCHD */
153 * Check for setuid invocation, which we do not support!
156 if (getuid() != geteuid())
158 fputs("cupsd: Cannot run as a setuid program\n", stderr
);
161 #endif /* HAVE_GETEUID */
164 * Check for command-line arguments...
170 if (getenv("CUPSD_LAUNCHD"))
175 #endif /* HAVE_LAUNCHD */
177 for (i
= 1; i
< argc
; i
++)
178 if (argv
[i
][0] == '-')
179 for (opt
= argv
[i
] + 1; *opt
!= '\0'; opt
++)
182 case 'C' : /* Run as child with config file */
186 case 'c' : /* Configuration file */
190 _cupsLangPuts(stderr
, _("cupsd: Expected config filename "
191 "after \"-c\" option."));
195 if (argv
[i
][0] == '/')
198 * Absolute directory...
201 cupsdSetString(&ConfigurationFile
, argv
[i
]);
206 * Relative directory...
209 char *current
; /* Current directory */
213 * Allocate a buffer for the current working directory to
214 * reduce run-time stack usage; this approximates the
215 * behavior of some implementations of getcwd() when they
216 * are passed a NULL pointer.
219 if ((current
= malloc(1024)) == NULL
)
221 _cupsLangPuts(stderr
,
222 _("cupsd: Unable to get current directory."));
226 if (!getcwd(current
, 1024))
228 _cupsLangPuts(stderr
,
229 _("cupsd: Unable to get current directory."));
234 cupsdSetStringf(&ConfigurationFile
, "%s/%s", current
, argv
[i
]);
239 case 'f' : /* Run in foreground... */
243 case 'F' : /* Run in foreground, but disconnect from terminal... */
247 case 'h' : /* Show usage/help */
251 case 'l' : /* Started by launchd... */
256 _cupsLangPuts(stderr
, _("cupsd: launchd(8) support not compiled "
257 "in, running in normal mode."));
259 #endif /* HAVE_LAUNCHD */
262 case 'p' : /* Stop immediately for profiling */
263 fputs("cupsd: -p (startup profiling) is for internal testing "
264 "use only!\n", stderr
);
269 case 'P' : /* Disable security profiles */
270 fputs("cupsd: -P (disable security profiles) is for internal "
271 "testing use only!\n", stderr
);
276 case 'S' : /* Disable system management functions */
277 fputs("cupsd: -S (disable system management) for internal "
278 "testing use only!\n", stderr
);
281 #endif /* __APPLE__ */
283 case 't' : /* Test the cupsd.conf file... */
288 default : /* Unknown option */
289 _cupsLangPrintf(stderr
, _("cupsd: Unknown option \"%c\" - "
296 _cupsLangPrintf(stderr
, _("cupsd: Unknown argument \"%s\" - aborting."),
301 if (!ConfigurationFile
)
302 cupsdSetString(&ConfigurationFile
, CUPS_SERVERROOT
"/cupsd.conf");
305 * If the user hasn't specified "-f", run in the background...
311 * Setup signal handlers for the parent...
314 #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
315 sigset(SIGUSR1
, parent_handler
);
316 sigset(SIGCHLD
, parent_handler
);
318 sigset(SIGHUP
, SIG_IGN
);
319 #elif defined(HAVE_SIGACTION)
320 memset(&action
, 0, sizeof(action
));
321 sigemptyset(&action
.sa_mask
);
322 sigaddset(&action
.sa_mask
, SIGUSR1
);
323 action
.sa_handler
= parent_handler
;
324 sigaction(SIGUSR1
, &action
, NULL
);
325 sigaction(SIGCHLD
, &action
, NULL
);
327 sigemptyset(&action
.sa_mask
);
328 action
.sa_handler
= SIG_IGN
;
329 sigaction(SIGHUP
, &action
, NULL
);
331 signal(SIGUSR1
, parent_handler
);
332 signal(SIGCLD
, parent_handler
);
334 signal(SIGHUP
, SIG_IGN
);
335 #endif /* HAVE_SIGSET */
340 * OK, wait for the child to startup and send us SIGUSR1 or to crash
341 * and the OS send us SIGCHLD... We also need to ignore SIGHUP which
342 * might be sent by the init script to restart the scheduler...
345 for (; parent_signal
== 0;)
348 if (parent_signal
== SIGUSR1
)
356 else if (WIFEXITED(i
))
358 fprintf(stderr
, "cupsd: Child exited with status %d\n",
364 fprintf(stderr
, "cupsd: Child exited on signal %d\n", WTERMSIG(i
));
371 * Call _thread_sys_closefrom() so the child process doesn't reset the
372 * parent's file descriptors to be blocking. This is a workaround for a
373 * limitation of userland libpthread on OpenBSD.
376 _thread_sys_closefrom(0);
377 #endif /* __OpenBSD__ */
380 * Since CoreFoundation and DBUS both create fork-unsafe data on execution of
381 * a program, and since this kind of really unfriendly behavior seems to be
382 * more common these days in system libraries, we need to re-execute the
383 * background cupsd with the "-C" option to avoid problems. Unfortunately,
384 * we also have to assume that argv[0] contains the name of the cupsd
385 * executable - there is no portable way to get the real pathname...
388 execlp(argv
[0], argv
[0], "-C", ConfigurationFile
, (char *)0);
395 * Make sure we aren't tying up any filesystems...
402 * Disable core dumps...
405 getrlimit(RLIMIT_CORE
, &limit
);
407 setrlimit(RLIMIT_CORE
, &limit
);
410 * Disconnect from the controlling terminal...
416 * Close all open files...
419 getrlimit(RLIMIT_NOFILE
, &limit
);
421 for (i
= 0; i
< limit
.rlim_cur
&& i
< 1024; i
++)
425 * Redirect stdin/out/err to /dev/null...
428 if ((i
= open("/dev/null", O_RDONLY
)) != 0)
434 if ((i
= open("/dev/null", O_WRONLY
)) != 1)
440 if ((i
= open("/dev/null", O_WRONLY
)) != 2)
449 * Set the timezone info...
455 setlocale(LC_TIME
, "");
459 * Set the maximum number of files...
462 getrlimit(RLIMIT_NOFILE
, &limit
);
464 #if !defined(HAVE_POLL) && !defined(HAVE_EPOLL) && !defined(HAVE_KQUEUE)
465 if (limit
.rlim_max
> FD_SETSIZE
)
468 #endif /* !HAVE_POLL && !HAVE_EPOLL && !HAVE_KQUEUE */
470 if (limit
.rlim_max
== RLIM_INFINITY
)
473 #endif /* RLIM_INFINITY */
474 MaxFDs
= limit
.rlim_max
;
476 limit
.rlim_cur
= MaxFDs
;
478 setrlimit(RLIMIT_NOFILE
, &limit
);
483 * Read configuration...
486 if (!cupsdReadConfiguration())
489 printf("%s contains errors\n", ConfigurationFile
);
491 syslog(LOG_LPR
, "Unable to read configuration file \'%s\' - exiting!",
495 else if (TestConfigFile
)
497 printf("%s is OK\n", ConfigurationFile
);
502 * Clean out old temp files and printer cache data.
505 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
506 cupsdCleanFiles(TempDir
, NULL
);
508 cupsdCleanFiles(CacheDir
, "*.ipp");
514 * If we were started by launchd get the listen sockets file descriptors...
520 #endif /* HAVE_LAUNCHD */
523 * Startup the server...
531 * Catch hangup and child signals and ignore broken pipes...
534 #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
535 sigset(SIGCHLD
, sigchld_handler
);
536 sigset(SIGHUP
, sighup_handler
);
537 sigset(SIGPIPE
, SIG_IGN
);
538 sigset(SIGTERM
, sigterm_handler
);
539 #elif defined(HAVE_SIGACTION)
540 memset(&action
, 0, sizeof(action
));
542 sigemptyset(&action
.sa_mask
);
543 sigaddset(&action
.sa_mask
, SIGTERM
);
544 sigaddset(&action
.sa_mask
, SIGCHLD
);
545 action
.sa_handler
= sigchld_handler
;
546 sigaction(SIGCHLD
, &action
, NULL
);
548 sigemptyset(&action
.sa_mask
);
549 sigaddset(&action
.sa_mask
, SIGHUP
);
550 action
.sa_handler
= sighup_handler
;
551 sigaction(SIGHUP
, &action
, NULL
);
553 sigemptyset(&action
.sa_mask
);
554 action
.sa_handler
= SIG_IGN
;
555 sigaction(SIGPIPE
, &action
, NULL
);
557 sigemptyset(&action
.sa_mask
);
558 sigaddset(&action
.sa_mask
, SIGTERM
);
559 sigaddset(&action
.sa_mask
, SIGCHLD
);
560 action
.sa_handler
= sigterm_handler
;
561 sigaction(SIGTERM
, &action
, NULL
);
563 signal(SIGCLD
, sigchld_handler
); /* No, SIGCLD isn't a typo... */
564 signal(SIGHUP
, sighup_handler
);
565 signal(SIGPIPE
, SIG_IGN
);
566 signal(SIGTERM
, sigterm_handler
);
567 #endif /* HAVE_SIGSET */
571 * Try to create a fake lpsched lock file if one is not already there.
572 * Some Adobe applications need it under IRIX in order to enable
576 if ((fp
= cupsFileOpen("/var/spool/lp/SCHEDLOCK", "w")) == NULL
)
578 syslog(LOG_LPR
, "Unable to create fake lpsched lock file "
579 "\"/var/spool/lp/SCHEDLOCK\"\' - %s!",
584 fchmod(cupsFileNumber(fp
), 0644);
585 fchown(cupsFileNumber(fp
), User
, Group
);
592 * Initialize authentication certificates...
598 * If we are running in the background, signal the parent process that
599 * we are up and running...
602 if (!fg
|| run_as_child
)
605 * Send a signal to the parent process, but only if the parent is
606 * not PID 1 (init). This avoids accidentally shutting down the
607 * system on OpenBSD if you CTRL-C the server before it is up...
610 i
= getppid(); /* Save parent PID to avoid race condition */
618 * Start power management framework...
622 cupsdStartSystemMonitor();
623 #endif /* __APPLE__ */
626 * Send server-started event...
631 cupsdAddEvent(CUPSD_EVENT_SERVER_STARTED
, NULL
, NULL
,
632 "Scheduler started via launchd.");
634 #endif /* HAVE_LAUNCHD */
636 cupsdAddEvent(CUPSD_EVENT_SERVER_STARTED
, NULL
, NULL
,
637 "Scheduler started in foreground.");
639 cupsdAddEvent(CUPSD_EVENT_SERVER_STARTED
, NULL
, NULL
,
640 "Scheduler started in background.");
643 * Start any pending print jobs...
652 current_time
= time(NULL
);
653 browse_time
= current_time
;
654 event_time
= current_time
;
655 expire_time
= current_time
;
658 senddoc_time
= current_time
;
660 while (!stop_scheduler
)
663 * Check if there are dead children to handle...
670 * Check if we need to load the server configuration file...
676 * Close any idle clients...
679 if (cupsArrayCount(Clients
) > 0)
681 for (con
= (cupsd_client_t
*)cupsArrayFirst(Clients
);
683 con
= (cupsd_client_t
*)cupsArrayNext(Clients
))
684 if (con
->http
.state
== HTTP_WAITING
)
685 cupsdCloseClient(con
);
687 con
->http
.keep_alive
= HTTP_KEEPALIVE_OFF
;
689 cupsdPauseListening();
693 * Restart if all clients are closed and all jobs finished, or
694 * if the reload timeout has elapsed...
697 if ((cupsArrayCount(Clients
) == 0 &&
698 (cupsArrayCount(PrintingJobs
) == 0 || NeedReload
!= RELOAD_ALL
)) ||
699 (time(NULL
) - ReloadTime
) >= ReloadTimeout
)
702 * Shutdown the server...
710 * Read configuration...
713 if (!cupsdReadConfiguration())
715 syslog(LOG_LPR
, "Unable to read configuration file \'%s\' - exiting!",
724 * If we were started by launchd, get the listen socket file
731 #endif /* HAVE_LAUNCHD */
734 * Startup the server...
742 * Send a server-restarted event...
745 cupsdAddEvent(CUPSD_EVENT_SERVER_RESTARTED
, NULL
, NULL
,
746 "Scheduler restarted.");
751 * Check for available input or ready output. If cupsdDoSelect()
752 * returns 0 or -1, something bad happened and we should exit
755 * Note that we at least have one listening socket open at all
759 if ((timeout
= select_timeout(fds
)) > 1 && LastEvent
)
764 * If no other work is scheduled and we're being controlled by
765 * launchd then timeout after 'LaunchdTimeout' seconds of
769 if (timeout
== 86400 && Launchd
&& LaunchdTimeout
&& !NumPolled
&&
770 !cupsArrayCount(ActiveJobs
) &&
772 (!BrowseRemoteProtocols
&&
773 (!BrowseLocalProtocols
|| !cupsArrayCount(Printers
)))))
775 timeout
= LaunchdTimeout
;
776 launchd_idle_exit
= 1;
779 launchd_idle_exit
= 0;
780 #endif /* HAVE_LAUNCHD */
782 if ((fds
= cupsdDoSelect(timeout
)) < 0)
785 * Got an error from select!
789 cupsd_printer_t
*p
; /* Current printer */
790 #endif /* HAVE_DNSSD */
793 if (errno
== EINTR
) /* Just interrupted by a signal */
797 * Log all sorts of debug info to help track down the problem.
800 cupsdLogMessage(CUPSD_LOG_EMERG
, "cupsdDoSelect() failed - %s!",
803 for (i
= 0, con
= (cupsd_client_t
*)cupsArrayFirst(Clients
);
805 i
++, con
= (cupsd_client_t
*)cupsArrayNext(Clients
))
806 cupsdLogMessage(CUPSD_LOG_EMERG
,
807 "Clients[%d] = %d, file = %d, state = %d",
808 i
, con
->http
.fd
, con
->file
, con
->http
.state
);
810 for (i
= 0, lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
812 i
++, lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
813 cupsdLogMessage(CUPSD_LOG_EMERG
, "Listeners[%d] = %d", i
, lis
->fd
);
815 cupsdLogMessage(CUPSD_LOG_EMERG
, "BrowseSocket = %d", BrowseSocket
);
817 cupsdLogMessage(CUPSD_LOG_EMERG
, "CGIPipes[0] = %d", CGIPipes
[0]);
820 cupsdLogMessage(CUPSD_LOG_EMERG
, "SysEventPipes[0] = %d",
822 #endif /* __APPLE__ */
824 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
826 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
827 cupsdLogMessage(CUPSD_LOG_EMERG
, "Jobs[%d] = %d < [%d %d] > [%d %d]",
829 job
->status_buffer
? job
->status_buffer
->fd
: -1,
830 job
->print_pipes
[0], job
->print_pipes
[1],
831 job
->back_pipes
[0], job
->back_pipes
[1]);
834 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
836 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
837 cupsdLogMessage(CUPSD_LOG_EMERG
, "printer[%s] reg_name=\"%s\"", p
->name
,
838 p
->reg_name
? p
->reg_name
: "(null)");
839 #endif /* HAVE_DNSSD */
844 current_time
= time(NULL
);
847 * Write dirty config/state files...
850 if (DirtyCleanTime
&& current_time
>= DirtyCleanTime
)
855 * If we are going to sleep and still have pending jobs, stop them after
856 * a period of time...
859 if (SleepJobs
> 0 && current_time
>= SleepJobs
&&
860 cupsArrayCount(PrintingJobs
) > 0)
863 cupsdStopAllJobs(CUPSD_JOB_DEFAULT
, 5);
865 #endif /* __APPLE__ */
869 * Update the network interfaces once a minute...
872 if ((current_time
- netif_time
) >= 60)
874 netif_time
= current_time
;
877 #endif /* !__APPLE__ */
881 * If no other work was scheduled and we're being controlled by launchd
882 * then timeout after 'LaunchdTimeout' seconds of inactivity...
885 if (!fds
&& launchd_idle_exit
)
887 cupsdLogMessage(CUPSD_LOG_INFO
,
888 "Printer sharing is off and there are no jobs pending, "
889 "will restart on demand.");
893 #endif /* HAVE_LAUNCHD */
896 * Resume listening for new connections as needed...
899 if (ListeningPaused
&& ListeningPaused
<= current_time
&&
900 cupsArrayCount(Clients
) < MaxClients
)
901 cupsdResumeListening();
904 * Expire subscriptions and unload completed jobs as needed...
907 if (current_time
> expire_time
)
909 if (cupsArrayCount(Subscriptions
) > 0)
910 cupsdExpireSubscriptions(NULL
, NULL
);
912 cupsdUnloadCompletedJobs();
914 expire_time
= current_time
;
918 * Update the browse list as needed...
924 if ((BrowseRemoteProtocols
& BROWSE_SLP
) &&
925 BrowseSLPRefresh
<= current_time
)
926 cupsdUpdateSLPBrowse();
927 #endif /* HAVE_LIBSLP */
930 if ((BrowseRemoteProtocols
& BROWSE_LDAP
) &&
931 BrowseLDAPRefresh
<= current_time
)
932 cupsdUpdateLDAPBrowse();
933 #endif /* HAVE_LDAP */
936 if (Browsing
&& current_time
> browse_time
)
938 cupsdSendBrowseList();
939 browse_time
= current_time
;
942 #ifndef HAVE_AUTHORIZATION_H
944 * Update the root certificate once every 5 minutes if we have client
948 if ((current_time
- RootCertTime
) >= RootCertDuration
&& RootCertDuration
&&
949 !RunUser
&& cupsArrayCount(Clients
))
952 * Update the root certificate...
956 cupsdAddCert(0, "root", NULL
);
958 #endif /* !HAVE_AUTHORIZATION_H */
961 * Check for new data on the client sockets...
964 for (con
= (cupsd_client_t
*)cupsArrayFirst(Clients
);
966 con
= (cupsd_client_t
*)cupsArrayNext(Clients
))
969 * Process pending data in the input buffer...
974 cupsdReadClient(con
);
979 * Check the activity and close old clients...
982 activity
= current_time
- Timeout
;
983 if (con
->http
.activity
< activity
&& !con
->pipe_pid
)
985 cupsdLogMessage(CUPSD_LOG_DEBUG
,
986 "Closing client %d after %d seconds of inactivity...",
987 con
->http
.fd
, Timeout
);
989 cupsdCloseClient(con
);
995 * Update any pending multi-file documents...
998 if ((current_time
- senddoc_time
) >= 10)
1002 senddoc_time
= current_time
;
1006 * Log statistics at most once a minute when in debug mode...
1009 if ((current_time
- report_time
) >= 60 && LogLevel
>= CUPSD_LOG_DEBUG
)
1011 size_t string_count
, /* String count */
1012 alloc_bytes
, /* Allocated string bytes */
1013 total_bytes
; /* Total string bytes */
1014 #ifdef HAVE_MALLINFO
1015 struct mallinfo mem
; /* Malloc information */
1019 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Report: malloc-arena=%lu", mem
.arena
);
1020 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Report: malloc-used=%lu",
1021 mem
.usmblks
+ mem
.uordblks
);
1022 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Report: malloc-free=%lu",
1023 mem
.fsmblks
+ mem
.fordblks
);
1024 #endif /* HAVE_MALLINFO */
1026 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Report: clients=%d",
1027 cupsArrayCount(Clients
));
1028 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Report: jobs=%d",
1029 cupsArrayCount(Jobs
));
1030 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Report: jobs-active=%d",
1031 cupsArrayCount(ActiveJobs
));
1032 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Report: printers=%d",
1033 cupsArrayCount(Printers
));
1034 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Report: printers-implicit=%d",
1035 cupsArrayCount(ImplicitPrinters
));
1037 string_count
= _cupsStrStatistics(&alloc_bytes
, &total_bytes
);
1038 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1039 "Report: stringpool-string-count=" CUPS_LLFMT
,
1040 CUPS_LLCAST string_count
);
1041 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1042 "Report: stringpool-alloc-bytes=" CUPS_LLFMT
,
1043 CUPS_LLCAST alloc_bytes
);
1044 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1045 "Report: stringpool-total-bytes=" CUPS_LLFMT
,
1046 CUPS_LLCAST total_bytes
);
1048 report_time
= current_time
;
1052 * Handle OS-specific event notification for any events that have
1053 * accumulated. Don't send these more than once a second...
1056 if (LastEvent
&& (current_time
- event_time
) >= 1)
1058 #ifdef HAVE_NOTIFY_POST
1059 if (LastEvent
& (CUPSD_EVENT_PRINTER_ADDED
|
1060 CUPSD_EVENT_PRINTER_DELETED
|
1061 CUPSD_EVENT_PRINTER_MODIFIED
))
1063 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1064 "notify_post(\"com.apple.printerListChange\")");
1065 notify_post("com.apple.printerListChange");
1068 if (LastEvent
& CUPSD_EVENT_PRINTER_STATE_CHANGED
)
1070 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1071 "notify_post(\"com.apple.printerHistoryChange\")");
1072 notify_post("com.apple.printerHistoryChange");
1075 if (LastEvent
& (CUPSD_EVENT_JOB_STATE_CHANGED
|
1076 CUPSD_EVENT_JOB_CONFIG_CHANGED
|
1077 CUPSD_EVENT_JOB_PROGRESS
))
1079 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1080 "notify_post(\"com.apple.jobChange\")");
1081 notify_post("com.apple.jobChange");
1083 #endif /* HAVE_NOTIFY_POST */
1086 * Reset the accumulated events...
1089 LastEvent
= CUPSD_EVENT_NONE
;
1090 event_time
= current_time
;
1095 * Log a message based on what happened...
1100 cupsdLogMessage(CUPSD_LOG_INFO
, "Scheduler shutting down normally.");
1101 cupsdAddEvent(CUPSD_EVENT_SERVER_STOPPED
, NULL
, NULL
,
1102 "Scheduler shutting down normally.");
1106 cupsdLogMessage(CUPSD_LOG_ERROR
,
1107 "Scheduler shutting down due to program error.");
1108 cupsdAddEvent(CUPSD_EVENT_SERVER_STOPPED
, NULL
, NULL
,
1109 "Scheduler shutting down due to program error.");
1113 * Close all network clients...
1122 * Update the launchd KeepAlive file as needed...
1127 #endif /* HAVE_LAUNCHD */
1137 * Stop monitoring system event monitoring...
1141 cupsdStopSystemMonitor();
1142 #endif /* __APPLE__ */
1146 * Free the scheduler's Kerberos context...
1151 * If the weak-linked GSSAPI/Kerberos library is not present, don't try
1155 if (krb5_init_context
!= NULL
)
1156 # endif /* __APPLE__ */
1157 if (KerberosContext
)
1158 krb5_free_context(KerberosContext
);
1159 #endif /* HAVE_GSSAPI */
1163 * Remove the fake IRIX lpsched lock file, but only if the existing
1164 * file is not a FIFO which indicates that the real IRIX lpsched is
1168 if (!stat("/var/spool/lp/FIFO", &statbuf
))
1169 if (!S_ISFIFO(statbuf
.st_mode
))
1170 unlink("/var/spool/lp/SCHEDLOCK");
1175 return (!stop_scheduler
);
1180 * 'cupsdAddString()' - Copy and add a string to an array.
1183 int /* O - 1 on success, 0 on failure */
1184 cupsdAddString(cups_array_t
**a
, /* IO - String array */
1185 const char *s
) /* I - String to copy and add */
1188 *a
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
,
1189 (cups_ahash_func_t
)NULL
, 0,
1190 (cups_acopy_func_t
)_cupsStrAlloc
,
1191 (cups_afree_func_t
)_cupsStrFree
);
1193 return (cupsArrayAdd(*a
, (char *)s
));
1198 * 'cupsdCheckProcess()' - Tell the main loop to check for dead children.
1202 cupsdCheckProcess(void)
1205 * Flag that we have dead children...
1213 * 'cupsdClearString()' - Clear a string.
1217 cupsdClearString(char **s
) /* O - String value */
1228 * 'cupsdFreeStrings()' - Free an array of strings.
1232 cupsdFreeStrings(cups_array_t
**a
) /* IO - String array */
1236 cupsArrayDelete(*a
);
1243 * 'cupsdHoldSignals()' - Hold child and termination signals.
1247 cupsdHoldSignals(void)
1249 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
1250 sigset_t newmask
; /* New POSIX signal mask */
1251 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
1261 #elif defined(HAVE_SIGACTION)
1262 sigemptyset(&newmask
);
1263 sigaddset(&newmask
, SIGTERM
);
1264 sigaddset(&newmask
, SIGCHLD
);
1265 sigprocmask(SIG_BLOCK
, &newmask
, &holdmask
);
1266 #endif /* HAVE_SIGSET */
1271 * 'cupsdReleaseSignals()' - Release signals for delivery.
1275 cupsdReleaseSignals(void)
1284 #elif defined(HAVE_SIGACTION)
1285 sigprocmask(SIG_SETMASK
, &holdmask
, NULL
);
1286 #endif /* HAVE_SIGSET */
1291 * 'cupsdSetString()' - Set a string value.
1295 cupsdSetString(char **s
, /* O - New string */
1296 const char *v
) /* I - String value */
1305 *s
= _cupsStrAlloc(v
);
1312 * 'cupsdSetStringf()' - Set a formatted string value.
1316 cupsdSetStringf(char **s
, /* O - New string */
1317 const char *f
, /* I - Printf-style format string */
1318 ...) /* I - Additional args as needed */
1320 char v
[4096]; /* Formatting string value */
1321 va_list ap
; /* Argument pointer */
1322 char *olds
; /* Old string */
1333 vsnprintf(v
, sizeof(v
), f
, ap
);
1336 *s
= _cupsStrAlloc(v
);
1348 * 'launchd_checkin()' - Check-in with launchd and collect the listening fds.
1352 launchd_checkin(void)
1354 size_t i
, /* Looping var */
1355 count
; /* Number of listeners */
1356 launch_data_t ld_msg
, /* Launch data message */
1357 ld_resp
, /* Launch data response */
1358 ld_array
, /* Launch data array */
1359 ld_sockets
, /* Launch data sockets dictionary */
1360 tmp
; /* Launch data */
1361 cupsd_listener_t
*lis
; /* Listeners array */
1362 http_addr_t addr
; /* Address variable */
1363 socklen_t addrlen
; /* Length of address */
1364 int fd
; /* File descriptor */
1365 char s
[256]; /* String addresss */
1368 cupsdLogMessage(CUPSD_LOG_DEBUG
, "launchd_checkin: pid=%d", (int)getpid());
1371 * Check-in with launchd...
1374 ld_msg
= launch_data_new_string(LAUNCH_KEY_CHECKIN
);
1375 if ((ld_resp
= launch_msg(ld_msg
)) == NULL
)
1377 cupsdLogMessage(CUPSD_LOG_ERROR
,
1378 "launchd_checkin: launch_msg(\"" LAUNCH_KEY_CHECKIN
1381 return; /* anti-compiler-warning */
1384 if (launch_data_get_type(ld_resp
) == LAUNCH_DATA_ERRNO
)
1386 errno
= launch_data_get_errno(ld_resp
);
1387 cupsdLogMessage(CUPSD_LOG_ERROR
, "launchd_checkin: Check-in failed: %s",
1390 return; /* anti-compiler-warning */
1394 * Get the sockets dictionary...
1397 if ((ld_sockets
= launch_data_dict_lookup(ld_resp
, LAUNCH_JOBKEY_SOCKETS
))
1400 cupsdLogMessage(CUPSD_LOG_ERROR
,
1401 "launchd_checkin: No sockets found to answer requests on!");
1403 return; /* anti-compiler-warning */
1407 * Get the array of listener sockets...
1410 if ((ld_array
= launch_data_dict_lookup(ld_sockets
, "Listeners")) == NULL
)
1412 cupsdLogMessage(CUPSD_LOG_ERROR
,
1413 "launchd_checkin: No sockets found to answer requests on!");
1415 return; /* anti-compiler-warning */
1419 * Add listening fd(s) to the Listener array...
1422 if (launch_data_get_type(ld_array
) == LAUNCH_DATA_ARRAY
)
1424 count
= launch_data_array_get_count(ld_array
);
1426 for (i
= 0; i
< count
; i
++)
1429 * Get the launchd file descriptor and address...
1432 if ((tmp
= launch_data_array_get_index(ld_array
, i
)) != NULL
)
1434 fd
= launch_data_get_fd(tmp
);
1435 addrlen
= sizeof(addr
);
1437 if (getsockname(fd
, (struct sockaddr
*)&addr
, &addrlen
))
1439 cupsdLogMessage(CUPSD_LOG_ERROR
,
1440 "launchd_checkin: Unable to get local address - %s",
1446 * Try to match the launchd socket address to one of the listeners...
1449 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
1451 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
1452 if (httpAddrEqual(&lis
->address
, &addr
))
1456 * Add a new listener If there's no match...
1461 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1462 "launchd_checkin: Matched existing listener %s with fd %d...",
1463 httpAddrString(&(lis
->address
), s
, sizeof(s
)), fd
);
1467 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1468 "launchd_checkin: Adding new listener %s with fd %d...",
1469 httpAddrString(&addr
, s
, sizeof(s
)), fd
);
1471 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
1473 cupsdLogMessage(CUPSD_LOG_ERROR
,
1474 "launchd_checkin: Unable to allocate listener - "
1475 "%s.", strerror(errno
));
1479 cupsArrayAdd(Listeners
, lis
);
1481 memcpy(&lis
->address
, &addr
, sizeof(lis
->address
));
1487 if (_httpAddrPort(&(lis
->address
)) == 443)
1488 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
1489 # endif /* HAVE_SSL */
1494 launch_data_free(ld_msg
);
1495 launch_data_free(ld_resp
);
1500 * 'launchd_checkout()' - Update the launchd KeepAlive file as needed.
1504 launchd_checkout(void)
1506 int fd
; /* File descriptor */
1510 * Create or remove the launchd KeepAlive file based on whether
1511 * there are active jobs, polling, browsing for remote printers or
1512 * shared printers to advertise...
1515 if (cupsArrayCount(ActiveJobs
) || NumPolled
||
1517 (BrowseRemoteProtocols
||
1518 (BrowseLocalProtocols
&& cupsArrayCount(Printers
)))))
1520 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1521 "Creating launchd keepalive file \"" CUPS_KEEPALIVE
1524 if ((fd
= open(CUPS_KEEPALIVE
, O_RDONLY
| O_CREAT
| O_EXCL
, S_IRUSR
)) >= 0)
1529 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1530 "Removing launchd keepalive file \"" CUPS_KEEPALIVE
1533 unlink(CUPS_KEEPALIVE
);
1536 #endif /* HAVE_LAUNCHD */
1540 * 'parent_handler()' - Catch USR1/CHLD signals...
1544 parent_handler(int sig
) /* I - Signal */
1547 * Store the signal we got from the OS and return...
1550 parent_signal
= sig
;
1555 * 'process_children()' - Process all dead children...
1559 process_children(void)
1561 int status
; /* Exit status of child */
1562 int pid
, /* Process ID of child */
1563 job_id
; /* Job ID of child */
1564 cupsd_job_t
*job
; /* Current job */
1565 int i
; /* Looping var */
1566 char name
[1024]; /* Process name */
1569 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "process_children()");
1572 * Reset the dead_children flag...
1578 * Collect the exit status of some children...
1582 while ((pid
= waitpid(-1, &status
, WNOHANG
)) > 0)
1583 #elif defined(HAVE_WAIT3)
1584 while ((pid
= wait3(&status
, WNOHANG
, NULL
)) > 0)
1586 if ((pid
= wait(&status
)) > 0)
1587 #endif /* HAVE_WAITPID */
1590 * Collect the name of the process that finished...
1593 cupsdFinishProcess(pid
, name
, sizeof(name
), &job_id
);
1596 * Delete certificates for CGI processes...
1600 cupsdDeleteCert(pid
);
1603 * Handle completed job filters...
1606 if (job_id
> 0 && (job
= cupsdFindJob(job_id
)) != NULL
)
1608 for (i
= 0; job
->filters
[i
]; i
++)
1609 if (job
->filters
[i
] == pid
)
1612 if (job
->filters
[i
] || job
->backend
== pid
)
1615 * OK, this process has gone away; what's left?
1618 if (job
->filters
[i
])
1619 job
->filters
[i
] = -pid
;
1621 job
->backend
= -pid
;
1623 if (status
&& status
!= SIGTERM
&& status
!= SIGKILL
&&
1624 status
!= SIGPIPE
&& job
->status
>= 0)
1627 * An error occurred; save the exit status so we know to stop
1628 * the printer or cancel the job when all of the filters finish...
1630 * A negative status indicates that the backend failed and the
1631 * printer needs to be stopped.
1634 if (job
->filters
[i
])
1635 job
->status
= status
; /* Filter failed */
1637 job
->status
= -status
; /* Backend failed */
1639 if (job
->state_value
== IPP_JOB_PROCESSING
&&
1640 job
->status_level
> CUPSD_LOG_ERROR
)
1642 char message
[1024]; /* New printer-state-message */
1645 job
->status_level
= CUPSD_LOG_ERROR
;
1647 snprintf(message
, sizeof(message
), "%s failed", name
);
1651 strlcpy(job
->printer
->state_message
, message
,
1652 sizeof(job
->printer
->state_message
));
1658 if (!job
->printer_message
&& job
->attrs
)
1660 if ((job
->printer_message
=
1661 ippFindAttribute(job
->attrs
, "job-printer-state-message",
1662 IPP_TAG_TEXT
)) == NULL
)
1663 job
->printer_message
= ippAddString(job
->attrs
, IPP_TAG_JOB
,
1665 "job-printer-state-message",
1669 if (job
->printer_message
)
1670 cupsdSetString(&(job
->printer_message
->values
[0].string
.text
),
1676 * If this is not the last file in a job, see if all of the
1677 * filters are done, and if so move to the next file.
1680 if (job
->current_file
< job
->num_files
&& job
->printer
)
1682 for (i
= 0; job
->filters
[i
] < 0; i
++);
1684 if (!job
->filters
[i
] &&
1685 (!job
->printer
->pc
|| !job
->printer
->pc
->single_file
||
1689 * Process the next file...
1692 cupsdContinueJob(job
);
1695 else if (job
->state_value
>= IPP_JOB_CANCELED
)
1698 * Remove the job from the active list if there are no processes still
1702 for (i
= 0; job
->filters
[i
] < 0; i
++);
1704 if (!job
->filters
[i
] && job
->backend
<= 0)
1705 cupsArrayRemove(ActiveJobs
, job
);
1711 * Show the exit status as needed, ignoring SIGTERM and SIGKILL errors
1712 * since they come when we kill/end a process...
1715 if (status
== SIGTERM
|| status
== SIGKILL
)
1717 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1718 "PID %d (%s) was terminated normally with signal %d.",
1721 else if (status
== SIGPIPE
)
1723 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1724 "PID %d (%s) did not catch or ignore signal %d.",
1729 if (WIFEXITED(status
))
1731 int code
= WEXITSTATUS(status
); /* Exit code */
1734 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1735 "PID %d (%s) stopped with status %d (%s)", pid
, name
,
1736 code
, strerror(code
- 100));
1738 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1739 "PID %d (%s) stopped with status %d.", pid
, name
,
1743 cupsdLogMessage(CUPSD_LOG_ERROR
, "PID %d (%s) crashed on signal %d.",
1744 pid
, name
, WTERMSIG(status
));
1746 if (LogLevel
< CUPSD_LOG_DEBUG
)
1747 cupsdLogMessage(CUPSD_LOG_INFO
,
1748 "Hint: Try setting the LogLevel to \"debug\" to find "
1752 cupsdLogMessage(CUPSD_LOG_DEBUG
, "PID %d (%s) exited with no errors.",
1757 * If wait*() is interrupted by a signal, tell main() to call us again...
1760 if (pid
< 0 && errno
== EINTR
)
1766 * 'select_timeout()' - Calculate the select timeout value.
1770 static long /* O - Number of seconds */
1771 select_timeout(int fds
) /* I - Number of descriptors returned */
1773 long timeout
; /* Timeout for select */
1774 time_t now
; /* Current time */
1775 cupsd_client_t
*con
; /* Client information */
1776 cupsd_printer_t
*p
; /* Printer information */
1777 cupsd_job_t
*job
; /* Job information */
1778 cupsd_subscription_t
*sub
; /* Subscription information */
1779 const char *why
; /* Debugging aid */
1783 * Check to see if any of the clients have pending data to be
1784 * processed; if so, the timeout should be 0...
1787 for (con
= (cupsd_client_t
*)cupsArrayFirst(Clients
);
1789 con
= (cupsd_client_t
*)cupsArrayNext(Clients
))
1790 if (con
->http
.used
> 0)
1794 * If select has been active in the last second (fds > 0) or we have
1795 * many resources in use then don't bother trying to optimize the
1796 * timeout, just make it 1 second.
1799 if (fds
> 0 || cupsArrayCount(Clients
) > 50)
1803 * Otherwise, check all of the possible events that we need to wake for...
1807 timeout
= now
+ 86400; /* 86400 == 1 day */
1812 * When going to sleep, wake up to cancel jobs that don't complete in time.
1815 if (SleepJobs
> 0 && SleepJobs
< timeout
)
1817 timeout
= SleepJobs
;
1818 why
= "cancel jobs before sleeping";
1820 #endif /* __APPLE__ */
1823 * Check whether we are accepting new connections...
1826 if (ListeningPaused
> 0 && cupsArrayCount(Clients
) < MaxClients
&&
1827 ListeningPaused
< timeout
)
1829 if (ListeningPaused
<= now
)
1832 timeout
= ListeningPaused
;
1834 why
= "resume listening";
1838 * Check the activity and close old clients...
1841 for (con
= (cupsd_client_t
*)cupsArrayFirst(Clients
);
1843 con
= (cupsd_client_t
*)cupsArrayNext(Clients
))
1844 if ((con
->http
.activity
+ Timeout
) < timeout
)
1846 timeout
= con
->http
.activity
+ Timeout
;
1847 why
= "timeout a client connection";
1851 * Update the browse list as needed...
1854 if (Browsing
&& BrowseLocalProtocols
)
1857 if ((BrowseLocalProtocols
& BROWSE_SLP
) && (BrowseSLPRefresh
< timeout
))
1859 timeout
= BrowseSLPRefresh
;
1860 why
= "update SLP browsing";
1862 #endif /* HAVE_LIBSLP */
1865 if ((BrowseLocalProtocols
& BROWSE_LDAP
) && (BrowseLDAPRefresh
< timeout
))
1867 timeout
= BrowseLDAPRefresh
;
1868 why
= "update LDAP browsing";
1870 #endif /* HAVE_LDAP */
1872 if ((BrowseLocalProtocols
& BROWSE_CUPS
) && NumBrowsers
)
1874 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
1876 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
1878 if (p
->type
& CUPS_PRINTER_REMOTE
)
1880 if ((p
->browse_time
+ BrowseTimeout
) < timeout
)
1882 timeout
= p
->browse_time
+ BrowseTimeout
;
1883 why
= "browse timeout a printer";
1886 else if (p
->shared
&& !(p
->type
& CUPS_PRINTER_IMPLICIT
))
1888 if (BrowseInterval
&& (p
->browse_time
+ BrowseInterval
) < timeout
)
1890 timeout
= p
->browse_time
+ BrowseInterval
;
1891 why
= "send browse update";
1899 * Write out changes to configuration and state files...
1902 if (DirtyCleanTime
&& timeout
> DirtyCleanTime
)
1904 timeout
= DirtyCleanTime
;
1905 why
= "write dirty config/state files";
1909 * Check for any active jobs...
1912 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
1914 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
1916 if (job
->kill_time
&& job
->kill_time
< timeout
)
1918 timeout
= job
->kill_time
;
1919 why
= "kill unresponsive jobs";
1922 if (job
->state_value
== IPP_JOB_HELD
&& job
->hold_until
< timeout
)
1924 timeout
= job
->hold_until
;
1925 why
= "release held jobs";
1927 else if (job
->state_value
== IPP_JOB_PENDING
&& timeout
> (now
+ 10))
1930 why
= "start pending jobs";
1935 #ifdef HAVE_MALLINFO
1937 * Log memory usage every minute...
1940 if (LogLevel
>= CUPSD_LOG_DEBUG
&& (mallinfo_time
+ 60) < timeout
)
1942 timeout
= mallinfo_time
+ 60;
1943 why
= "display memory usage";
1945 #endif /* HAVE_MALLINFO */
1948 * Expire subscriptions as needed...
1951 for (sub
= (cupsd_subscription_t
*)cupsArrayFirst(Subscriptions
);
1953 sub
= (cupsd_subscription_t
*)cupsArrayNext(Subscriptions
))
1954 if (!sub
->job
&& sub
->expire
&& sub
->expire
< timeout
)
1956 timeout
= sub
->expire
;
1957 why
= "expire subscription";
1961 * Adjust from absolute to relative time. If p->browse_time above
1962 * was 0 then we can end up with a negative value here, so check.
1963 * We add 1 second to the timeout since events occur after the
1964 * timeout expires, and limit the timeout to 86400 seconds (1 day)
1965 * to avoid select() timeout limits present on some operating
1969 timeout
= timeout
- now
+ 1;
1973 else if (timeout
> 86400)
1977 * Log and return the timeout value...
1980 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "select_timeout(%d): %ld seconds to %s",
1988 * 'sigchld_handler()' - Handle 'child' signals from old processes.
1992 sigchld_handler(int sig
) /* I - Signal number */
1997 * Flag that we have dead children...
2003 * Reset the signal handler as needed...
2006 #if !defined(HAVE_SIGSET) && !defined(HAVE_SIGACTION)
2007 signal(SIGCLD
, sigchld_handler
);
2008 #endif /* !HAVE_SIGSET && !HAVE_SIGACTION */
2013 * 'sighup_handler()' - Handle 'hangup' signals to reconfigure the scheduler.
2017 sighup_handler(int sig
) /* I - Signal number */
2021 NeedReload
= RELOAD_ALL
;
2022 ReloadTime
= time(NULL
);
2024 #if !defined(HAVE_SIGSET) && !defined(HAVE_SIGACTION)
2025 signal(SIGHUP
, sighup_handler
);
2026 #endif /* !HAVE_SIGSET && !HAVE_SIGACTION */
2031 * 'sigterm_handler()' - Handle 'terminate' signals that stop the scheduler.
2035 sigterm_handler(int sig
) /* I - Signal number */
2037 (void)sig
; /* remove compiler warnings... */
2040 * Flag that we should stop and return...
2048 * 'usage()' - Show scheduler usage.
2052 usage(int status
) /* O - Exit status */
2054 FILE *fp
= status
? stderr
: stdout
; /* Output file */
2057 _cupsLangPuts(fp
, _("Usage: cupsd [options]"));
2058 _cupsLangPuts(fp
, _("Options:"));
2059 _cupsLangPuts(fp
, _(" -c config-file Load alternate configuration "
2061 _cupsLangPuts(fp
, _(" -f Run in the foreground."));
2062 _cupsLangPuts(fp
, _(" -F Run in the foreground but "
2063 "detach from console."));
2064 _cupsLangPuts(fp
, _(" -h Show this usage message."));
2065 _cupsLangPuts(fp
, _(" -l Run cupsd from launchd(8)."));
2066 _cupsLangPuts(fp
, _(" -t Test the configuration "
2074 * End of "$Id: main.c 7925 2008-09-10 17:47:26Z mike $".