2 * Main loop for the CUPS scheduler.
4 * Copyright 2007-2016 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * "LICENSE" which should have been included with this file. If this
11 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * Include necessary headers...
20 #include <sys/resource.h>
23 #elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
24 # define SD_JOURNAL_SUPPRESS_LOCATION
25 # include <systemd/sd-journal.h>
26 #endif /* HAVE_ASL_H */
32 #endif /* HAVE_LAUNCH_H */
35 # include <systemd/sd-daemon.h>
36 #endif /* HAVE_SYSTEMD */
39 # define CUPS_KEEPALIVE CUPS_CACHEDIR "/org.cups.cupsd"
40 /* Name of the KeepAlive file */
43 #if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
45 #endif /* HAVE_MALLOC_H && HAVE_MALLINFO */
49 #endif /* HAVE_NOTIFY_H */
52 # include <dbus/dbus.h>
53 #endif /* HAVE_DBUS */
55 #ifdef HAVE_SYS_PARAM_H
56 # include <sys/param.h>
57 #endif /* HAVE_SYS_PARAM_H */
64 static void parent_handler(int sig
);
65 static void process_children(void);
66 static void sigchld_handler(int sig
);
67 static void sighup_handler(int sig
);
68 static void sigterm_handler(int sig
);
69 static long select_timeout(int fds
);
71 static void service_checkin(void);
72 static void service_checkout(void);
73 #endif /* HAVE_ONDEMAND */
74 static void usage(int status
) __attribute__((noreturn
));
81 static int parent_signal
= 0;
82 /* Set to signal number from child */
83 static int holdcount
= 0; /* Number of times "hold" was called */
84 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
85 static sigset_t holdmask
; /* Old POSIX signal mask */
86 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
87 static int dead_children
= 0;
89 static int stop_scheduler
= 0;
90 /* Should the scheduler stop? */
94 * 'main()' - Main entry for the CUPS scheduler.
97 int /* O - Exit status */
98 main(int argc
, /* I - Number of command-line args */
99 char *argv
[]) /* I - Command-line arguments */
101 int i
; /* Looping var */
102 char *opt
; /* Option character */
103 int close_all
= 1, /* Close all file descriptors? */
104 disconnect
= 1, /* Disconnect from controlling terminal? */
105 fg
= 0, /* Run in foreground? */
107 /* Running as child process? */
109 /* Print the sandbox profile to stdout? */
110 int fds
; /* Number of ready descriptors */
111 cupsd_client_t
*con
; /* Current client */
112 cupsd_job_t
*job
; /* Current job */
113 cupsd_listener_t
*lis
; /* Current listener */
114 time_t current_time
, /* Current time */
115 activity
, /* Client activity timer */
116 senddoc_time
, /* Send-Document time */
117 expire_time
, /* Subscription expire time */
118 report_time
, /* Malloc/client/job report time */
119 event_time
; /* Last event notification time */
120 long timeout
; /* Timeout for cupsdDoSelect() */
121 struct rlimit limit
; /* Runtime limit */
122 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
123 struct sigaction action
; /* Actions for POSIX signals */
124 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
126 int use_sysman
= 1; /* Use system management functions? */
128 time_t netif_time
= 0; /* Time since last network update */
129 #endif /* __APPLE__ */
130 #if defined(HAVE_ONDEMAND)
131 int service_idle_exit
;
132 /* Idle exit on select timeout? */
133 #endif /* HAVE_ONDEMAND */
138 * Check for setuid invocation, which we do not support!
141 if (getuid() != geteuid())
143 fputs("cupsd: Cannot run as a setuid program.\n", stderr
);
146 #endif /* HAVE_GETEUID */
149 * Check for command-line arguments...
155 if (getenv("CUPSD_LAUNCHD"))
162 #endif /* HAVE_LAUNCHD */
164 for (i
= 1; i
< argc
; i
++)
165 if (argv
[i
][0] == '-')
166 for (opt
= argv
[i
] + 1; *opt
!= '\0'; opt
++)
169 case 'C' : /* Run as child with config file */
174 case 'c' : /* Configuration file */
178 _cupsLangPuts(stderr
, _("cupsd: Expected config filename "
179 "after \"-c\" option."));
183 if (argv
[i
][0] == '/')
186 * Absolute directory...
189 cupsdSetString(&ConfigurationFile
, argv
[i
]);
194 * Relative directory...
197 char *current
; /* Current directory */
200 * Allocate a buffer for the current working directory to
201 * reduce run-time stack usage; this approximates the
202 * behavior of some implementations of getcwd() when they
203 * are passed a NULL pointer.
206 if ((current
= malloc(1024)) == NULL
)
208 _cupsLangPuts(stderr
,
209 _("cupsd: Unable to get current directory."));
213 if (!getcwd(current
, 1024))
215 _cupsLangPuts(stderr
,
216 _("cupsd: Unable to get current directory."));
221 cupsdSetStringf(&ConfigurationFile
, "%s/%s", current
, argv
[i
]);
226 case 'f' : /* Run in foreground... */
232 case 'F' : /* Run in foreground, but disconnect from terminal... */
237 case 'h' : /* Show usage/help */
241 case 'l' : /* Started by launchd/systemd/upstart... */
242 #if defined(HAVE_ONDEMAND)
248 _cupsLangPuts(stderr
, _("cupsd: On-demand support not compiled "
249 "in, running in normal mode."));
253 #endif /* HAVE_ONDEMAND */
256 case 'p' : /* Stop immediately for profiling */
257 fputs("cupsd: -p (startup profiling) is for internal testing "
258 "use only!\n", stderr
);
265 case 'P' : /* Disable security profiles */
266 fputs("cupsd: -P (disable sandboxing) is for internal testing use only.\n", stderr
);
270 case 's' : /* Set cups-files.conf location */
274 _cupsLangPuts(stderr
, _("cupsd: Expected cups-files.conf "
275 "filename after \"-s\" option."));
279 if (argv
[i
][0] != '/')
282 * Relative filename not allowed...
285 _cupsLangPuts(stderr
, _("cupsd: Relative cups-files.conf "
286 "filename not allowed."));
290 cupsdSetString(&CupsFilesFile
, argv
[i
]);
294 case 'S' : /* Disable system management functions */
295 fputs("cupsd: -S (disable system management) for internal "
296 "testing use only!\n", stderr
);
299 #endif /* __APPLE__ */
301 case 't' : /* Test the cupsd.conf file... */
308 case 'T' : /* Print security profile */
315 default : /* Unknown option */
316 _cupsLangPrintf(stderr
, _("cupsd: Unknown option \"%c\" - "
323 _cupsLangPrintf(stderr
, _("cupsd: Unknown argument \"%s\" - aborting."),
328 if (!ConfigurationFile
)
329 cupsdSetString(&ConfigurationFile
, CUPS_SERVERROOT
"/cupsd.conf");
333 char *filename
, /* Copy of cupsd.conf filename */
334 *slash
; /* Final slash in cupsd.conf filename */
335 size_t len
; /* Size of buffer */
337 len
= strlen(ConfigurationFile
) + 15;
338 if ((filename
= malloc(len
)) == NULL
)
340 _cupsLangPrintf(stderr
,
341 _("cupsd: Unable to get path to "
342 "cups-files.conf file."));
346 strlcpy(filename
, ConfigurationFile
, len
);
347 if ((slash
= strrchr(filename
, '/')) == NULL
)
349 _cupsLangPrintf(stderr
,
350 _("cupsd: Unable to get path to "
351 "cups-files.conf file."));
355 strlcpy(slash
, "/cups-files.conf", len
- (size_t)(slash
- filename
));
356 cupsdSetString(&CupsFilesFile
, filename
);
363 * Make sure we aren't tying up any filesystems...
369 * Disconnect from the controlling terminal...
378 * Close all open files...
381 getrlimit(RLIMIT_NOFILE
, &limit
);
383 for (i
= 0; i
< (int)limit
.rlim_cur
&& i
< 1024; i
++)
387 * Redirect stdin/out/err to /dev/null...
390 if ((i
= open("/dev/null", O_RDONLY
)) != 0)
396 if ((i
= open("/dev/null", O_WRONLY
)) != 1)
402 if ((i
= open("/dev/null", O_WRONLY
)) != 2)
409 LogStderr
= cupsFileStderr();
412 * Run in the background as needed...
418 * Setup signal handlers for the parent...
421 #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
422 sigset(SIGUSR1
, parent_handler
);
423 sigset(SIGCHLD
, parent_handler
);
425 sigset(SIGHUP
, SIG_IGN
);
426 #elif defined(HAVE_SIGACTION)
427 memset(&action
, 0, sizeof(action
));
428 sigemptyset(&action
.sa_mask
);
429 sigaddset(&action
.sa_mask
, SIGUSR1
);
430 action
.sa_handler
= parent_handler
;
431 sigaction(SIGUSR1
, &action
, NULL
);
432 sigaction(SIGCHLD
, &action
, NULL
);
434 sigemptyset(&action
.sa_mask
);
435 action
.sa_handler
= SIG_IGN
;
436 sigaction(SIGHUP
, &action
, NULL
);
438 signal(SIGUSR1
, parent_handler
);
439 signal(SIGCLD
, parent_handler
);
441 signal(SIGHUP
, SIG_IGN
);
442 #endif /* HAVE_SIGSET */
447 * OK, wait for the child to startup and send us SIGUSR1 or to crash
448 * and the OS send us SIGCHLD... We also need to ignore SIGHUP which
449 * might be sent by the init script to restart the scheduler...
452 for (; parent_signal
== 0;)
455 if (parent_signal
== SIGUSR1
)
463 else if (WIFEXITED(i
))
465 fprintf(stderr
, "cupsd: Child exited with status %d\n",
471 fprintf(stderr
, "cupsd: Child exited on signal %d\n", WTERMSIG(i
));
476 #if defined(__OpenBSD__) && OpenBSD < 201211
478 * Call _thread_sys_closefrom() so the child process doesn't reset the
479 * parent's file descriptors to be blocking. This is a workaround for a
480 * limitation of userland libpthread on older versions of OpenBSD.
483 _thread_sys_closefrom(0);
484 #endif /* __OpenBSD__ && OpenBSD < 201211 */
487 * Since many system libraries create fork-unsafe data on execution of a
488 * program, we need to re-execute the background cupsd with the "-C" and "-s"
489 * options to avoid problems. Unfortunately, we also have to assume that
490 * argv[0] contains the name of the cupsd executable - there is no portable
491 * way to get the real pathname...
494 execlp(argv
[0], argv
[0], "-C", ConfigurationFile
, "-s", CupsFilesFile
, (char *)0);
499 * Set the timezone info...
505 setlocale(LC_TIME
, "");
508 #ifdef HAVE_DBUS_THREADS_INIT
510 * Enable threading support for D-BUS...
513 dbus_threads_init_default();
514 #endif /* HAVE_DBUS_THREADS_INIT */
517 * Set the maximum number of files...
520 getrlimit(RLIMIT_NOFILE
, &limit
);
522 #if !defined(HAVE_POLL) && !defined(HAVE_EPOLL) && !defined(HAVE_KQUEUE)
523 if (limit
.rlim_max
> FD_SETSIZE
)
526 #endif /* !HAVE_POLL && !HAVE_EPOLL && !HAVE_KQUEUE */
528 if (limit
.rlim_max
== RLIM_INFINITY
)
531 #endif /* RLIM_INFINITY */
532 MaxFDs
= limit
.rlim_max
;
534 limit
.rlim_cur
= (rlim_t
)MaxFDs
;
536 setrlimit(RLIMIT_NOFILE
, &limit
);
541 * Read configuration...
544 if (!cupsdReadConfiguration())
546 else if (TestConfigFile
)
548 printf("\"%s\" is OK.\n", CupsFilesFile
);
549 printf("\"%s\" is OK.\n", ConfigurationFile
);
552 else if (print_profile
)
554 cups_file_t
*fp
; /* File pointer */
555 const char *profile
= cupsdCreateProfile(42, 0);
557 char line
[1024]; /* Line from file */
560 if ((fp
= cupsFileOpen(profile
, "r")) == NULL
)
562 printf("Unable to open profile file \"%s\": %s\n", profile
? profile
: "(null)", strerror(errno
));
566 while (cupsFileGets(fp
, line
, sizeof(line
)))
575 * Clean out old temp files and printer cache data.
578 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
579 cupsdCleanFiles(TempDir
, NULL
);
581 cupsdCleanFiles(CacheDir
, "*.ipp");
583 #if defined(HAVE_ONDEMAND)
587 * If we were started on demand by launchd or systemd get the listen sockets
588 * file descriptors...
594 #endif /* HAVE_ONDEMAND */
597 * Startup the server...
605 * Catch hangup and child signals and ignore broken pipes...
608 #ifdef HAVE_SIGSET /* Use System V signals over POSIX to avoid bugs */
609 sigset(SIGCHLD
, sigchld_handler
);
610 sigset(SIGHUP
, sighup_handler
);
611 sigset(SIGPIPE
, SIG_IGN
);
612 sigset(SIGTERM
, sigterm_handler
);
613 #elif defined(HAVE_SIGACTION)
614 memset(&action
, 0, sizeof(action
));
616 sigemptyset(&action
.sa_mask
);
617 sigaddset(&action
.sa_mask
, SIGTERM
);
618 sigaddset(&action
.sa_mask
, SIGCHLD
);
619 action
.sa_handler
= sigchld_handler
;
620 sigaction(SIGCHLD
, &action
, NULL
);
622 sigemptyset(&action
.sa_mask
);
623 sigaddset(&action
.sa_mask
, SIGHUP
);
624 action
.sa_handler
= sighup_handler
;
625 sigaction(SIGHUP
, &action
, NULL
);
627 sigemptyset(&action
.sa_mask
);
628 action
.sa_handler
= SIG_IGN
;
629 sigaction(SIGPIPE
, &action
, NULL
);
631 sigemptyset(&action
.sa_mask
);
632 sigaddset(&action
.sa_mask
, SIGTERM
);
633 sigaddset(&action
.sa_mask
, SIGCHLD
);
634 action
.sa_handler
= sigterm_handler
;
635 sigaction(SIGTERM
, &action
, NULL
);
637 signal(SIGCLD
, sigchld_handler
); /* No, SIGCLD isn't a typo... */
638 signal(SIGHUP
, sighup_handler
);
639 signal(SIGPIPE
, SIG_IGN
);
640 signal(SIGTERM
, sigterm_handler
);
641 #endif /* HAVE_SIGSET */
644 * Initialize authentication certificates...
650 * If we are running in the background, signal the parent process that
651 * we are up and running...
654 if (!fg
|| run_as_child
)
657 * Send a signal to the parent process, but only if the parent is
658 * not PID 1 (init). This avoids accidentally shutting down the
659 * system on OpenBSD if you CTRL-C the server before it is up...
662 i
= getppid(); /* Save parent PID to avoid race condition */
670 * Start power management framework...
674 cupsdStartSystemMonitor();
675 #endif /* __APPLE__ */
678 * Send server-started event...
681 #if defined(HAVE_ONDEMAND)
683 cupsdAddEvent(CUPSD_EVENT_SERVER_STARTED
, NULL
, NULL
, "Scheduler started on demand.");
685 #endif /* HAVE_ONDEMAND */
687 cupsdAddEvent(CUPSD_EVENT_SERVER_STARTED
, NULL
, NULL
, "Scheduler started in foreground.");
689 cupsdAddEvent(CUPSD_EVENT_SERVER_STARTED
, NULL
, NULL
, "Scheduler started in background.");
692 * Start any pending print jobs...
701 current_time
= time(NULL
);
702 event_time
= current_time
;
703 expire_time
= current_time
;
706 senddoc_time
= current_time
;
708 while (!stop_scheduler
)
711 * Check if there are dead children to handle...
718 * Check if we need to load the server configuration file...
724 * Close any idle clients...
727 if (cupsArrayCount(Clients
) > 0)
729 for (con
= (cupsd_client_t
*)cupsArrayFirst(Clients
);
731 con
= (cupsd_client_t
*)cupsArrayNext(Clients
))
732 if (httpGetState(con
->http
) == HTTP_WAITING
)
733 cupsdCloseClient(con
);
735 con
->http
->keep_alive
= HTTP_KEEPALIVE_OFF
;
737 cupsdPauseListening();
741 * Restart if all clients are closed and all jobs finished, or
742 * if the reload timeout has elapsed...
745 if ((cupsArrayCount(Clients
) == 0 &&
746 (cupsArrayCount(PrintingJobs
) == 0 || NeedReload
!= RELOAD_ALL
)) ||
747 (time(NULL
) - ReloadTime
) >= ReloadTimeout
)
750 * Shutdown the server...
756 #endif /* HAVE_ONDEMAND */
763 * Read configuration...
766 if (!cupsdReadConfiguration())
768 #ifdef HAVE_SYSTEMD_SD_JOURNAL_H
769 sd_journal_print(LOG_ERR
, "Unable to read configuration file \"%s\" - exiting.", ConfigurationFile
);
771 syslog(LOG_LPR
, "Unable to read configuration file \'%s\' - exiting.", ConfigurationFile
);
772 #endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
778 * Startup the server...
786 * Send a server-restarted event...
789 cupsdAddEvent(CUPSD_EVENT_SERVER_RESTARTED
, NULL
, NULL
,
790 "Scheduler restarted.");
795 * Check for available input or ready output. If cupsdDoSelect()
796 * returns 0 or -1, something bad happened and we should exit
799 * Note that we at least have one listening socket open at all
803 if ((timeout
= select_timeout(fds
)) > 1 && LastEvent
)
808 * If no other work is scheduled and we're being controlled by
809 * launchd then timeout after 'LaunchdTimeout' seconds of
813 if (timeout
== 86400 && OnDemand
&& IdleExitTimeout
&&
814 !cupsArrayCount(ActiveJobs
) &&
817 # endif /* HAVE_SYSTEMD */
818 (!Browsing
|| !BrowseLocalProtocols
|| !cupsArrayCount(Printers
)))
820 timeout
= IdleExitTimeout
;
821 service_idle_exit
= 1;
824 service_idle_exit
= 0;
825 #endif /* HAVE_ONDEMAND */
827 if ((fds
= cupsdDoSelect(timeout
)) < 0)
830 * Got an error from select!
833 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
834 cupsd_printer_t
*p
; /* Current printer */
835 #endif /* HAVE_DNSSD || HAVE_AVAHI */
837 if (errno
== EINTR
) /* Just interrupted by a signal */
841 * Log all sorts of debug info to help track down the problem.
844 cupsdLogMessage(CUPSD_LOG_EMERG
, "cupsdDoSelect() failed - %s!",
847 for (i
= 0, con
= (cupsd_client_t
*)cupsArrayFirst(Clients
);
849 i
++, con
= (cupsd_client_t
*)cupsArrayNext(Clients
))
850 cupsdLogMessage(CUPSD_LOG_EMERG
,
851 "Clients[%d] = %d, file = %d, state = %d",
852 i
, con
->number
, con
->file
, httpGetState(con
->http
));
854 for (i
= 0, lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
856 i
++, lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
857 cupsdLogMessage(CUPSD_LOG_EMERG
, "Listeners[%d] = %d", i
, lis
->fd
);
859 cupsdLogMessage(CUPSD_LOG_EMERG
, "CGIPipes[0] = %d", CGIPipes
[0]);
862 cupsdLogMessage(CUPSD_LOG_EMERG
, "SysEventPipes[0] = %d",
864 #endif /* __APPLE__ */
866 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
868 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
869 cupsdLogMessage(CUPSD_LOG_EMERG
, "Jobs[%d] = %d < [%d %d] > [%d %d]",
871 job
->status_buffer
? job
->status_buffer
->fd
: -1,
872 job
->print_pipes
[0], job
->print_pipes
[1],
873 job
->back_pipes
[0], job
->back_pipes
[1]);
875 #if defined(HAVE_DNSSD) || defined(HAVE_AVAHI)
876 for (p
= (cupsd_printer_t
*)cupsArrayFirst(Printers
);
878 p
= (cupsd_printer_t
*)cupsArrayNext(Printers
))
879 cupsdLogMessage(CUPSD_LOG_EMERG
, "printer[%s] reg_name=\"%s\"", p
->name
,
880 p
->reg_name
? p
->reg_name
: "(null)");
881 #endif /* HAVE_DNSSD || HAVE_AVAHI */
886 current_time
= time(NULL
);
889 * Write dirty config/state files...
892 if (DirtyCleanTime
&& current_time
>= DirtyCleanTime
)
897 * If we are going to sleep and still have pending jobs, stop them after
898 * a period of time...
901 if (SleepJobs
> 0 && current_time
>= SleepJobs
&&
902 cupsArrayCount(PrintingJobs
) > 0)
905 cupsdStopAllJobs(CUPSD_JOB_DEFAULT
, 5);
907 #endif /* __APPLE__ */
911 * Update the network interfaces once a minute...
914 if ((current_time
- netif_time
) >= 60)
916 netif_time
= current_time
;
919 #endif /* !__APPLE__ */
923 * If no other work was scheduled and we're being controlled by launchd,
924 * systemd, or upstart then timeout after 'LaunchdTimeout' seconds of
928 if (!fds
&& service_idle_exit
)
930 cupsdLogMessage(CUPSD_LOG_INFO
,
931 "Printer sharing is off and there are no jobs pending, "
932 "will restart on demand.");
936 #endif /* HAVE_ONDEMAND */
939 * Resume listening for new connections as needed...
942 if (ListeningPaused
&& ListeningPaused
<= current_time
&&
943 cupsArrayCount(Clients
) < MaxClients
)
944 cupsdResumeListening();
947 * Expire subscriptions and unload completed jobs as needed...
950 if (current_time
> expire_time
)
952 if (cupsArrayCount(Subscriptions
) > 0)
953 cupsdExpireSubscriptions(NULL
, NULL
);
955 cupsdUnloadCompletedJobs();
957 expire_time
= current_time
;
960 #ifndef HAVE_AUTHORIZATION_H
962 * Update the root certificate once every 5 minutes if we have client
966 if ((current_time
- RootCertTime
) >= RootCertDuration
&& RootCertDuration
&&
967 !RunUser
&& cupsArrayCount(Clients
))
970 * Update the root certificate...
974 cupsdAddCert(0, "root", cupsdDefaultAuthType());
976 #endif /* !HAVE_AUTHORIZATION_H */
979 * Check for new data on the client sockets...
982 for (con
= (cupsd_client_t
*)cupsArrayFirst(Clients
);
984 con
= (cupsd_client_t
*)cupsArrayNext(Clients
))
987 * Process pending data in the input buffer...
990 if (httpGetReady(con
->http
))
992 cupsdReadClient(con
);
997 * Check the activity and close old clients...
1000 activity
= current_time
- Timeout
;
1001 if (httpGetActivity(con
->http
) < activity
&& !con
->pipe_pid
)
1003 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Closing client %d after %d seconds of inactivity.", con
->number
, Timeout
);
1005 cupsdCloseClient(con
);
1011 * Update any pending multi-file documents...
1014 if ((current_time
- senddoc_time
) >= 10)
1017 senddoc_time
= current_time
;
1021 * Clean job history...
1024 if (JobHistoryUpdate
&& current_time
>= JobHistoryUpdate
)
1028 * Log statistics at most once a minute when in debug mode...
1031 if ((current_time
- report_time
) >= 60 && LogLevel
>= CUPSD_LOG_DEBUG
)
1033 size_t string_count
, /* String count */
1034 alloc_bytes
, /* Allocated string bytes */
1035 total_bytes
; /* Total string bytes */
1036 #ifdef HAVE_MALLINFO
1037 struct mallinfo mem
; /* Malloc information */
1041 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Report: malloc-arena=%lu", mem
.arena
);
1042 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Report: malloc-used=%lu",
1043 mem
.usmblks
+ mem
.uordblks
);
1044 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Report: malloc-free=%lu",
1045 mem
.fsmblks
+ mem
.fordblks
);
1046 #endif /* HAVE_MALLINFO */
1048 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Report: clients=%d",
1049 cupsArrayCount(Clients
));
1050 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Report: jobs=%d",
1051 cupsArrayCount(Jobs
));
1052 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Report: jobs-active=%d",
1053 cupsArrayCount(ActiveJobs
));
1054 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Report: printers=%d",
1055 cupsArrayCount(Printers
));
1057 string_count
= _cupsStrStatistics(&alloc_bytes
, &total_bytes
);
1058 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1059 "Report: stringpool-string-count=" CUPS_LLFMT
,
1060 CUPS_LLCAST string_count
);
1061 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1062 "Report: stringpool-alloc-bytes=" CUPS_LLFMT
,
1063 CUPS_LLCAST alloc_bytes
);
1064 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1065 "Report: stringpool-total-bytes=" CUPS_LLFMT
,
1066 CUPS_LLCAST total_bytes
);
1068 report_time
= current_time
;
1072 * Handle OS-specific event notification for any events that have
1073 * accumulated. Don't send these more than once a second...
1076 if (LastEvent
&& (current_time
- event_time
) >= 1)
1078 #ifdef HAVE_NOTIFY_POST
1079 if (LastEvent
& (CUPSD_EVENT_PRINTER_ADDED
|
1080 CUPSD_EVENT_PRINTER_DELETED
|
1081 CUPSD_EVENT_PRINTER_MODIFIED
))
1083 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1084 "notify_post(\"com.apple.printerListChange\")");
1085 notify_post("com.apple.printerListChange");
1088 if (LastEvent
& CUPSD_EVENT_PRINTER_STATE_CHANGED
)
1090 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1091 "notify_post(\"com.apple.printerHistoryChange\")");
1092 notify_post("com.apple.printerHistoryChange");
1095 if (LastEvent
& (CUPSD_EVENT_JOB_STATE_CHANGED
|
1096 CUPSD_EVENT_JOB_CONFIG_CHANGED
|
1097 CUPSD_EVENT_JOB_PROGRESS
))
1099 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1100 "notify_post(\"com.apple.jobChange\")");
1101 notify_post("com.apple.jobChange");
1103 #endif /* HAVE_NOTIFY_POST */
1106 * Reset the accumulated events...
1109 LastEvent
= CUPSD_EVENT_NONE
;
1110 event_time
= current_time
;
1115 * Log a message based on what happened...
1120 cupsdLogMessage(CUPSD_LOG_INFO
, "Scheduler shutting down normally.");
1121 cupsdAddEvent(CUPSD_EVENT_SERVER_STOPPED
, NULL
, NULL
,
1122 "Scheduler shutting down normally.");
1126 cupsdLogMessage(CUPSD_LOG_ERROR
,
1127 "Scheduler shutting down due to program error.");
1128 cupsdAddEvent(CUPSD_EVENT_SERVER_STOPPED
, NULL
, NULL
,
1129 "Scheduler shutting down due to program error.");
1133 * Close all network clients...
1140 #ifdef HAVE_ONDEMAND
1142 * Update the keep-alive file as needed...
1147 #endif /* HAVE_ONDEMAND */
1157 * Stop monitoring system event monitoring...
1161 cupsdStopSystemMonitor();
1162 #endif /* __APPLE__ */
1166 return (!stop_scheduler
);
1171 * 'cupsdAddString()' - Copy and add a string to an array.
1174 int /* O - 1 on success, 0 on failure */
1175 cupsdAddString(cups_array_t
**a
, /* IO - String array */
1176 const char *s
) /* I - String to copy and add */
1179 *a
= cupsArrayNew3((cups_array_func_t
)strcmp
, NULL
,
1180 (cups_ahash_func_t
)NULL
, 0,
1181 (cups_acopy_func_t
)strdup
,
1182 (cups_afree_func_t
)free
);
1184 return (cupsArrayAdd(*a
, (char *)s
));
1189 * 'cupsdCheckProcess()' - Tell the main loop to check for dead children.
1193 cupsdCheckProcess(void)
1196 * Flag that we have dead children...
1204 * 'cupsdClearString()' - Clear a string.
1208 cupsdClearString(char **s
) /* O - String value */
1219 * 'cupsdFreeStrings()' - Free an array of strings.
1223 cupsdFreeStrings(cups_array_t
**a
) /* IO - String array */
1227 cupsArrayDelete(*a
);
1234 * 'cupsdHoldSignals()' - Hold child and termination signals.
1238 cupsdHoldSignals(void)
1240 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
1241 sigset_t newmask
; /* New POSIX signal mask */
1242 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
1252 #elif defined(HAVE_SIGACTION)
1253 sigemptyset(&newmask
);
1254 sigaddset(&newmask
, SIGTERM
);
1255 sigaddset(&newmask
, SIGCHLD
);
1256 sigprocmask(SIG_BLOCK
, &newmask
, &holdmask
);
1257 #endif /* HAVE_SIGSET */
1262 * 'cupsdReleaseSignals()' - Release signals for delivery.
1266 cupsdReleaseSignals(void)
1275 #elif defined(HAVE_SIGACTION)
1276 sigprocmask(SIG_SETMASK
, &holdmask
, NULL
);
1277 #endif /* HAVE_SIGSET */
1282 * 'cupsdSetString()' - Set a string value.
1286 cupsdSetString(char **s
, /* O - New string */
1287 const char *v
) /* I - String value */
1303 * 'cupsdSetStringf()' - Set a formatted string value.
1307 cupsdSetStringf(char **s
, /* O - New string */
1308 const char *f
, /* I - Printf-style format string */
1309 ...) /* I - Additional args as needed */
1311 char v
[65536 + 64]; /* Formatting string value */
1312 va_list ap
; /* Argument pointer */
1313 char *olds
; /* Old string */
1324 vsnprintf(v
, sizeof(v
), f
, ap
);
1338 * 'parent_handler()' - Catch USR1/CHLD signals...
1342 parent_handler(int sig
) /* I - Signal */
1345 * Store the signal we got from the OS and return...
1348 parent_signal
= sig
;
1353 * 'process_children()' - Process all dead children...
1357 process_children(void)
1359 int status
; /* Exit status of child */
1360 int pid
, /* Process ID of child */
1361 job_id
; /* Job ID of child */
1362 cupsd_job_t
*job
; /* Current job */
1363 int i
; /* Looping var */
1364 char name
[1024]; /* Process name */
1365 const char *type
; /* Type of program */
1368 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "process_children()");
1371 * Reset the dead_children flag...
1377 * Collect the exit status of some children...
1381 while ((pid
= waitpid(-1, &status
, WNOHANG
)) > 0)
1382 #elif defined(HAVE_WAIT3)
1383 while ((pid
= wait3(&status
, WNOHANG
, NULL
)) > 0)
1385 if ((pid
= wait(&status
)) > 0)
1386 #endif /* HAVE_WAITPID */
1389 * Collect the name of the process that finished...
1392 cupsdFinishProcess(pid
, name
, sizeof(name
), &job_id
);
1395 * Delete certificates for CGI processes...
1399 cupsdDeleteCert(pid
);
1402 * Handle completed job filters...
1406 job
= cupsdFindJob(job_id
);
1412 for (i
= 0; job
->filters
[i
]; i
++)
1413 if (job
->filters
[i
] == pid
)
1416 if (job
->filters
[i
] || job
->backend
== pid
)
1419 * OK, this process has gone away; what's left?
1422 if (job
->filters
[i
])
1424 job
->filters
[i
] = -pid
;
1429 job
->backend
= -pid
;
1433 if (status
&& status
!= SIGTERM
&& status
!= SIGKILL
&&
1437 * An error occurred; save the exit status so we know to stop
1438 * the printer or cancel the job when all of the filters finish...
1440 * A negative status indicates that the backend failed and the
1441 * printer needs to be stopped.
1443 * In order to preserve the most serious status, we always log
1444 * when a process dies due to a signal (e.g. SIGABRT, SIGSEGV,
1445 * and SIGBUS) and prefer to log the backend exit status over a
1449 int old_status
= abs(job
->status
);
1451 if (WIFSIGNALED(status
) || /* This process crashed, or */
1452 !job
->status
|| /* No process had a status, or */
1453 (!job
->filters
[i
] && WIFEXITED(old_status
)))
1454 { /* Backend and filter didn't crash */
1455 if (job
->filters
[i
])
1456 job
->status
= status
; /* Filter failed */
1458 job
->status
= -status
; /* Backend failed */
1461 if (job
->state_value
== IPP_JOB_PROCESSING
&&
1462 job
->status_level
> CUPSD_LOG_ERROR
&&
1463 (job
->filters
[i
] || !WIFEXITED(status
)))
1465 char message
[1024]; /* New printer-state-message */
1468 job
->status_level
= CUPSD_LOG_ERROR
;
1470 snprintf(message
, sizeof(message
), "%s failed", type
);
1474 strlcpy(job
->printer
->state_message
, message
,
1475 sizeof(job
->printer
->state_message
));
1481 if (!job
->printer_message
&& job
->attrs
)
1483 if ((job
->printer_message
=
1484 ippFindAttribute(job
->attrs
, "job-printer-state-message",
1485 IPP_TAG_TEXT
)) == NULL
)
1486 job
->printer_message
= ippAddString(job
->attrs
, IPP_TAG_JOB
,
1488 "job-printer-state-message",
1492 if (job
->printer_message
)
1493 ippSetString(job
->attrs
, &job
->printer_message
, 0, message
);
1498 * If this is not the last file in a job, see if all of the
1499 * filters are done, and if so move to the next file.
1502 if (job
->state_value
>= IPP_JOB_CANCELED
)
1505 * Remove the job from the active list if there are no processes still
1509 for (i
= 0; job
->filters
[i
] < 0; i
++);
1511 if (!job
->filters
[i
] && job
->backend
<= 0)
1512 cupsArrayRemove(ActiveJobs
, job
);
1514 else if (job
->current_file
< job
->num_files
&& job
->printer
)
1516 for (i
= 0; job
->filters
[i
] < 0; i
++);
1518 if (!job
->filters
[i
] &&
1519 (!job
->printer
->pc
|| !job
->printer
->pc
->single_file
||
1523 * Process the next file...
1526 cupsdContinueJob(job
);
1533 * Show the exit status as needed, ignoring SIGTERM and SIGKILL errors
1534 * since they come when we kill/end a process...
1537 if (status
== SIGTERM
|| status
== SIGKILL
)
1539 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
1540 "PID %d (%s) was terminated normally with signal %d.", pid
,
1543 else if (status
== SIGPIPE
)
1545 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
1546 "PID %d (%s) did not catch or ignore signal %d.", pid
, name
,
1551 if (WIFEXITED(status
))
1553 int code
= WEXITSTATUS(status
); /* Exit code */
1556 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
1557 "PID %d (%s) stopped with status %d (%s)", pid
, name
,
1558 code
, strerror(code
- 100));
1560 cupsdLogJob(job
, CUPSD_LOG_DEBUG
,
1561 "PID %d (%s) stopped with status %d.", pid
, name
, code
);
1564 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "PID %d (%s) crashed on signal %d.",
1565 pid
, name
, WTERMSIG(status
));
1567 if (LogLevel
< CUPSD_LOG_DEBUG
)
1568 cupsdLogJob(job
, CUPSD_LOG_INFO
,
1569 "Hint: Try setting the LogLevel to \"debug\" to find out "
1573 cupsdLogJob(job
, CUPSD_LOG_DEBUG
, "PID %d (%s) exited with no errors.",
1578 * If wait*() is interrupted by a signal, tell main() to call us again...
1581 if (pid
< 0 && errno
== EINTR
)
1587 * 'select_timeout()' - Calculate the select timeout value.
1591 static long /* O - Number of seconds */
1592 select_timeout(int fds
) /* I - Number of descriptors returned */
1594 long timeout
; /* Timeout for select */
1595 time_t now
; /* Current time */
1596 cupsd_client_t
*con
; /* Client information */
1597 cupsd_job_t
*job
; /* Job information */
1598 const char *why
; /* Debugging aid */
1601 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "select_timeout: JobHistoryUpdate=%ld",
1602 (long)JobHistoryUpdate
);
1605 * Check to see if any of the clients have pending data to be
1606 * processed; if so, the timeout should be 0...
1609 for (con
= (cupsd_client_t
*)cupsArrayFirst(Clients
);
1611 con
= (cupsd_client_t
*)cupsArrayNext(Clients
))
1612 if (httpGetReady(con
->http
))
1616 * If select has been active in the last second (fds > 0) or we have
1617 * many resources in use then don't bother trying to optimize the
1618 * timeout, just make it 1 second.
1621 if (fds
> 0 || cupsArrayCount(Clients
) > 50)
1625 * Otherwise, check all of the possible events that we need to wake for...
1629 timeout
= now
+ 86400; /* 86400 == 1 day */
1634 * When going to sleep, wake up to cancel jobs that don't complete in time.
1637 if (SleepJobs
> 0 && SleepJobs
< timeout
)
1639 timeout
= SleepJobs
;
1640 why
= "cancel jobs before sleeping";
1642 #endif /* __APPLE__ */
1645 * Check whether we are accepting new connections...
1648 if (ListeningPaused
> 0 && cupsArrayCount(Clients
) < MaxClients
&&
1649 ListeningPaused
< timeout
)
1651 if (ListeningPaused
<= now
)
1654 timeout
= ListeningPaused
;
1656 why
= "resume listening";
1660 * Check the activity and close old clients...
1663 for (con
= (cupsd_client_t
*)cupsArrayFirst(Clients
);
1665 con
= (cupsd_client_t
*)cupsArrayNext(Clients
))
1666 if ((httpGetActivity(con
->http
) + Timeout
) < timeout
)
1668 timeout
= httpGetActivity(con
->http
) + Timeout
;
1669 why
= "timeout a client connection";
1673 * Write out changes to configuration and state files...
1676 if (DirtyCleanTime
&& timeout
> DirtyCleanTime
)
1678 timeout
= DirtyCleanTime
;
1679 why
= "write dirty config/state files";
1683 * Check for any job activity...
1686 if (JobHistoryUpdate
&& timeout
> JobHistoryUpdate
)
1688 timeout
= JobHistoryUpdate
;
1689 why
= "update job history";
1692 for (job
= (cupsd_job_t
*)cupsArrayFirst(ActiveJobs
);
1694 job
= (cupsd_job_t
*)cupsArrayNext(ActiveJobs
))
1696 if (job
->cancel_time
&& job
->cancel_time
< timeout
)
1698 timeout
= job
->cancel_time
;
1699 why
= "cancel stuck jobs";
1702 if (job
->kill_time
&& job
->kill_time
< timeout
)
1704 timeout
= job
->kill_time
;
1705 why
= "kill unresponsive jobs";
1708 if (job
->state_value
== IPP_JOB_HELD
&& job
->hold_until
< timeout
)
1710 timeout
= job
->hold_until
;
1711 why
= "release held jobs";
1714 if (job
->state_value
== IPP_JOB_PENDING
&& timeout
> (now
+ 10))
1717 why
= "start pending jobs";
1722 #ifdef HAVE_MALLINFO
1724 * Log memory usage every minute...
1727 if (LogLevel
>= CUPSD_LOG_DEBUG
&& (mallinfo_time
+ 60) < timeout
)
1729 timeout
= mallinfo_time
+ 60;
1730 why
= "display memory usage";
1732 #endif /* HAVE_MALLINFO */
1735 * Adjust from absolute to relative time. We add 1 second to the timeout since
1736 * events occur after the timeout expires, and limit the timeout to 86400
1737 * seconds (1 day) to avoid select() timeout limits present on some operating
1741 timeout
= timeout
- now
+ 1;
1745 else if (timeout
> 86400)
1749 * Log and return the timeout value...
1752 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "select_timeout(%d): %ld seconds to %s",
1760 * 'sigchld_handler()' - Handle 'child' signals from old processes.
1764 sigchld_handler(int sig
) /* I - Signal number */
1769 * Flag that we have dead children...
1775 * Reset the signal handler as needed...
1778 #if !defined(HAVE_SIGSET) && !defined(HAVE_SIGACTION)
1779 signal(SIGCLD
, sigchld_handler
);
1780 #endif /* !HAVE_SIGSET && !HAVE_SIGACTION */
1785 * 'sighup_handler()' - Handle 'hangup' signals to reconfigure the scheduler.
1789 sighup_handler(int sig
) /* I - Signal number */
1793 NeedReload
= RELOAD_ALL
;
1794 ReloadTime
= time(NULL
);
1796 #if !defined(HAVE_SIGSET) && !defined(HAVE_SIGACTION)
1797 signal(SIGHUP
, sighup_handler
);
1798 #endif /* !HAVE_SIGSET && !HAVE_SIGACTION */
1803 * 'sigterm_handler()' - Handle 'terminate' signals that stop the scheduler.
1807 sigterm_handler(int sig
) /* I - Signal number */
1809 (void)sig
; /* remove compiler warnings... */
1812 * Flag that we should stop and return...
1819 #ifdef HAVE_ONDEMAND
1821 * 'service_add_listener()' - Bind an open fd as a Listener.
1825 service_add_listener(int fd
, /* I - Socket file descriptor */
1826 int idx
) /* I - Listener number, for logging */
1828 cupsd_listener_t
*lis
; /* Listeners array */
1829 http_addr_t addr
; /* Address variable */
1830 socklen_t addrlen
; /* Length of address */
1831 char s
[256]; /* String addresss */
1834 addrlen
= sizeof(addr
);
1836 if (getsockname(fd
, (struct sockaddr
*)&addr
, &addrlen
))
1838 cupsdLogMessage(CUPSD_LOG_ERROR
, "service_add_listener: Unable to get local address for listener #%d: %s", idx
+ 1, strerror(errno
));
1842 cupsdLogMessage(CUPSD_LOG_DEBUG
, "service_add_listener: Listener #%d at fd %d, \"%s\".", idx
+ 1, fd
, httpAddrString(&addr
, s
, sizeof(s
)));
1845 * Try to match the on-demand socket address to one of the listeners...
1848 for (lis
= (cupsd_listener_t
*)cupsArrayFirst(Listeners
);
1850 lis
= (cupsd_listener_t
*)cupsArrayNext(Listeners
))
1851 if (httpAddrEqual(&lis
->address
, &addr
))
1855 * Add a new listener If there's no match...
1860 cupsdLogMessage(CUPSD_LOG_DEBUG
, "service_add_listener: Matched existing listener #%d to %s.", idx
+ 1, httpAddrString(&(lis
->address
), s
, sizeof(s
)));
1864 cupsdLogMessage(CUPSD_LOG_DEBUG
, "service_add_listener: Adding new listener #%d for %s.", idx
+ 1, httpAddrString(&addr
, s
, sizeof(s
)));
1866 if ((lis
= calloc(1, sizeof(cupsd_listener_t
))) == NULL
)
1868 cupsdLogMessage(CUPSD_LOG_ERROR
, "service_add_listener: Unable to allocate listener: %s.", strerror(errno
));
1873 cupsArrayAdd(Listeners
, lis
);
1875 memcpy(&lis
->address
, &addr
, sizeof(lis
->address
));
1882 if (httpAddrPort(&(lis
->address
)) == 443)
1883 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
1884 # endif /* HAVE_SSL */
1889 * 'service_checkin()' - Check-in with launchd and collect the listening fds.
1893 service_checkin(void)
1895 # ifdef HAVE_LAUNCHD
1896 int error
; /* Check-in error, if any */
1897 size_t i
, /* Looping var */
1898 count
; /* Number of listeners */
1899 int *ld_sockets
; /* Listener sockets */
1902 cupsdLogMessage(CUPSD_LOG_DEBUG
, "service_checkin: pid=%d", (int)getpid());
1905 * Check-in with launchd...
1908 if ((error
= launch_activate_socket("Listeners", &ld_sockets
, &count
)) != 0)
1910 cupsdLogMessage(CUPSD_LOG_ERROR
, "service_checkin: Unable to get listener sockets: %s", strerror(error
));
1912 return; /* anti-compiler-warning */
1916 * Try to match the launchd sockets to the cupsd listeners...
1919 cupsdLogMessage(CUPSD_LOG_DEBUG
, "service_checkin: %d listeners.", (int)count
);
1921 for (i
= 0; i
< count
; i
++)
1922 service_add_listener(ld_sockets
[i
], (int)i
);
1926 # elif defined(HAVE_SYSTEMD)
1927 int i
, /* Looping var */
1928 count
; /* Number of listeners */
1931 cupsdLogMessage(CUPSD_LOG_DEBUG
, "service_checkin: pid=%d", (int)getpid());
1934 * Check-in with systemd...
1937 if ((count
= sd_listen_fds(0)) < 0)
1939 cupsdLogMessage(CUPSD_LOG_ERROR
, "service_checkin: Unable to get listener sockets: %s", strerror(-count
));
1941 return; /* anti-compiler-warning */
1945 * Try to match the systemd sockets to the cupsd listeners...
1948 cupsdLogMessage(CUPSD_LOG_DEBUG
, "service_checkin: %d listeners.", count
);
1950 for (i
= 0; i
< count
; i
++)
1951 service_add_listener(SD_LISTEN_FDS_START
+ i
, i
);
1953 # elif defined(HAVE_UPSTART)
1954 const char *e
; /* Environment var */
1955 int fd
; /* File descriptor */
1958 if (!(e
= getenv("UPSTART_EVENTS")))
1960 cupsdLogMessage(CUPSD_LOG_ERROR
, "service_checkin: We did not get started via Upstart.");
1965 if (strcasecmp(e
, "socket"))
1967 cupsdLogMessage(CUPSD_LOG_ERROR
, "service_checkin: We did not get triggered via an Upstart socket event.");
1972 if ((e
= getenv("UPSTART_FDS")) == NULL
)
1974 cupsdLogMessage(CUPSD_LOG_ERROR
, "service_checkin: Unable to get listener sockets from UPSTART_FDS.");
1979 cupsdLogMessage(CUPSD_LOG_DEBUG
, "service_checkin: UPSTART_FDS=%s", e
);
1981 fd
= (int)strtol(e
, NULL
, 10);
1984 cupsdLogMessage(CUPSD_LOG_ERROR
, "service_checkin: Could not parse UPSTART_FDS: %s", strerror(errno
));
1990 * Upstart only supportst a single on-demand socket file descriptor...
1993 service_add_listener(fd
, 0);
1996 # error "Error: defined HAVE_ONDEMAND but no launchd/systemd/upstart selection"
1997 # endif /* HAVE_LAUNCH_ACTIVATE_SOCKET */
2002 * 'service_checkout()' - Update the CUPS_KEEPALIVE file as needed.
2006 service_checkout(void)
2008 int fd
; /* File descriptor */
2012 * Create or remove the "keep-alive" file based on whether there are active
2013 * jobs or shared printers to advertise...
2016 if (cupsArrayCount(ActiveJobs
) || /* Active jobs */
2017 WebInterface
|| /* Web interface enabled */
2018 NeedReload
|| /* Doing a reload */
2019 (Browsing
&& BrowseLocalProtocols
&& cupsArrayCount(Printers
)))
2020 /* Printers being shared */
2022 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Creating keep-alive file \"" CUPS_KEEPALIVE
"\".");
2024 if ((fd
= open(CUPS_KEEPALIVE
, O_RDONLY
| O_CREAT
| O_EXCL
, S_IRUSR
)) >= 0)
2029 cupsdLogMessage(CUPSD_LOG_DEBUG
, "Removing keep-alive file \"" CUPS_KEEPALIVE
"\".");
2031 unlink(CUPS_KEEPALIVE
);
2034 #endif /* HAVE_ONDEMAND */
2038 * 'usage()' - Show scheduler usage.
2042 usage(int status
) /* O - Exit status */
2044 FILE *fp
= status
? stderr
: stdout
; /* Output file */
2047 _cupsLangPuts(fp
, _("Usage: cupsd [options]"));
2048 _cupsLangPuts(fp
, _("Options:"));
2049 _cupsLangPuts(fp
, _(" -c cupsd.conf Set cupsd.conf file to use."));
2050 _cupsLangPuts(fp
, _(" -f Run in the foreground."));
2051 _cupsLangPuts(fp
, _(" -F Run in the foreground but detach from console."));
2052 _cupsLangPuts(fp
, _(" -h Show this usage message."));
2053 #ifdef HAVE_ONDEMAND
2054 _cupsLangPuts(fp
, _(" -l Run cupsd on demand."));
2055 #endif /* HAVE_ONDEMAND */
2056 _cupsLangPuts(fp
, _(" -s cups-files.conf Set cups-files.conf file to use."));
2057 _cupsLangPuts(fp
, _(" -t Test the configuration file."));