]> git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/server.c
License change: Apache License, Version 2.0.
[thirdparty/cups.git] / scheduler / server.c
1 /*
2 * Server start/stop routines for the CUPS scheduler.
3 *
4 * Copyright 2007-2017 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 * Start color management (as needed)...
38 */
39
40 cupsdStartColor();
41
42 /*
43 * Create the default security profile...
44 */
45
46 DefaultProfile = cupsdCreateProfile(0, 1);
47
48 /*
49 * Startup all the networking stuff...
50 */
51
52 cupsdStartListening();
53 cupsdStartBrowsing();
54
55 /*
56 * Create a pipe for CGI processes...
57 */
58
59 if (cupsdOpenPipe(CGIPipes))
60 cupsdLogMessage(CUPSD_LOG_ERROR,
61 "cupsdStartServer: Unable to create pipes for CGI status!");
62 else
63 {
64 CGIStatusBuffer = cupsdStatBufNew(CGIPipes[0], "[CGI]");
65
66 cupsdAddSelect(CGIPipes[0], (cupsd_selfunc_t)cupsdUpdateCGI, NULL, NULL);
67 }
68
69 /*
70 * Mark that the server has started and printers and jobs may be changed...
71 */
72
73 LastEvent = CUPSD_EVENT_PRINTER_CHANGED | CUPSD_EVENT_JOB_STATE_CHANGED |
74 CUPSD_EVENT_SERVER_STARTED;
75 started = 1;
76
77 cupsdSetBusyState(0);
78 }
79
80
81 /*
82 * 'cupsdStopServer()' - Stop the server.
83 */
84
85 void
86 cupsdStopServer(void)
87 {
88 if (!started)
89 return;
90
91 /*
92 * Stop color management (as needed)...
93 */
94
95 cupsdStopColor();
96
97 /*
98 * Close all network clients...
99 */
100
101 cupsdCloseAllClients();
102 cupsdStopListening();
103 cupsdStopBrowsing();
104 cupsdStopAllNotifiers();
105 cupsdDeleteAllCerts();
106
107 if (Clients)
108 {
109 cupsArrayDelete(Clients);
110 Clients = NULL;
111 }
112
113 /*
114 * Close the pipe for CGI processes...
115 */
116
117 if (CGIPipes[0] >= 0)
118 {
119 cupsdRemoveSelect(CGIPipes[0]);
120
121 cupsdStatBufDelete(CGIStatusBuffer);
122 close(CGIPipes[1]);
123
124 CGIPipes[0] = -1;
125 CGIPipes[1] = -1;
126 }
127
128 /*
129 * Close all log files...
130 */
131
132 if (AccessFile != NULL)
133 {
134 if (AccessFile != LogStderr)
135 cupsFileClose(AccessFile);
136
137 AccessFile = NULL;
138 }
139
140 if (ErrorFile != NULL)
141 {
142 if (ErrorFile != LogStderr)
143 cupsFileClose(ErrorFile);
144
145 ErrorFile = NULL;
146 }
147
148 if (PageFile != NULL)
149 {
150 if (PageFile != LogStderr)
151 cupsFileClose(PageFile);
152
153 PageFile = NULL;
154 }
155
156 /*
157 * Delete the default security profile...
158 */
159
160 cupsdDestroyProfile(DefaultProfile);
161 DefaultProfile = NULL;
162
163 /*
164 * Write out any dirty files...
165 */
166
167 if (DirtyFiles)
168 cupsdCleanDirty();
169
170 started = 0;
171 }