]> git.ipfire.org Git - thirdparty/cups.git/blame - scheduler/server.c
Merge changes from CUPS 1.5svn-r9641
[thirdparty/cups.git] / scheduler / server.c
CommitLineData
ef416fc2 1/*
b19ccc9e 2 * "$Id: server.c 7927 2008-09-10 22:05:29Z mike $"
ef416fc2 3 *
6d2f911b 4 * Server start/stop routines for the CUPS scheduler.
ef416fc2 5 *
6d2f911b 6 * Copyright 2007-2010 by Apple Inc.
bd7854cb 7 * Copyright 1997-2006 by Easy Software Products, all rights reserved.
ef416fc2 8 *
9 * These coded instructions, statements, and computer programs are the
bc44d920 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/".
ef416fc2 14 *
15 * Contents:
16 *
17 * cupsdStartServer() - Start the server.
18 * cupsdStopServer() - Stop the server.
19 */
20
21/*
22 * Include necessary headers...
23 */
24
25#include <cups/http-private.h>
26#include "cupsd.h"
27#include <grp.h>
fa73b229 28#ifdef HAVE_NOTIFY_H
29# include <notify.h>
30#endif /* HAVE_NOTIFY_H */
ef416fc2 31
32
33/*
34 * Local globals...
35 */
36
84315f46 37static int started = 0; /* Did we start the server already? */
ef416fc2 38
39
40/*
41 * 'cupsdStartServer()' - Start the server.
42 */
43
44void
45cupsdStartServer(void)
46{
a4924f6c
MS
47 /*
48 * Create the default security profile...
49 */
50
51 DefaultProfile = cupsdCreateProfile(0);
52
ef416fc2 53 /*
54 * Startup all the networking stuff...
55 */
56
57 cupsdStartListening();
58 cupsdStartBrowsing();
59 cupsdStartPolling();
60
61 /*
62 * Create a pipe for CGI processes...
63 */
64
65 if (cupsdOpenPipe(CGIPipes))
66 cupsdLogMessage(CUPSD_LOG_ERROR,
67 "cupsdStartServer: Unable to create pipes for CGI status!");
68 else
69 {
70 CGIStatusBuffer = cupsdStatBufNew(CGIPipes[0], "[CGI]");
71
f7deaa1a 72 cupsdAddSelect(CGIPipes[0], (cupsd_selfunc_t)cupsdUpdateCGI, NULL, NULL);
ef416fc2 73 }
74
fa73b229 75 /*
76 * Mark that the server has started and printers and jobs may be changed...
77 */
78
49d87452
MS
79 LastEvent = CUPSD_EVENT_PRINTER_CHANGED | CUPSD_EVENT_JOB_STATE_CHANGED |
80 CUPSD_EVENT_SERVER_STARTED;
81 started = 1;
fa73b229 82
49d87452 83 cupsdSetBusyState();
ef416fc2 84}
85
86
87/*
88 * 'cupsdStopServer()' - Stop the server.
89 */
90
91void
92cupsdStopServer(void)
93{
94 if (!started)
95 return;
96
97 /*
98 * Close all network clients and stop all jobs...
99 */
100
101 cupsdCloseAllClients();
102 cupsdStopListening();
103 cupsdStopPolling();
104 cupsdStopBrowsing();
105 cupsdStopAllNotifiers();
e1d6a774 106 cupsdDeleteAllCerts();
ef416fc2 107
a74454a7 108 if (Clients)
ef416fc2 109 {
a74454a7 110 cupsArrayDelete(Clients);
ef416fc2 111 Clients = NULL;
112 }
113
ef416fc2 114 /*
115 * Close the pipe for CGI processes...
116 */
117
118 if (CGIPipes[0] >= 0)
119 {
f7deaa1a 120 cupsdRemoveSelect(CGIPipes[0]);
ef416fc2 121
122 cupsdStatBufDelete(CGIStatusBuffer);
123 close(CGIPipes[1]);
124
125 CGIPipes[0] = -1;
126 CGIPipes[1] = -1;
127 }
128
a4924f6c
MS
129#ifdef HAVE_NOTIFY_POST
130 /*
131 * Send one last notification as the server shuts down.
132 */
133
e60ec91f 134 cupsdLogMessage(CUPSD_LOG_DEBUG2,
a4924f6c
MS
135 "notify_post(\"com.apple.printerListChange\") last");
136 notify_post("com.apple.printerListChange");
137#endif /* HAVE_NOTIFY_POST */
138
ef416fc2 139 /*
140 * Close all log files...
141 */
142
143 if (AccessFile != NULL)
144 {
145 cupsFileClose(AccessFile);
146
147 AccessFile = NULL;
148 }
149
150 if (ErrorFile != NULL)
151 {
152 cupsFileClose(ErrorFile);
153
154 ErrorFile = NULL;
155 }
156
157 if (PageFile != NULL)
158 {
159 cupsFileClose(PageFile);
160
161 PageFile = NULL;
162 }
163
fa73b229 164 /*
a4924f6c 165 * Delete the default security profile...
fa73b229 166 */
167
a4924f6c
MS
168 cupsdDestroyProfile(DefaultProfile);
169 DefaultProfile = NULL;
fa73b229 170
3dfe78b3
MS
171 /*
172 * Write out any dirty files...
173 */
174
175 if (DirtyFiles)
176 cupsdCleanDirty();
177
ef416fc2 178 started = 0;
179}
180
181
182/*
b19ccc9e 183 * End of "$Id: server.c 7927 2008-09-10 22:05:29Z mike $".
ef416fc2 184 */