2 * "$Id: server.c 6649 2007-07-11 21:46:42Z mike $"
4 * Server start/stop routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 by Apple Inc.
7 * Copyright 1997-2006 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
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/".
17 * cupsdStartServer() - Start the server.
18 * cupsdStopServer() - Stop the server.
22 * Include necessary headers...
25 #include <cups/http-private.h>
30 #endif /* HAVE_NOTIFY_H */
37 static int started
= 0;
41 * 'cupsdStartServer()' - Start the server.
45 cupsdStartServer(void)
48 int i
; /* Looping var */
49 struct timeval curtime
; /* Current time in microseconds */
50 unsigned char data
[1024]; /* Seed data */
51 #endif /* HAVE_LIBSSL */
56 * Initialize the encryption libraries...
60 SSL_load_error_strings();
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...)
67 gettimeofday(&curtime
, NULL
);
68 srand(curtime
.tv_sec
+ curtime
.tv_usec
);
70 for (i
= 0; i
< sizeof(data
); i
++)
71 data
[i
] = rand(); /* Yes, this is a poor source of random data... */
73 RAND_seed(&data
, sizeof(data
));
74 #elif defined(HAVE_GNUTLS)
76 * Initialize the encryption libraries...
80 #endif /* HAVE_LIBSSL */
83 * Startup all the networking stuff...
86 cupsdStartListening();
91 * Create a pipe for CGI processes...
94 if (cupsdOpenPipe(CGIPipes
))
95 cupsdLogMessage(CUPSD_LOG_ERROR
,
96 "cupsdStartServer: Unable to create pipes for CGI status!");
99 CGIStatusBuffer
= cupsdStatBufNew(CGIPipes
[0], "[CGI]");
101 cupsdAddSelect(CGIPipes
[0], (cupsd_selfunc_t
)cupsdUpdateCGI
, NULL
, NULL
);
105 * Mark that the server has started and printers and jobs may be changed...
108 LastEvent
= CUPSD_EVENT_PRINTER_CHANGED
| CUPSD_EVENT_JOB_STATE_CHANGED
|
109 CUPSD_EVENT_SERVER_STARTED
;
116 * 'cupsdStopServer()' - Stop the server.
120 cupsdStopServer(void)
126 * Close all network clients and stop all jobs...
129 cupsdCloseAllClients();
130 cupsdStopListening();
133 cupsdStopAllNotifiers();
134 cupsdSaveRemoteCache();
135 cupsdDeleteAllCerts();
139 cupsArrayDelete(Clients
);
144 * Close the pipe for CGI processes...
147 if (CGIPipes
[0] >= 0)
149 cupsdRemoveSelect(CGIPipes
[0]);
151 cupsdStatBufDelete(CGIStatusBuffer
);
159 * Close all log files...
162 if (AccessFile
!= NULL
)
164 cupsFileClose(AccessFile
);
169 if (ErrorFile
!= NULL
)
171 cupsFileClose(ErrorFile
);
176 if (PageFile
!= NULL
)
178 cupsFileClose(PageFile
);
183 #ifdef HAVE_NOTIFY_POST
185 * Send one last notification as the server shuts down.
188 cupsdLogMessage(CUPSD_LOG_DEBUG
,
189 "notify_post(\"com.apple.printerListChange\") last");
190 notify_post("com.apple.printerListChange");
191 #endif /* HAVE_NOTIFY_POST */
198 * End of "$Id: server.c 6649 2007-07-11 21:46:42Z mike $".