2 * Server start/stop routines for the CUPS scheduler.
4 * Copyright 2007-2019 by Apple Inc.
5 * Copyright 1997-2006 by Easy Software Products, all rights reserved.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
11 * Include necessary headers...
14 #include <cups/http-private.h>
19 #endif /* HAVE_NOTIFY_H */
26 static int started
= 0; /* Did we start the server already? */
30 * 'cupsdStartServer()' - Start the server.
34 cupsdStartServer(void)
37 * Create the default security profile...
40 DefaultProfile
= cupsdCreateProfile(0, 1);
43 if (!DefaultProfile
&& UseSandboxing
&& Sandboxing
!= CUPSD_SANDBOXING_OFF
)
46 * Failure to create the sandbox profile means something really bad has
47 * happened and we need to shutdown immediately.
52 #endif /* HAVE_SANDBOX_H */
55 * Start color management (as needed)...
61 * Startup all the networking stuff...
64 cupsdStartListening();
68 * Create a pipe for CGI processes...
71 if (cupsdOpenPipe(CGIPipes
))
72 cupsdLogMessage(CUPSD_LOG_ERROR
,
73 "cupsdStartServer: Unable to create pipes for CGI status!");
76 CGIStatusBuffer
= cupsdStatBufNew(CGIPipes
[0], "[CGI]");
78 cupsdAddSelect(CGIPipes
[0], (cupsd_selfunc_t
)cupsdUpdateCGI
, NULL
, NULL
);
82 * Mark that the server has started and printers and jobs may be changed...
85 LastEvent
= CUPSD_EVENT_PRINTER_CHANGED
| CUPSD_EVENT_JOB_STATE_CHANGED
|
86 CUPSD_EVENT_SERVER_STARTED
;
94 * 'cupsdStopServer()' - Stop the server.
104 * Stop color management (as needed)...
110 * Close all network clients...
113 cupsdCloseAllClients();
114 cupsdStopListening();
116 cupsdStopAllNotifiers();
117 cupsdDeleteAllCerts();
121 cupsArrayDelete(Clients
);
126 * Close the pipe for CGI processes...
129 if (CGIPipes
[0] >= 0)
131 cupsdRemoveSelect(CGIPipes
[0]);
133 cupsdStatBufDelete(CGIStatusBuffer
);
141 * Close all log files...
144 if (AccessFile
!= NULL
)
146 if (AccessFile
!= LogStderr
)
147 cupsFileClose(AccessFile
);
152 if (ErrorFile
!= NULL
)
154 if (ErrorFile
!= LogStderr
)
155 cupsFileClose(ErrorFile
);
160 if (PageFile
!= NULL
)
162 if (PageFile
!= LogStderr
)
163 cupsFileClose(PageFile
);
169 * Delete the default security profile...
172 cupsdDestroyProfile(DefaultProfile
);
173 DefaultProfile
= NULL
;
176 * Expire subscriptions and clean out old jobs...
179 cupsdExpireSubscriptions(NULL
, NULL
);
181 if (JobHistoryUpdate
)
185 * Write out any dirty files...