]> git.ipfire.org Git - thirdparty/cups.git/blame - scheduler/server.c
License change: Apache License, Version 2.0.
[thirdparty/cups.git] / scheduler / server.c
CommitLineData
ef416fc2 1/*
503b54c9 2 * Server start/stop routines for the CUPS scheduler.
ef416fc2 3 *
e4e37194 4 * Copyright 2007-2017 by Apple Inc.
503b54c9 5 * Copyright 1997-2006 by Easy Software Products, all rights reserved.
ef416fc2 6 *
e3101897 7 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
ef416fc2 8 */
9
10/*
11 * Include necessary headers...
12 */
13
14#include <cups/http-private.h>
15#include "cupsd.h"
16#include <grp.h>
fa73b229 17#ifdef HAVE_NOTIFY_H
18# include <notify.h>
19#endif /* HAVE_NOTIFY_H */
ef416fc2 20
21
22/*
23 * Local globals...
24 */
25
84315f46 26static int started = 0; /* Did we start the server already? */
ef416fc2 27
28
29/*
30 * 'cupsdStartServer()' - Start the server.
31 */
32
33void
34cupsdStartServer(void)
35{
a29fd7dd
MS
36 /*
37 * Start color management (as needed)...
38 */
39
40 cupsdStartColor();
41
a4924f6c
MS
42 /*
43 * Create the default security profile...
44 */
45
8fe0183a 46 DefaultProfile = cupsdCreateProfile(0, 1);
a4924f6c 47
ef416fc2 48 /*
49 * Startup all the networking stuff...
50 */
51
52 cupsdStartListening();
53 cupsdStartBrowsing();
ef416fc2 54
55 /*
56 * Create a pipe for CGI processes...
57 */
58
59 if (cupsdOpenPipe(CGIPipes))
60 cupsdLogMessage(CUPSD_LOG_ERROR,
61 "cupsdStartServer: Unable to create pipes for CGI status!");
62 else
63 {
64 CGIStatusBuffer = cupsdStatBufNew(CGIPipes[0], "[CGI]");
65
f7deaa1a 66 cupsdAddSelect(CGIPipes[0], (cupsd_selfunc_t)cupsdUpdateCGI, NULL, NULL);
ef416fc2 67 }
68
fa73b229 69 /*
70 * Mark that the server has started and printers and jobs may be changed...
71 */
72
49d87452
MS
73 LastEvent = CUPSD_EVENT_PRINTER_CHANGED | CUPSD_EVENT_JOB_STATE_CHANGED |
74 CUPSD_EVENT_SERVER_STARTED;
75 started = 1;
fa73b229 76
e4e37194 77 cupsdSetBusyState(0);
ef416fc2 78}
79
80
81/*
82 * 'cupsdStopServer()' - Stop the server.
83 */
84
85void
86cupsdStopServer(void)
87{
88 if (!started)
89 return;
90
91 /*
a29fd7dd
MS
92 * Stop color management (as needed)...
93 */
94
95 cupsdStopColor();
96
97 /*
98 * Close all network clients...
ef416fc2 99 */
100
101 cupsdCloseAllClients();
102 cupsdStopListening();
ef416fc2 103 cupsdStopBrowsing();
104 cupsdStopAllNotifiers();
e1d6a774 105 cupsdDeleteAllCerts();
ef416fc2 106
a74454a7 107 if (Clients)
ef416fc2 108 {
a74454a7 109 cupsArrayDelete(Clients);
ef416fc2 110 Clients = NULL;
111 }
112
ef416fc2 113 /*
114 * Close the pipe for CGI processes...
115 */
116
117 if (CGIPipes[0] >= 0)
118 {
f7deaa1a 119 cupsdRemoveSelect(CGIPipes[0]);
ef416fc2 120
121 cupsdStatBufDelete(CGIStatusBuffer);
122 close(CGIPipes[1]);
123
124 CGIPipes[0] = -1;
125 CGIPipes[1] = -1;
126 }
127
128 /*
129 * Close all log files...
130 */
131
132 if (AccessFile != NULL)
133 {
a1797929
MS
134 if (AccessFile != LogStderr)
135 cupsFileClose(AccessFile);
ef416fc2 136
137 AccessFile = NULL;
138 }
139
140 if (ErrorFile != NULL)
141 {
a1797929
MS
142 if (ErrorFile != LogStderr)
143 cupsFileClose(ErrorFile);
ef416fc2 144
145 ErrorFile = NULL;
146 }
147
148 if (PageFile != NULL)
149 {
a1797929
MS
150 if (PageFile != LogStderr)
151 cupsFileClose(PageFile);
ef416fc2 152
153 PageFile = NULL;
154 }
155
fa73b229 156 /*
a4924f6c 157 * Delete the default security profile...
fa73b229 158 */
159
a4924f6c
MS
160 cupsdDestroyProfile(DefaultProfile);
161 DefaultProfile = NULL;
fa73b229 162
3dfe78b3
MS
163 /*
164 * Write out any dirty files...
165 */
166
167 if (DirtyFiles)
168 cupsdCleanDirty();
169
ef416fc2 170 started = 0;
171}