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