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