]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
503b54c9 | 2 | * Server start/stop routines for the CUPS scheduler. |
ef416fc2 | 3 | * |
e4e37194 | 4 | * Copyright 2007-2017 by Apple Inc. |
503b54c9 | 5 | * Copyright 1997-2006 by Easy Software Products, all rights reserved. |
ef416fc2 | 6 | * |
e3101897 | 7 | * Licensed under Apache License v2.0. See the file "LICENSE" for more information. |
ef416fc2 | 8 | */ |
9 | ||
10 | /* | |
11 | * Include necessary headers... | |
12 | */ | |
13 | ||
14 | #include <cups/http-private.h> | |
15 | #include "cupsd.h" | |
16 | #include <grp.h> | |
fa73b229 | 17 | #ifdef HAVE_NOTIFY_H |
18 | # include <notify.h> | |
19 | #endif /* HAVE_NOTIFY_H */ | |
ef416fc2 | 20 | |
21 | ||
22 | /* | |
23 | * Local globals... | |
24 | */ | |
25 | ||
84315f46 | 26 | static int started = 0; /* Did we start the server already? */ |
ef416fc2 | 27 | |
28 | ||
29 | /* | |
30 | * 'cupsdStartServer()' - Start the server. | |
31 | */ | |
32 | ||
33 | void | |
34 | cupsdStartServer(void) | |
35 | { | |
a29fd7dd | 36 | /* |
0d92ec1c | 37 | * Create the default security profile... |
a29fd7dd MS |
38 | */ |
39 | ||
0d92ec1c MS |
40 | DefaultProfile = cupsdCreateProfile(0, 1); |
41 | ||
42 | #ifdef HAVE_SANDBOX_H | |
43 | if (!DefaultProfile && UseSandboxing && Sandboxing != CUPSD_SANDBOXING_OFF) | |
44 | { | |
45 | /* | |
46 | * Failure to create the sandbox profile means something really bad has | |
47 | * happened and we need to shutdown immediately. | |
48 | */ | |
49 | ||
50 | return; | |
51 | } | |
52 | #endif /* HAVE_SANDBOX_H */ | |
a29fd7dd | 53 | |
a4924f6c | 54 | /* |
0d92ec1c | 55 | * Start color management (as needed)... |
a4924f6c MS |
56 | */ |
57 | ||
0d92ec1c | 58 | cupsdStartColor(); |
a4924f6c | 59 | |
ef416fc2 | 60 | /* |
61 | * Startup all the networking stuff... | |
62 | */ | |
63 | ||
64 | cupsdStartListening(); | |
65 | cupsdStartBrowsing(); | |
ef416fc2 | 66 | |
67 | /* | |
68 | * Create a pipe for CGI processes... | |
69 | */ | |
70 | ||
71 | if (cupsdOpenPipe(CGIPipes)) | |
72 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
73 | "cupsdStartServer: Unable to create pipes for CGI status!"); | |
74 | else | |
75 | { | |
76 | CGIStatusBuffer = cupsdStatBufNew(CGIPipes[0], "[CGI]"); | |
77 | ||
f7deaa1a | 78 | cupsdAddSelect(CGIPipes[0], (cupsd_selfunc_t)cupsdUpdateCGI, NULL, NULL); |
ef416fc2 | 79 | } |
80 | ||
fa73b229 | 81 | /* |
82 | * Mark that the server has started and printers and jobs may be changed... | |
83 | */ | |
84 | ||
49d87452 MS |
85 | LastEvent = CUPSD_EVENT_PRINTER_CHANGED | CUPSD_EVENT_JOB_STATE_CHANGED | |
86 | CUPSD_EVENT_SERVER_STARTED; | |
87 | started = 1; | |
fa73b229 | 88 | |
e4e37194 | 89 | cupsdSetBusyState(0); |
ef416fc2 | 90 | } |
91 | ||
92 | ||
93 | /* | |
94 | * 'cupsdStopServer()' - Stop the server. | |
95 | */ | |
96 | ||
97 | void | |
98 | cupsdStopServer(void) | |
99 | { | |
100 | if (!started) | |
101 | return; | |
102 | ||
103 | /* | |
a29fd7dd MS |
104 | * Stop color management (as needed)... |
105 | */ | |
106 | ||
107 | cupsdStopColor(); | |
108 | ||
109 | /* | |
110 | * Close all network clients... | |
ef416fc2 | 111 | */ |
112 | ||
113 | cupsdCloseAllClients(); | |
114 | cupsdStopListening(); | |
ef416fc2 | 115 | cupsdStopBrowsing(); |
116 | cupsdStopAllNotifiers(); | |
e1d6a774 | 117 | cupsdDeleteAllCerts(); |
ef416fc2 | 118 | |
a74454a7 | 119 | if (Clients) |
ef416fc2 | 120 | { |
a74454a7 | 121 | cupsArrayDelete(Clients); |
ef416fc2 | 122 | Clients = NULL; |
123 | } | |
124 | ||
ef416fc2 | 125 | /* |
126 | * Close the pipe for CGI processes... | |
127 | */ | |
128 | ||
129 | if (CGIPipes[0] >= 0) | |
130 | { | |
f7deaa1a | 131 | cupsdRemoveSelect(CGIPipes[0]); |
ef416fc2 | 132 | |
133 | cupsdStatBufDelete(CGIStatusBuffer); | |
134 | close(CGIPipes[1]); | |
135 | ||
136 | CGIPipes[0] = -1; | |
137 | CGIPipes[1] = -1; | |
138 | } | |
139 | ||
140 | /* | |
141 | * Close all log files... | |
142 | */ | |
143 | ||
144 | if (AccessFile != NULL) | |
145 | { | |
a1797929 MS |
146 | if (AccessFile != LogStderr) |
147 | cupsFileClose(AccessFile); | |
ef416fc2 | 148 | |
149 | AccessFile = NULL; | |
150 | } | |
151 | ||
152 | if (ErrorFile != NULL) | |
153 | { | |
a1797929 MS |
154 | if (ErrorFile != LogStderr) |
155 | cupsFileClose(ErrorFile); | |
ef416fc2 | 156 | |
157 | ErrorFile = NULL; | |
158 | } | |
159 | ||
160 | if (PageFile != NULL) | |
161 | { | |
a1797929 MS |
162 | if (PageFile != LogStderr) |
163 | cupsFileClose(PageFile); | |
ef416fc2 | 164 | |
165 | PageFile = NULL; | |
166 | } | |
167 | ||
fa73b229 | 168 | /* |
a4924f6c | 169 | * Delete the default security profile... |
fa73b229 | 170 | */ |
171 | ||
a4924f6c MS |
172 | cupsdDestroyProfile(DefaultProfile); |
173 | DefaultProfile = NULL; | |
fa73b229 | 174 | |
3dfe78b3 MS |
175 | /* |
176 | * Write out any dirty files... | |
177 | */ | |
178 | ||
179 | if (DirtyFiles) | |
180 | cupsdCleanDirty(); | |
181 | ||
ef416fc2 | 182 | started = 0; |
183 | } |