]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
b423cd4c | 2 | * "$Id: server.c 5200 2006-02-28 00:10:32Z mike $" |
ef416fc2 | 3 | * |
4 | * Server start/stop routines for the Common UNIX Printing System (CUPS). | |
5 | * | |
bd7854cb | 6 | * Copyright 1997-2006 by Easy Software Products, all rights reserved. |
ef416fc2 | 7 | * |
8 | * These coded instructions, statements, and computer programs are the | |
9 | * property of Easy Software Products and are protected by Federal | |
10 | * copyright law. Distribution and use rights are outlined in the file | |
11 | * "LICENSE.txt" which should have been included with this file. If this | |
12 | * file is missing or damaged please contact Easy Software Products | |
13 | * at: | |
14 | * | |
15 | * Attn: CUPS Licensing Information | |
16 | * Easy Software Products | |
17 | * 44141 Airport View Drive, Suite 204 | |
18 | * Hollywood, Maryland 20636 USA | |
19 | * | |
20 | * Voice: (301) 373-9600 | |
21 | * EMail: cups-info@cups.org | |
22 | * WWW: http://www.cups.org | |
23 | * | |
24 | * Contents: | |
25 | * | |
26 | * cupsdStartServer() - Start the server. | |
27 | * cupsdStopServer() - Stop the server. | |
28 | */ | |
29 | ||
30 | /* | |
31 | * Include necessary headers... | |
32 | */ | |
33 | ||
34 | #include <cups/http-private.h> | |
35 | #include "cupsd.h" | |
36 | #include <grp.h> | |
fa73b229 | 37 | #ifdef HAVE_NOTIFY_H |
38 | # include <notify.h> | |
39 | #endif /* HAVE_NOTIFY_H */ | |
ef416fc2 | 40 | |
41 | ||
42 | /* | |
43 | * Local globals... | |
44 | */ | |
45 | ||
46 | static int started = 0; | |
47 | ||
48 | ||
49 | /* | |
50 | * 'cupsdStartServer()' - Start the server. | |
51 | */ | |
52 | ||
53 | void | |
54 | cupsdStartServer(void) | |
55 | { | |
56 | #ifdef HAVE_LIBSSL | |
57 | int i; /* Looping var */ | |
58 | struct timeval curtime; /* Current time in microseconds */ | |
59 | unsigned char data[1024]; /* Seed data */ | |
60 | #endif /* HAVE_LIBSSL */ | |
61 | ||
62 | ||
63 | #ifdef HAVE_LIBSSL | |
64 | /* | |
65 | * Initialize the encryption libraries... | |
66 | */ | |
67 | ||
68 | SSL_library_init(); | |
69 | SSL_load_error_strings(); | |
70 | ||
71 | /* | |
72 | * Using the current time is a dubious random seed, but on some systems | |
73 | * it is the best we can do (on others, this seed isn't even used...) | |
74 | */ | |
75 | ||
76 | gettimeofday(&curtime, NULL); | |
77 | srand(curtime.tv_sec + curtime.tv_usec); | |
78 | ||
79 | for (i = 0; i < sizeof(data); i ++) | |
80 | data[i] = rand(); /* Yes, this is a poor source of random data... */ | |
81 | ||
82 | RAND_seed(&data, sizeof(data)); | |
83 | #elif defined(HAVE_GNUTLS) | |
84 | /* | |
85 | * Initialize the encryption libraries... | |
86 | */ | |
87 | ||
88 | gnutls_global_init(); | |
89 | #endif /* HAVE_LIBSSL */ | |
90 | ||
91 | /* | |
92 | * Startup all the networking stuff... | |
93 | */ | |
94 | ||
95 | cupsdStartListening(); | |
96 | cupsdStartBrowsing(); | |
97 | cupsdStartPolling(); | |
98 | ||
99 | /* | |
100 | * Create a pipe for CGI processes... | |
101 | */ | |
102 | ||
103 | if (cupsdOpenPipe(CGIPipes)) | |
104 | cupsdLogMessage(CUPSD_LOG_ERROR, | |
105 | "cupsdStartServer: Unable to create pipes for CGI status!"); | |
106 | else | |
107 | { | |
108 | CGIStatusBuffer = cupsdStatBufNew(CGIPipes[0], "[CGI]"); | |
109 | ||
110 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
111 | "cupsdStartServer: Adding fd %d to InputSet...", | |
112 | CGIPipes[0]); | |
113 | FD_SET(CGIPipes[0], InputSet); | |
114 | } | |
115 | ||
fa73b229 | 116 | /* |
117 | * Mark that the server has started and printers and jobs may be changed... | |
118 | */ | |
119 | ||
120 | LastEvent = CUPSD_EVENT_PRINTER_CHANGED | CUPSD_EVENT_JOB_STATE_CHANGED | | |
121 | CUPSD_EVENT_SERVER_STARTED; | |
122 | LastEventTime = 0; | |
123 | ||
ef416fc2 | 124 | started = 1; |
125 | } | |
126 | ||
127 | ||
128 | /* | |
129 | * 'cupsdStopServer()' - Stop the server. | |
130 | */ | |
131 | ||
132 | void | |
133 | cupsdStopServer(void) | |
134 | { | |
135 | if (!started) | |
136 | return; | |
137 | ||
138 | /* | |
139 | * Close all network clients and stop all jobs... | |
140 | */ | |
141 | ||
142 | cupsdCloseAllClients(); | |
143 | cupsdStopListening(); | |
144 | cupsdStopPolling(); | |
145 | cupsdStopBrowsing(); | |
146 | cupsdStopAllNotifiers(); | |
147 | cupsdSaveRemoteCache(); | |
148 | ||
149 | if (Clients != NULL) | |
150 | { | |
151 | free(Clients); | |
152 | Clients = NULL; | |
153 | } | |
154 | ||
ef416fc2 | 155 | /* |
156 | * Close the pipe for CGI processes... | |
157 | */ | |
158 | ||
159 | if (CGIPipes[0] >= 0) | |
160 | { | |
161 | cupsdLogMessage(CUPSD_LOG_DEBUG2, | |
162 | "cupsdStopServer: Removing fd %d from InputSet...", | |
163 | CGIPipes[0]); | |
164 | ||
165 | FD_CLR(CGIPipes[0], InputSet); | |
166 | ||
167 | cupsdStatBufDelete(CGIStatusBuffer); | |
168 | close(CGIPipes[1]); | |
169 | ||
170 | CGIPipes[0] = -1; | |
171 | CGIPipes[1] = -1; | |
172 | } | |
173 | ||
174 | /* | |
175 | * Close all log files... | |
176 | */ | |
177 | ||
178 | if (AccessFile != NULL) | |
179 | { | |
180 | cupsFileClose(AccessFile); | |
181 | ||
182 | AccessFile = NULL; | |
183 | } | |
184 | ||
185 | if (ErrorFile != NULL) | |
186 | { | |
187 | cupsFileClose(ErrorFile); | |
188 | ||
189 | ErrorFile = NULL; | |
190 | } | |
191 | ||
192 | if (PageFile != NULL) | |
193 | { | |
194 | cupsFileClose(PageFile); | |
195 | ||
196 | PageFile = NULL; | |
197 | } | |
198 | ||
fa73b229 | 199 | #ifdef HAVE_NOTIFY_POST |
200 | /* | |
201 | * Send one last notification as the server shuts down. | |
202 | */ | |
203 | ||
204 | cupsdLogMessage(CUPSD_LOG_DEBUG, | |
205 | "notify_post(\"com.apple.printerListChange\") last"); | |
206 | notify_post("com.apple.printerListChange"); | |
207 | #endif /* HAVE_NOTIFY_POST */ | |
208 | ||
ef416fc2 | 209 | started = 0; |
210 | } | |
211 | ||
212 | ||
213 | /* | |
b423cd4c | 214 | * End of "$Id: server.c 5200 2006-02-28 00:10:32Z mike $". |
ef416fc2 | 215 | */ |