]> git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/server.c
Merge changes from CUPS 1.6svn-r10112.
[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-2010 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 #ifdef HAVE_NOTIFY_POST
128 /*
129 * Send one last notification as the server shuts down.
130 */
131
132 cupsdLogMessage(CUPSD_LOG_DEBUG2,
133 "notify_post(\"com.apple.printerListChange\") last");
134 notify_post("com.apple.printerListChange");
135 #endif /* HAVE_NOTIFY_POST */
136
137 /*
138 * Close all log files...
139 */
140
141 if (AccessFile != NULL)
142 {
143 cupsFileClose(AccessFile);
144
145 AccessFile = NULL;
146 }
147
148 if (ErrorFile != NULL)
149 {
150 cupsFileClose(ErrorFile);
151
152 ErrorFile = NULL;
153 }
154
155 if (PageFile != NULL)
156 {
157 cupsFileClose(PageFile);
158
159 PageFile = NULL;
160 }
161
162 /*
163 * Delete the default security profile...
164 */
165
166 cupsdDestroyProfile(DefaultProfile);
167 DefaultProfile = NULL;
168
169 /*
170 * Write out any dirty files...
171 */
172
173 if (DirtyFiles)
174 cupsdCleanDirty();
175
176 started = 0;
177 }
178
179
180 /*
181 * End of "$Id: server.c 7927 2008-09-10 22:05:29Z mike $".
182 */