2 * "$Id: server.c 5095 2006-02-09 16:22:48Z mike $"
4 * Server start/stop routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 by Easy Software Products, all rights reserved.
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
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * cupsdStartServer() - Start the server.
27 * cupsdStopServer() - Stop the server.
31 * Include necessary headers...
34 #include <cups/http-private.h>
39 #endif /* HAVE_NOTIFY_H */
46 static int started
= 0;
50 * 'cupsdStartServer()' - Start the server.
54 cupsdStartServer(void)
57 int i
; /* Looping var */
58 struct timeval curtime
; /* Current time in microseconds */
59 unsigned char data
[1024]; /* Seed data */
60 #endif /* HAVE_LIBSSL */
65 * Initialize the encryption libraries...
69 SSL_load_error_strings();
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...)
76 gettimeofday(&curtime
, NULL
);
77 srand(curtime
.tv_sec
+ curtime
.tv_usec
);
79 for (i
= 0; i
< sizeof(data
); i
++)
80 data
[i
] = rand(); /* Yes, this is a poor source of random data... */
82 RAND_seed(&data
, sizeof(data
));
83 #elif defined(HAVE_GNUTLS)
85 * Initialize the encryption libraries...
89 #endif /* HAVE_LIBSSL */
92 * Startup all the networking stuff...
95 cupsdStartListening();
100 * Create a pipe for CGI processes...
103 if (cupsdOpenPipe(CGIPipes
))
104 cupsdLogMessage(CUPSD_LOG_ERROR
,
105 "cupsdStartServer: Unable to create pipes for CGI status!");
108 CGIStatusBuffer
= cupsdStatBufNew(CGIPipes
[0], "[CGI]");
110 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
111 "cupsdStartServer: Adding fd %d to InputSet...",
113 FD_SET(CGIPipes
[0], InputSet
);
117 * Mark that the server has started and printers and jobs may be changed...
120 LastEvent
= CUPSD_EVENT_PRINTER_CHANGED
| CUPSD_EVENT_JOB_STATE_CHANGED
|
121 CUPSD_EVENT_SERVER_STARTED
;
129 * 'cupsdStopServer()' - Stop the server.
133 cupsdStopServer(void)
139 * Close all network clients and stop all jobs...
142 cupsdCloseAllClients();
143 cupsdStopListening();
146 cupsdStopAllNotifiers();
147 cupsdSaveRemoteCache();
155 #if defined(HAVE_SSL) && defined(HAVE_CDSASSL)
157 * Free all of the certificates...
160 if (ServerCertificatesArray
)
162 CFRelease(ServerCertificatesArray
);
163 ServerCertificatesArray
= NULL
;
165 #endif /* HAVE_SSL && HAVE_CDSASSL */
168 * Close the pipe for CGI processes...
171 if (CGIPipes
[0] >= 0)
173 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
174 "cupsdStopServer: Removing fd %d from InputSet...",
177 FD_CLR(CGIPipes
[0], InputSet
);
179 cupsdStatBufDelete(CGIStatusBuffer
);
187 * Close all log files...
190 if (AccessFile
!= NULL
)
192 cupsFileClose(AccessFile
);
197 if (ErrorFile
!= NULL
)
199 cupsFileClose(ErrorFile
);
204 if (PageFile
!= NULL
)
206 cupsFileClose(PageFile
);
211 #ifdef HAVE_NOTIFY_POST
213 * Send one last notification as the server shuts down.
216 cupsdLogMessage(CUPSD_LOG_DEBUG
,
217 "notify_post(\"com.apple.printerListChange\") last");
218 notify_post("com.apple.printerListChange");
219 #endif /* HAVE_NOTIFY_POST */
226 * End of "$Id: server.c 5095 2006-02-09 16:22:48Z mike $".