]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
75bd9771 | 2 | * "$Id: server.c 7468 2008-04-18 18:31:59Z mike $" |
ef416fc2 | 3 | * |
4 | * Server start/stop routines for the Common UNIX Printing System (CUPS). | |
5 | * | |
3dfe78b3 | 6 | * Copyright 2007-2008 by Apple Inc. |
bd7854cb | 7 | * Copyright 1997-2006 by Easy Software Products, all rights reserved. |
ef416fc2 | 8 | * |
9 | * These coded instructions, statements, and computer programs are the | |
bc44d920 | 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/". | |
ef416fc2 | 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> | |
fa73b229 | 28 | #ifdef HAVE_NOTIFY_H |
29 | # include <notify.h> | |
30 | #endif /* HAVE_NOTIFY_H */ | |
ef416fc2 | 31 | |
32 | ||
33 | /* | |
34 | * Local globals... | |
35 | */ | |
36 | ||
37 | static int started = 0; | |
38 | ||
39 | ||
40 | /* | |
41 | * 'cupsdStartServer()' - Start the server. | |
42 | */ | |
43 | ||
44 | void | |
45 | cupsdStartServer(void) | |
46 | { | |
47 | #ifdef HAVE_LIBSSL | |
48 | int i; /* Looping var */ | |
49 | struct timeval curtime; /* Current time in microseconds */ | |
50 | unsigned char data[1024]; /* Seed data */ | |
51 | #endif /* HAVE_LIBSSL */ | |
52 | ||
53 | ||
54 | #ifdef HAVE_LIBSSL | |
55 | /* | |
56 | * Initialize the encryption libraries... | |
57 | */ | |
58 | ||
59 | SSL_library_init(); | |
60 | SSL_load_error_strings(); | |
61 | ||
62 | /* | |
63 | * Using the current time is a dubious random seed, but on some systems | |
64 | * it is the best we can do (on others, this seed isn't even used...) | |
65 | */ | |
66 | ||
67 | gettimeofday(&curtime, NULL); | |
68 | srand(curtime.tv_sec + curtime.tv_usec); | |
69 | ||
70 | for (i = 0; i < sizeof(data); i ++) | |
71 | data[i] = rand(); /* Yes, this is a poor source of random data... */ | |
72 | ||
73 | RAND_seed(&data, sizeof(data)); | |
74 | #elif defined(HAVE_GNUTLS) | |
75 | /* | |
76 | * Initialize the encryption libraries... | |
77 | */ | |
78 | ||
79 | gnutls_global_init(); | |
80 | #endif /* HAVE_LIBSSL */ | |
81 | ||
a4924f6c MS |
82 | /* |
83 | * Create the default security profile... | |
84 | */ | |
85 | ||
86 | DefaultProfile = cupsdCreateProfile(0); | |
87 | ||
ef416fc2 | 88 | /* |
89 | * Startup all the networking stuff... | |
90 | */ | |
91 | ||
92 | cupsdStartListening(); | |
93 | cupsdStartBrowsing(); | |
94 | cupsdStartPolling(); | |
95 | ||
96 | /* | |
97 | * Create a pipe for CGI processes... | |
98 | */ | |
99 | ||
100 | if (cupsdOpenPipe(CGIPipes)) | |
101 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
102 | "cupsdStartServer: Unable to create pipes for CGI status!"); | |
103 | else | |
104 | { | |
105 | CGIStatusBuffer = cupsdStatBufNew(CGIPipes[0], "[CGI]"); | |
106 | ||
f7deaa1a | 107 | cupsdAddSelect(CGIPipes[0], (cupsd_selfunc_t)cupsdUpdateCGI, NULL, NULL); |
ef416fc2 | 108 | } |
109 | ||
fa73b229 | 110 | /* |
111 | * Mark that the server has started and printers and jobs may be changed... | |
112 | */ | |
113 | ||
114 | LastEvent = CUPSD_EVENT_PRINTER_CHANGED | CUPSD_EVENT_JOB_STATE_CHANGED | | |
115 | CUPSD_EVENT_SERVER_STARTED; | |
fa73b229 | 116 | |
ef416fc2 | 117 | started = 1; |
118 | } | |
119 | ||
120 | ||
121 | /* | |
122 | * 'cupsdStopServer()' - Stop the server. | |
123 | */ | |
124 | ||
125 | void | |
126 | cupsdStopServer(void) | |
127 | { | |
128 | if (!started) | |
129 | return; | |
130 | ||
131 | /* | |
132 | * Close all network clients and stop all jobs... | |
133 | */ | |
134 | ||
135 | cupsdCloseAllClients(); | |
136 | cupsdStopListening(); | |
137 | cupsdStopPolling(); | |
138 | cupsdStopBrowsing(); | |
139 | cupsdStopAllNotifiers(); | |
e1d6a774 | 140 | cupsdDeleteAllCerts(); |
ef416fc2 | 141 | |
a74454a7 | 142 | if (Clients) |
ef416fc2 | 143 | { |
a74454a7 | 144 | cupsArrayDelete(Clients); |
ef416fc2 | 145 | Clients = NULL; |
146 | } | |
147 | ||
ef416fc2 | 148 | /* |
149 | * Close the pipe for CGI processes... | |
150 | */ | |
151 | ||
152 | if (CGIPipes[0] >= 0) | |
153 | { | |
f7deaa1a | 154 | cupsdRemoveSelect(CGIPipes[0]); |
ef416fc2 | 155 | |
156 | cupsdStatBufDelete(CGIStatusBuffer); | |
157 | close(CGIPipes[1]); | |
158 | ||
159 | CGIPipes[0] = -1; | |
160 | CGIPipes[1] = -1; | |
161 | } | |
162 | ||
a4924f6c MS |
163 | #ifdef HAVE_NOTIFY_POST |
164 | /* | |
165 | * Send one last notification as the server shuts down. | |
166 | */ | |
167 | ||
168 | cupsdLogMessage(CUPSD_LOG_DEBUG, | |
169 | "notify_post(\"com.apple.printerListChange\") last"); | |
170 | notify_post("com.apple.printerListChange"); | |
171 | #endif /* HAVE_NOTIFY_POST */ | |
172 | ||
ef416fc2 | 173 | /* |
174 | * Close all log files... | |
175 | */ | |
176 | ||
177 | if (AccessFile != NULL) | |
178 | { | |
179 | cupsFileClose(AccessFile); | |
180 | ||
181 | AccessFile = NULL; | |
182 | } | |
183 | ||
184 | if (ErrorFile != NULL) | |
185 | { | |
186 | cupsFileClose(ErrorFile); | |
187 | ||
188 | ErrorFile = NULL; | |
189 | } | |
190 | ||
191 | if (PageFile != NULL) | |
192 | { | |
193 | cupsFileClose(PageFile); | |
194 | ||
195 | PageFile = NULL; | |
196 | } | |
197 | ||
fa73b229 | 198 | /* |
a4924f6c | 199 | * Delete the default security profile... |
fa73b229 | 200 | */ |
201 | ||
a4924f6c MS |
202 | cupsdDestroyProfile(DefaultProfile); |
203 | DefaultProfile = NULL; | |
fa73b229 | 204 | |
3dfe78b3 MS |
205 | /* |
206 | * Write out any dirty files... | |
207 | */ | |
208 | ||
209 | if (DirtyFiles) | |
210 | cupsdCleanDirty(); | |
211 | ||
ef416fc2 | 212 | started = 0; |
213 | } | |
214 | ||
215 | ||
216 | /* | |
75bd9771 | 217 | * End of "$Id: server.c 7468 2008-04-18 18:31:59Z mike $". |
ef416fc2 | 218 | */ |