]> git.ipfire.org Git - thirdparty/cups.git/blame - scheduler/server.c
Mass change of copyright to CUPS' new owner, Apple Inc.
[thirdparty/cups.git] / scheduler / server.c
CommitLineData
89db771d 1/*
c9d3f842 2 * "$Id$"
89db771d 3 *
4 * Server start/stop routines for the Common UNIX Printing System (CUPS).
5 *
4e8d321f 6 * Copyright 2007 by Apple Inc.
d10c7a3d 7 * Copyright 1997-2006 by Easy Software Products, all rights reserved.
89db771d 8 *
9 * These coded instructions, statements, and computer programs are the
4e8d321f 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/".
89db771d 14 *
15 * Contents:
16 *
589eb420 17 * cupsdStartServer() - Start the server.
18 * cupsdStopServer() - Stop the server.
89db771d 19 */
20
21/*
22 * Include necessary headers...
23 */
24
3b602493 25#include <cups/http-private.h>
89db771d 26#include "cupsd.h"
7a91f14b 27#include <grp.h>
beda8626 28#ifdef HAVE_NOTIFY_H
29# include <notify.h>
30#endif /* HAVE_NOTIFY_H */
7a91f14b 31
89db771d 32
9b4efe89 33/*
34 * Local globals...
35 */
36
37static int started = 0;
38
39
89db771d 40/*
589eb420 41 * 'cupsdStartServer()' - Start the server.
89db771d 42 */
43
44void
589eb420 45cupsdStartServer(void)
89db771d 46{
47#ifdef HAVE_LIBSSL
f3e786fc 48 int i; /* Looping var */
49 struct timeval curtime; /* Current time in microseconds */
50 unsigned char data[1024]; /* Seed data */
89db771d 51#endif /* HAVE_LIBSSL */
52
53
74fccf89 54#ifdef HAVE_LIBSSL
89db771d 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));
74fccf89 74#elif defined(HAVE_GNUTLS)
bcf61448 75 /*
76 * Initialize the encryption libraries...
77 */
78
79 gnutls_global_init();
89db771d 80#endif /* HAVE_LIBSSL */
81
82 /*
83 * Startup all the networking stuff...
84 */
85
589eb420 86 cupsdStartListening();
87 cupsdStartBrowsing();
88 cupsdStartPolling();
0a968cfb 89
90 /*
91 * Create a pipe for CGI processes...
92 */
93
8650fcf2 94 if (cupsdOpenPipe(CGIPipes))
f3e786fc 95 cupsdLogMessage(CUPSD_LOG_ERROR,
96 "cupsdStartServer: Unable to create pipes for CGI status!");
db3c5bfd 97 else
98 {
99 CGIStatusBuffer = cupsdStatBufNew(CGIPipes[0], "[CGI]");
e6df8a90 100
9d4830a3 101 cupsdAddSelect(CGIPipes[0], (cupsd_selfunc_t)cupsdUpdateCGI, NULL, NULL);
db3c5bfd 102 }
9b4efe89 103
beda8626 104 /*
105 * Mark that the server has started and printers and jobs may be changed...
106 */
107
108 LastEvent = CUPSD_EVENT_PRINTER_CHANGED | CUPSD_EVENT_JOB_STATE_CHANGED |
109 CUPSD_EVENT_SERVER_STARTED;
beda8626 110
9b4efe89 111 started = 1;
89db771d 112}
113
114
115/*
589eb420 116 * 'cupsdStopServer()' - Stop the server.
89db771d 117 */
118
119void
589eb420 120cupsdStopServer(void)
89db771d 121{
9b4efe89 122 if (!started)
123 return;
124
89db771d 125 /*
126 * Close all network clients and stop all jobs...
127 */
128
589eb420 129 cupsdCloseAllClients();
130 cupsdStopListening();
131 cupsdStopPolling();
132 cupsdStopBrowsing();
fe3a28b7 133 cupsdStopAllNotifiers();
9b4efe89 134 cupsdSaveRemoteCache();
bd58a948 135 cupsdDeleteAllCerts();
89db771d 136
48b71928 137 if (Clients)
89db771d 138 {
48b71928 139 cupsArrayDelete(Clients);
89db771d 140 Clients = NULL;
141 }
142
0a968cfb 143 /*
144 * Close the pipe for CGI processes...
145 */
146
147 if (CGIPipes[0] >= 0)
148 {
9d4830a3 149 cupsdRemoveSelect(CGIPipes[0]);
53510eae 150
fd09381d 151 cupsdStatBufDelete(CGIStatusBuffer);
152 close(CGIPipes[1]);
153
0a968cfb 154 CGIPipes[0] = -1;
155 CGIPipes[1] = -1;
156 }
157
89db771d 158 /*
159 * Close all log files...
160 */
161
162 if (AccessFile != NULL)
163 {
7b0fde61 164 cupsFileClose(AccessFile);
89db771d 165
166 AccessFile = NULL;
167 }
168
169 if (ErrorFile != NULL)
170 {
7b0fde61 171 cupsFileClose(ErrorFile);
89db771d 172
173 ErrorFile = NULL;
174 }
175
176 if (PageFile != NULL)
177 {
7b0fde61 178 cupsFileClose(PageFile);
89db771d 179
180 PageFile = NULL;
181 }
9b4efe89 182
beda8626 183#ifdef HAVE_NOTIFY_POST
184 /*
185 * Send one last notification as the server shuts down.
186 */
187
188 cupsdLogMessage(CUPSD_LOG_DEBUG,
189 "notify_post(\"com.apple.printerListChange\") last");
190 notify_post("com.apple.printerListChange");
191#endif /* HAVE_NOTIFY_POST */
192
9b4efe89 193 started = 0;
89db771d 194}
195
196
197/*
c9d3f842 198 * End of "$Id$".
89db771d 199 */