]> git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/server.c
Update ipp documentation to reflect the behavior of configuring WiFi on IPP USB printers.
[thirdparty/cups.git] / scheduler / server.c
1 /*
2 * Server start/stop routines for the CUPS scheduler.
3 *
4 * Copyright 2007-2019 by Apple Inc.
5 * Copyright 1997-2006 by Easy Software Products, all rights reserved.
6 *
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
8 */
9
10 /*
11 * Include necessary headers...
12 */
13
14 #include <cups/http-private.h>
15 #include "cupsd.h"
16 #include <grp.h>
17 #ifdef HAVE_NOTIFY_H
18 # include <notify.h>
19 #endif /* HAVE_NOTIFY_H */
20
21
22 /*
23 * Local globals...
24 */
25
26 static int started = 0; /* Did we start the server already? */
27
28
29 /*
30 * 'cupsdStartServer()' - Start the server.
31 */
32
33 void
34 cupsdStartServer(void)
35 {
36 /*
37 * Create the default security profile...
38 */
39
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 */
53
54 /*
55 * Start color management (as needed)...
56 */
57
58 cupsdStartColor();
59
60 /*
61 * Startup all the networking stuff...
62 */
63
64 cupsdStartListening();
65 cupsdStartBrowsing();
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
78 cupsdAddSelect(CGIPipes[0], (cupsd_selfunc_t)cupsdUpdateCGI, NULL, NULL);
79 }
80
81 /*
82 * Mark that the server has started and printers and jobs may be changed...
83 */
84
85 LastEvent = CUPSD_EVENT_PRINTER_CHANGED | CUPSD_EVENT_JOB_STATE_CHANGED |
86 CUPSD_EVENT_SERVER_STARTED;
87 started = 1;
88
89 cupsdSetBusyState(0);
90 }
91
92
93 /*
94 * 'cupsdStopServer()' - Stop the server.
95 */
96
97 void
98 cupsdStopServer(void)
99 {
100 if (!started)
101 return;
102
103 /*
104 * Stop color management (as needed)...
105 */
106
107 cupsdStopColor();
108
109 /*
110 * Close all network clients...
111 */
112
113 cupsdCloseAllClients();
114 cupsdStopListening();
115 cupsdStopBrowsing();
116 cupsdStopAllNotifiers();
117 cupsdDeleteAllCerts();
118
119 if (Clients)
120 {
121 cupsArrayDelete(Clients);
122 Clients = NULL;
123 }
124
125 /*
126 * Close the pipe for CGI processes...
127 */
128
129 if (CGIPipes[0] >= 0)
130 {
131 cupsdRemoveSelect(CGIPipes[0]);
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 {
146 if (AccessFile != LogStderr)
147 cupsFileClose(AccessFile);
148
149 AccessFile = NULL;
150 }
151
152 if (ErrorFile != NULL)
153 {
154 if (ErrorFile != LogStderr)
155 cupsFileClose(ErrorFile);
156
157 ErrorFile = NULL;
158 }
159
160 if (PageFile != NULL)
161 {
162 if (PageFile != LogStderr)
163 cupsFileClose(PageFile);
164
165 PageFile = NULL;
166 }
167
168 /*
169 * Delete the default security profile...
170 */
171
172 cupsdDestroyProfile(DefaultProfile);
173 DefaultProfile = NULL;
174
175 /*
176 * Expire subscriptions and clean out old jobs...
177 */
178
179 cupsdExpireSubscriptions(NULL, NULL);
180
181 if (JobHistoryUpdate)
182 cupsdCleanJobs();
183
184 /*
185 * Write out any dirty files...
186 */
187
188 if (DirtyFiles)
189 cupsdCleanDirty();
190
191 started = 0;
192 }