]> git.ipfire.org Git - thirdparty/cups.git/blame - scheduler/server.c
Load cups into easysw/current.
[thirdparty/cups.git] / scheduler / server.c
CommitLineData
ef416fc2 1/*
2 * "$Id: server.c 4830 2005-11-12 03:27:16Z mike $"
3 *
4 * Server start/stop routines for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 1997-2005 by Easy Software Products, all rights reserved.
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>
37
38
39/*
40 * Local globals...
41 */
42
43static int started = 0;
44
45
46/*
47 * 'cupsdStartServer()' - Start the server.
48 */
49
50void
51cupsdStartServer(void)
52{
53#ifdef HAVE_LIBSSL
54 int i; /* Looping var */
55 struct timeval curtime; /* Current time in microseconds */
56 unsigned char data[1024]; /* Seed data */
57#endif /* HAVE_LIBSSL */
58
59
60#ifdef HAVE_LIBSSL
61 /*
62 * Initialize the encryption libraries...
63 */
64
65 SSL_library_init();
66 SSL_load_error_strings();
67
68 /*
69 * Using the current time is a dubious random seed, but on some systems
70 * it is the best we can do (on others, this seed isn't even used...)
71 */
72
73 gettimeofday(&curtime, NULL);
74 srand(curtime.tv_sec + curtime.tv_usec);
75
76 for (i = 0; i < sizeof(data); i ++)
77 data[i] = rand(); /* Yes, this is a poor source of random data... */
78
79 RAND_seed(&data, sizeof(data));
80#elif defined(HAVE_GNUTLS)
81 /*
82 * Initialize the encryption libraries...
83 */
84
85 gnutls_global_init();
86#endif /* HAVE_LIBSSL */
87
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
107 cupsdLogMessage(CUPSD_LOG_DEBUG2,
108 "cupsdStartServer: Adding fd %d to InputSet...",
109 CGIPipes[0]);
110 FD_SET(CGIPipes[0], InputSet);
111 }
112
113 started = 1;
114}
115
116
117/*
118 * 'cupsdStopServer()' - Stop the server.
119 */
120
121void
122cupsdStopServer(void)
123{
124 if (!started)
125 return;
126
127 /*
128 * Close all network clients and stop all jobs...
129 */
130
131 cupsdCloseAllClients();
132 cupsdStopListening();
133 cupsdStopPolling();
134 cupsdStopBrowsing();
135 cupsdStopAllNotifiers();
136 cupsdSaveRemoteCache();
137
138 if (Clients != NULL)
139 {
140 free(Clients);
141 Clients = NULL;
142 }
143
144#if defined(HAVE_SSL) && defined(HAVE_CDSASSL)
145 /*
146 * Free all of the certificates...
147 */
148
149 if (ServerCertificatesArray)
150 {
151 CFRelease(ServerCertificatesArray);
152 ServerCertificatesArray = NULL;
153 }
154#endif /* HAVE_SSL && HAVE_CDSASSL */
155
156 /*
157 * Close the pipe for CGI processes...
158 */
159
160 if (CGIPipes[0] >= 0)
161 {
162 cupsdLogMessage(CUPSD_LOG_DEBUG2,
163 "cupsdStopServer: Removing fd %d from InputSet...",
164 CGIPipes[0]);
165
166 FD_CLR(CGIPipes[0], InputSet);
167
168 cupsdStatBufDelete(CGIStatusBuffer);
169 close(CGIPipes[1]);
170
171 CGIPipes[0] = -1;
172 CGIPipes[1] = -1;
173 }
174
175 /*
176 * Close all log files...
177 */
178
179 if (AccessFile != NULL)
180 {
181 cupsFileClose(AccessFile);
182
183 AccessFile = NULL;
184 }
185
186 if (ErrorFile != NULL)
187 {
188 cupsFileClose(ErrorFile);
189
190 ErrorFile = NULL;
191 }
192
193 if (PageFile != NULL)
194 {
195 cupsFileClose(PageFile);
196
197 PageFile = NULL;
198 }
199
200 started = 0;
201}
202
203
204/*
205 * End of "$Id: server.c 4830 2005-11-12 03:27:16Z mike $".
206 */