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