]> git.ipfire.org Git - thirdparty/cups.git/blame - scheduler/server.c
Fix build errors on Linux for new journald logging.
[thirdparty/cups.git] / scheduler / server.c
CommitLineData
ef416fc2 1/*
f2d18633 2 * "$Id$"
ef416fc2 3 *
6d2f911b 4 * Server start/stop routines for the CUPS scheduler.
ef416fc2 5 *
a29fd7dd 6 * Copyright 2007-2012 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{
a29fd7dd
MS
47 /*
48 * Start color management (as needed)...
49 */
50
51 cupsdStartColor();
52
a4924f6c
MS
53 /*
54 * Create the default security profile...
55 */
56
8fe0183a 57 DefaultProfile = cupsdCreateProfile(0, 1);
a4924f6c 58
ef416fc2 59 /*
60 * Startup all the networking stuff...
61 */
62
63 cupsdStartListening();
64 cupsdStartBrowsing();
ef416fc2 65
66 /*
67 * Create a pipe for CGI processes...
68 */
69
70 if (cupsdOpenPipe(CGIPipes))
71 cupsdLogMessage(CUPSD_LOG_ERROR,
72 "cupsdStartServer: Unable to create pipes for CGI status!");
73 else
74 {
75 CGIStatusBuffer = cupsdStatBufNew(CGIPipes[0], "[CGI]");
76
f7deaa1a 77 cupsdAddSelect(CGIPipes[0], (cupsd_selfunc_t)cupsdUpdateCGI, NULL, NULL);
ef416fc2 78 }
79
fa73b229 80 /*
81 * Mark that the server has started and printers and jobs may be changed...
82 */
83
49d87452
MS
84 LastEvent = CUPSD_EVENT_PRINTER_CHANGED | CUPSD_EVENT_JOB_STATE_CHANGED |
85 CUPSD_EVENT_SERVER_STARTED;
86 started = 1;
fa73b229 87
49d87452 88 cupsdSetBusyState();
ef416fc2 89}
90
91
92/*
93 * 'cupsdStopServer()' - Stop the server.
94 */
95
96void
97cupsdStopServer(void)
98{
99 if (!started)
100 return;
101
102 /*
a29fd7dd
MS
103 * Stop color management (as needed)...
104 */
105
106 cupsdStopColor();
107
108 /*
109 * Close all network clients...
ef416fc2 110 */
111
112 cupsdCloseAllClients();
113 cupsdStopListening();
ef416fc2 114 cupsdStopBrowsing();
115 cupsdStopAllNotifiers();
e1d6a774 116 cupsdDeleteAllCerts();
ef416fc2 117
a74454a7 118 if (Clients)
ef416fc2 119 {
a74454a7 120 cupsArrayDelete(Clients);
ef416fc2 121 Clients = NULL;
122 }
123
ef416fc2 124 /*
125 * Close the pipe for CGI processes...
126 */
127
128 if (CGIPipes[0] >= 0)
129 {
f7deaa1a 130 cupsdRemoveSelect(CGIPipes[0]);
ef416fc2 131
132 cupsdStatBufDelete(CGIStatusBuffer);
133 close(CGIPipes[1]);
134
135 CGIPipes[0] = -1;
136 CGIPipes[1] = -1;
137 }
138
139 /*
140 * Close all log files...
141 */
142
143 if (AccessFile != NULL)
144 {
a1797929
MS
145 if (AccessFile != LogStderr)
146 cupsFileClose(AccessFile);
ef416fc2 147
148 AccessFile = NULL;
149 }
150
151 if (ErrorFile != NULL)
152 {
a1797929
MS
153 if (ErrorFile != LogStderr)
154 cupsFileClose(ErrorFile);
ef416fc2 155
156 ErrorFile = NULL;
157 }
158
159 if (PageFile != NULL)
160 {
a1797929
MS
161 if (PageFile != LogStderr)
162 cupsFileClose(PageFile);
ef416fc2 163
164 PageFile = NULL;
165 }
166
fa73b229 167 /*
a4924f6c 168 * Delete the default security profile...
fa73b229 169 */
170
a4924f6c
MS
171 cupsdDestroyProfile(DefaultProfile);
172 DefaultProfile = NULL;
fa73b229 173
3dfe78b3
MS
174 /*
175 * Write out any dirty files...
176 */
177
178 if (DirtyFiles)
179 cupsdCleanDirty();
180
ef416fc2 181 started = 0;
182}
183
184
185/*
f2d18633 186 * End of "$Id$".
ef416fc2 187 */