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