2 * "$Id: server.c 7927 2008-09-10 22:05:29Z mike $"
4 * Server start/stop routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2008 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 * Create the default security profile...
86 DefaultProfile
= cupsdCreateProfile(0);
89 * Startup all the networking stuff...
92 cupsdStartListening();
97 * Create a pipe for CGI processes...
100 if (cupsdOpenPipe(CGIPipes
))
101 cupsdLogMessage(CUPSD_LOG_ERROR
,
102 "cupsdStartServer: Unable to create pipes for CGI status!");
105 CGIStatusBuffer
= cupsdStatBufNew(CGIPipes
[0], "[CGI]");
107 cupsdAddSelect(CGIPipes
[0], (cupsd_selfunc_t
)cupsdUpdateCGI
, NULL
, NULL
);
111 * Mark that the server has started and printers and jobs may be changed...
114 LastEvent
= CUPSD_EVENT_PRINTER_CHANGED
| CUPSD_EVENT_JOB_STATE_CHANGED
|
115 CUPSD_EVENT_SERVER_STARTED
;
123 * 'cupsdStopServer()' - Stop the server.
127 cupsdStopServer(void)
133 * Close all network clients and stop all jobs...
136 cupsdCloseAllClients();
137 cupsdStopListening();
140 cupsdStopAllNotifiers();
141 cupsdDeleteAllCerts();
145 cupsArrayDelete(Clients
);
150 * Close the pipe for CGI processes...
153 if (CGIPipes
[0] >= 0)
155 cupsdRemoveSelect(CGIPipes
[0]);
157 cupsdStatBufDelete(CGIStatusBuffer
);
164 #ifdef HAVE_NOTIFY_POST
166 * Send one last notification as the server shuts down.
169 cupsdLogMessage(CUPSD_LOG_DEBUG
,
170 "notify_post(\"com.apple.printerListChange\") last");
171 notify_post("com.apple.printerListChange");
172 #endif /* HAVE_NOTIFY_POST */
175 * Close all log files...
178 if (AccessFile
!= NULL
)
180 cupsFileClose(AccessFile
);
185 if (ErrorFile
!= NULL
)
187 cupsFileClose(ErrorFile
);
192 if (PageFile
!= NULL
)
194 cupsFileClose(PageFile
);
200 * Delete the default security profile...
203 cupsdDestroyProfile(DefaultProfile
);
204 DefaultProfile
= NULL
;
207 * Write out any dirty files...
218 * End of "$Id: server.c 7927 2008-09-10 22:05:29Z mike $".