]>
Commit | Line | Data |
---|---|---|
f2552845 AM |
1 | diff -up cups-1.7.2/config.h.in.systemd-socket cups-1.7.2/config.h.in |
2 | --- cups-1.7.2/config.h.in.systemd-socket 2014-02-27 16:57:59.000000000 +0100 | |
3 | +++ cups-1.7.2/config.h.in 2014-04-17 14:05:04.104472016 +0200 | |
3e1538e5 | 4 | @@ -451,6 +451,13 @@ |
304fa3b3 JR |
5 | |
6 | ||
7 | /* | |
8 | + * Do we have systemd support? | |
9 | + */ | |
10 | + | |
11 | +#undef HAVE_SYSTEMD | |
12 | + | |
13 | + | |
14 | +/* | |
15 | * Various scripting languages... | |
16 | */ | |
17 | ||
f2552845 AM |
18 | diff -up cups-1.7.2/config-scripts/cups-systemd.m4.systemd-socket cups-1.7.2/config-scripts/cups-systemd.m4 |
19 | --- cups-1.7.2/config-scripts/cups-systemd.m4.systemd-socket 2014-04-17 14:05:04.104472016 +0200 | |
20 | +++ cups-1.7.2/config-scripts/cups-systemd.m4 2014-04-17 14:05:04.104472016 +0200 | |
304fa3b3 JR |
21 | @@ -0,0 +1,36 @@ |
22 | +dnl | |
23 | +dnl "$Id$" | |
24 | +dnl | |
25 | +dnl systemd stuff for CUPS. | |
26 | + | |
27 | +dnl Find whether systemd is available | |
28 | + | |
29 | +SDLIBS="" | |
30 | +AC_ARG_WITH([systemdsystemunitdir], | |
31 | + AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files]), | |
32 | + [], [with_systemdsystemunitdir=$($PKGCONFIG --variable=systemdsystemunitdir systemd)]) | |
33 | +if test "x$with_systemdsystemunitdir" != xno; then | |
34 | + AC_MSG_CHECKING(for libsystemd-daemon) | |
35 | + if $PKGCONFIG --exists libsystemd-daemon; then | |
36 | + AC_MSG_RESULT(yes) | |
37 | + SDCFLAGS=`$PKGCONFIG --cflags libsystemd-daemon` | |
38 | + SDLIBS=`$PKGCONFIG --libs libsystemd-daemon` | |
39 | + AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir]) | |
40 | + AC_DEFINE(HAVE_SYSTEMD) | |
41 | + else | |
42 | + AC_MSG_RESULT(no) | |
43 | + fi | |
44 | +fi | |
45 | + | |
46 | +if test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno ; then | |
47 | + SYSTEMD_UNITS="cups.service cups.socket cups.path" | |
48 | +else | |
49 | + SYSTEMD_UNITS="" | |
50 | +fi | |
51 | + | |
52 | +AC_SUBST(SYSTEMD_UNITS) | |
53 | +AC_SUBST(SDLIBS) | |
54 | + | |
55 | +dnl | |
56 | +dnl "$Id$" | |
57 | +dnl | |
f2552845 AM |
58 | diff -up cups-1.7.2/configure.in.systemd-socket cups-1.7.2/configure.in |
59 | --- cups-1.7.2/configure.in.systemd-socket 2013-07-08 23:15:13.000000000 +0200 | |
60 | +++ cups-1.7.2/configure.in 2014-04-17 14:05:04.104472016 +0200 | |
3e1538e5 | 61 | @@ -33,6 +33,7 @@ sinclude(config-scripts/cups-pam.m4) |
304fa3b3 JR |
62 | sinclude(config-scripts/cups-largefile.m4) |
63 | sinclude(config-scripts/cups-dnssd.m4) | |
64 | sinclude(config-scripts/cups-launchd.m4) | |
65 | +sinclude(config-scripts/cups-systemd.m4) | |
66 | sinclude(config-scripts/cups-defaults.m4) | |
304fa3b3 | 67 | sinclude(config-scripts/cups-scripting.m4) |
3e1538e5 JR |
68 | |
69 | @@ -67,6 +68,9 @@ AC_OUTPUT(Makedefs | |
304fa3b3 JR |
70 | conf/snmp.conf |
71 | cups-config | |
72 | data/testprint | |
3e1538e5 JR |
73 | + data/cups.service |
74 | + data/cups.socket | |
75 | + data/cups.path | |
304fa3b3 | 76 | desktop/cups.desktop |
3e1538e5 | 77 | doc/help/ref-cups-files-conf.html |
304fa3b3 | 78 | doc/help/ref-cupsd-conf.html |
f2552845 AM |
79 | diff -up cups-1.7.2/cups/usersys.c.systemd-socket cups-1.7.2/cups/usersys.c |
80 | --- cups-1.7.2/cups/usersys.c.systemd-socket 2014-03-05 22:22:12.000000000 +0100 | |
81 | +++ cups-1.7.2/cups/usersys.c 2014-04-17 14:05:04.105472002 +0200 | |
82 | @@ -1050,7 +1050,7 @@ cups_read_client_conf( | |
304fa3b3 JR |
83 | struct stat sockinfo; /* Domain socket information */ |
84 | ||
85 | if (!stat(CUPS_DEFAULT_DOMAINSOCKET, &sockinfo) && | |
86 | - (sockinfo.st_mode & S_IRWXO) == S_IRWXO) | |
87 | + (sockinfo.st_mode & (S_IROTH | S_IWOTH)) == (S_IROTH | S_IWOTH)) | |
88 | cups_server = CUPS_DEFAULT_DOMAINSOCKET; | |
89 | else | |
90 | #endif /* CUPS_DEFAULT_DOMAINSOCKET */ | |
f2552845 AM |
91 | diff -up cups-1.7.2/data/cups.path.in.systemd-socket cups-1.7.2/data/cups.path.in |
92 | --- cups-1.7.2/data/cups.path.in.systemd-socket 2014-04-17 14:05:04.105472002 +0200 | |
93 | +++ cups-1.7.2/data/cups.path.in 2014-04-17 14:05:04.105472002 +0200 | |
304fa3b3 JR |
94 | @@ -0,0 +1,8 @@ |
95 | +[Unit] | |
96 | +Description=CUPS Printer Service Spool | |
97 | + | |
98 | +[Path] | |
99 | +PathExistsGlob=@CUPS_REQUESTS@/d* | |
100 | + | |
101 | +[Install] | |
102 | +WantedBy=multi-user.target | |
f2552845 AM |
103 | diff -up cups-1.7.2/data/cups.service.in.systemd-socket cups-1.7.2/data/cups.service.in |
104 | --- cups-1.7.2/data/cups.service.in.systemd-socket 2014-04-17 14:05:04.105472002 +0200 | |
105 | +++ cups-1.7.2/data/cups.service.in 2014-04-17 14:05:04.105472002 +0200 | |
106 | @@ -0,0 +1,11 @@ | |
304fa3b3 JR |
107 | +[Unit] |
108 | +Description=CUPS Printing Service | |
109 | + | |
110 | +[Service] | |
f2552845 | 111 | +Type=notify |
304fa3b3 JR |
112 | +ExecStart=@sbindir@/cupsd -f |
113 | +PrivateTmp=true | |
114 | + | |
115 | +[Install] | |
116 | +Also=cups.socket cups.path | |
117 | +WantedBy=printer.target | |
f2552845 AM |
118 | diff -up cups-1.7.2/data/cups.socket.in.systemd-socket cups-1.7.2/data/cups.socket.in |
119 | --- cups-1.7.2/data/cups.socket.in.systemd-socket 2014-04-17 14:05:04.105472002 +0200 | |
120 | +++ cups-1.7.2/data/cups.socket.in 2014-04-17 14:05:04.105472002 +0200 | |
3e1538e5 | 121 | @@ -0,0 +1,8 @@ |
304fa3b3 JR |
122 | +[Unit] |
123 | +Description=CUPS Printing Service Sockets | |
124 | + | |
125 | +[Socket] | |
126 | +ListenStream=@CUPS_DEFAULT_DOMAINSOCKET@ | |
304fa3b3 JR |
127 | + |
128 | +[Install] | |
129 | +WantedBy=sockets.target | |
f2552845 AM |
130 | diff -up cups-1.7.2/data/Makefile.systemd-socket cups-1.7.2/data/Makefile |
131 | --- cups-1.7.2/data/Makefile.systemd-socket 2013-05-29 13:51:34.000000000 +0200 | |
132 | +++ cups-1.7.2/data/Makefile 2014-04-17 14:05:04.106471988 +0200 | |
3e1538e5 | 133 | @@ -100,6 +100,12 @@ install-data: |
304fa3b3 JR |
134 | $(INSTALL_DATA) $$file $(DATADIR)/ppdc; \ |
135 | done | |
136 | $(INSTALL_DIR) -m 755 $(DATADIR)/profiles | |
137 | + if test "x$(SYSTEMD_UNITS)" != "x" ; then \ | |
138 | + $(INSTALL_DIR) -m 755 $(SYSTEMDUNITDIR); \ | |
139 | + for file in $(SYSTEMD_UNITS); do \ | |
140 | + $(INSTALL_DATA) $$file $(SYSTEMDUNITDIR); \ | |
141 | + done; \ | |
142 | + fi | |
143 | ||
144 | ||
145 | # | |
3e1538e5 JR |
146 | @@ -143,6 +149,9 @@ uninstall: |
147 | -$(RMDIR) $(DATADIR)/data | |
304fa3b3 JR |
148 | -$(RMDIR) $(DATADIR)/banners |
149 | -$(RMDIR) $(DATADIR) | |
150 | + for file in $(SYSTEMD_UNITS); do \ | |
151 | + $(RM) $(SYSTEMDUNITDIR)/$$file; \ | |
152 | + done | |
153 | ||
154 | ||
155 | # | |
f2552845 AM |
156 | diff -up cups-1.7.2/Makedefs.in.systemd-socket cups-1.7.2/Makedefs.in |
157 | --- cups-1.7.2/Makedefs.in.systemd-socket 2014-04-17 14:05:04.092472182 +0200 | |
158 | +++ cups-1.7.2/Makedefs.in 2014-04-17 14:05:04.106471988 +0200 | |
3e1538e5 | 159 | @@ -134,6 +134,7 @@ CXXFLAGS = @CPPFLAGS@ @CXXFLAGS@ |
304fa3b3 JR |
160 | CXXLIBS = @CXXLIBS@ |
161 | DBUS_NOTIFIER = @DBUS_NOTIFIER@ | |
162 | DBUS_NOTIFIERLIBS = @DBUS_NOTIFIERLIBS@ | |
163 | +SYSTEMD_UNITS = @SYSTEMD_UNITS@ | |
164 | DNSSD_BACKEND = @DNSSD_BACKEND@ | |
165 | DSOFLAGS = -L../cups @DSOFLAGS@ | |
166 | DSOLIBS = @DSOLIBS@ $(COMMONLIBS) | |
3e1538e5 JR |
167 | @@ -141,6 +142,7 @@ DNSSDLIBS = @DNSSDLIBS@ |
168 | IPPFIND_BIN = @IPPFIND_BIN@ | |
169 | IPPFIND_MAN = @IPPFIND_MAN@ | |
304fa3b3 JR |
170 | LAUNCHDLIBS = @LAUNCHDLIBS@ |
171 | +SDLIBS = @SDLIBS@ | |
172 | LDFLAGS = -L../cgi-bin -L../cups -L../filter -L../ppdc \ | |
173 | -L../scheduler @LDARCHFLAGS@ \ | |
174 | @LDFLAGS@ @RELROFLAGS@ @PIEFLAGS@ $(OPTIM) | |
f2552845 | 175 | @@ -232,6 +234,7 @@ PAMFILE = @PAMFILE@ |
304fa3b3 JR |
176 | |
177 | DEFAULT_LAUNCHD_CONF = @DEFAULT_LAUNCHD_CONF@ | |
178 | DBUSDIR = @DBUSDIR@ | |
179 | +SYSTEMDUNITDIR = $(BUILDROOT)@systemdsystemunitdir@ | |
180 | ||
181 | ||
182 | # | |
f2552845 AM |
183 | diff -up cups-1.7.2/scheduler/client.h.systemd-socket cups-1.7.2/scheduler/client.h |
184 | --- cups-1.7.2/scheduler/client.h.systemd-socket 2013-08-02 00:23:18.000000000 +0200 | |
185 | +++ cups-1.7.2/scheduler/client.h 2014-04-17 14:05:04.106471988 +0200 | |
186 | @@ -79,6 +79,9 @@ typedef struct | |
304fa3b3 JR |
187 | int fd; /* File descriptor for this server */ |
188 | http_addr_t address; /* Bind address of socket */ | |
189 | http_encryption_t encryption; /* To encrypt or not to encrypt... */ | |
190 | +#ifdef HAVE_SYSTEMD | |
191 | + int is_systemd; /* Is this a systemd socket? */ | |
192 | +#endif /* HAVE_SYSTEMD */ | |
193 | } cupsd_listener_t; | |
194 | ||
195 | ||
f2552845 AM |
196 | diff -up cups-1.7.2/scheduler/listen.c.systemd-socket cups-1.7.2/scheduler/listen.c |
197 | --- cups-1.7.2/scheduler/listen.c.systemd-socket 2013-05-29 13:51:34.000000000 +0200 | |
198 | +++ cups-1.7.2/scheduler/listen.c 2014-04-17 14:05:04.107471974 +0200 | |
304fa3b3 JR |
199 | @@ -401,7 +401,11 @@ cupsdStopListening(void) |
200 | lis; | |
201 | lis = (cupsd_listener_t *)cupsArrayNext(Listeners)) | |
202 | { | |
203 | - if (lis->fd != -1) | |
204 | + if (lis->fd != -1 | |
205 | +#ifdef HAVE_SYSTEMD | |
206 | + && !lis->is_systemd | |
207 | +#endif /* HAVE_SYSTEMD */ | |
208 | + ) | |
209 | { | |
210 | #ifdef WIN32 | |
211 | closesocket(lis->fd); | |
f2552845 AM |
212 | diff -up cups-1.7.2/scheduler/main.c.systemd-socket cups-1.7.2/scheduler/main.c |
213 | --- cups-1.7.2/scheduler/main.c.systemd-socket 2014-04-17 14:05:04.052472738 +0200 | |
214 | +++ cups-1.7.2/scheduler/main.c 2014-04-17 14:09:39.102634667 +0200 | |
215 | @@ -39,6 +39,10 @@ | |
304fa3b3 JR |
216 | # endif /* !LAUNCH_JOBKEY_SERVICEIPC */ |
217 | #endif /* HAVE_LAUNCH_H */ | |
218 | ||
219 | +#ifdef HAVE_SYSTEMD | |
220 | +#include <systemd/sd-daemon.h> | |
221 | +#endif /* HAVE_SYSTEMD */ | |
222 | + | |
223 | #if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO) | |
224 | # include <malloc.h> | |
225 | #endif /* HAVE_MALLOC_H && HAVE_MALLINFO */ | |
f2552845 | 226 | @@ -64,6 +68,9 @@ |
304fa3b3 JR |
227 | static void launchd_checkin(void); |
228 | static void launchd_checkout(void); | |
229 | #endif /* HAVE_LAUNCHD */ | |
230 | +#ifdef HAVE_SYSTEMD | |
231 | +static void systemd_checkin(void); | |
232 | +#endif /* HAVE_SYSTEMD */ | |
233 | static void parent_handler(int sig); | |
234 | static void process_children(void); | |
235 | static void sigchld_handler(int sig); | |
f2552845 | 236 | @@ -563,6 +570,13 @@ main(int argc, /* I - Number of comm |
304fa3b3 JR |
237 | } |
238 | #endif /* HAVE_LAUNCHD */ | |
239 | ||
240 | +#ifdef HAVE_SYSTEMD | |
241 | + /* | |
242 | + * If we were started by systemd get the listen sockets file descriptors... | |
243 | + */ | |
244 | + systemd_checkin(); | |
245 | +#endif /* HAVE_SYSTEMD */ | |
246 | + | |
247 | /* | |
248 | * Startup the server... | |
249 | */ | |
f2552845 AM |
250 | @@ -654,6 +668,12 @@ main(int argc, /* I - Number of comm |
251 | "Scheduler started via launchd."); | |
252 | else | |
253 | #endif /* HAVE_LAUNCHD */ | |
254 | +#ifdef HAVE_SYSTEMD | |
255 | + sd_notifyf(0, "READY=1\n" | |
256 | + "STATUS=Scheduler is running...\n" | |
257 | + "MAINPID=%lu", | |
258 | + (unsigned long) getpid()); | |
259 | +#endif /* HAVE_SYSTEMD */ | |
260 | if (fg) | |
261 | cupsdAddEvent(CUPSD_EVENT_SERVER_STARTED, NULL, NULL, | |
262 | "Scheduler started in foreground."); | |
263 | @@ -751,6 +771,15 @@ main(int argc, /* I - Number of comm | |
304fa3b3 JR |
264 | } |
265 | #endif /* HAVE_LAUNCHD */ | |
266 | ||
267 | +#ifdef HAVE_SYSTEMD | |
268 | + /* | |
269 | + * If we were started by systemd get the listen sockets file | |
270 | + * descriptors... | |
271 | + */ | |
272 | + | |
273 | + systemd_checkin(); | |
274 | +#endif /* HAVE_SYSTEMD */ | |
275 | + | |
276 | /* | |
277 | * Startup the server... | |
278 | */ | |
f2552845 | 279 | @@ -1500,6 +1529,102 @@ launchd_checkout(void) |
304fa3b3 JR |
280 | } |
281 | #endif /* HAVE_LAUNCHD */ | |
282 | ||
283 | +#ifdef HAVE_SYSTEMD | |
284 | +static void | |
285 | +systemd_checkin(void) | |
286 | +{ | |
287 | + int n, fd; | |
288 | + | |
289 | + n = sd_listen_fds(0); | |
290 | + if (n < 0) | |
291 | + { | |
292 | + cupsdLogMessage(CUPSD_LOG_ERROR, | |
293 | + "systemd_checkin: Failed to acquire sockets from systemd - %s", | |
294 | + strerror(-n)); | |
295 | + exit(EXIT_FAILURE); | |
296 | + return; | |
297 | + } | |
298 | + | |
299 | + if (n == 0) | |
300 | + return; | |
301 | + | |
302 | + for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd ++) | |
303 | + { | |
304 | + http_addr_t addr; | |
305 | + socklen_t addrlen = sizeof (addr); | |
306 | + int r; | |
307 | + cupsd_listener_t *lis; | |
308 | + char s[256]; | |
309 | + | |
310 | + r = sd_is_socket(fd, AF_UNSPEC, SOCK_STREAM, 1); | |
311 | + if (r < 0) | |
312 | + { | |
313 | + cupsdLogMessage(CUPSD_LOG_ERROR, | |
314 | + "systemd_checkin: Unable to verify socket type - %s", | |
315 | + strerror(-r)); | |
316 | + continue; | |
317 | + } | |
318 | + | |
319 | + if (!r) | |
320 | + { | |
321 | + cupsdLogMessage(CUPSD_LOG_ERROR, | |
304fa3b3 JR |
322 | + "systemd_checkin: Socket not of the right type"); |
323 | + continue; | |
324 | + } | |
325 | + | |
326 | + if (getsockname(fd, (struct sockaddr*) &addr, &addrlen)) | |
327 | + { | |
328 | + cupsdLogMessage(CUPSD_LOG_ERROR, | |
329 | + "systemd_checkin: Unable to get local address - %s", | |
330 | + strerror(errno)); | |
331 | + continue; | |
332 | + } | |
333 | + | |
334 | + /* | |
335 | + * Try to match the systemd socket address to one of the listeners... | |
336 | + */ | |
337 | + | |
338 | + for (lis = (cupsd_listener_t *)cupsArrayFirst(Listeners); | |
339 | + lis; | |
340 | + lis = (cupsd_listener_t *)cupsArrayNext(Listeners)) | |
341 | + if (httpAddrEqual(&lis->address, &addr)) | |
342 | + break; | |
343 | + | |
344 | + if (lis) | |
345 | + { | |
346 | + cupsdLogMessage(CUPSD_LOG_DEBUG, | |
347 | + "systemd_checkin: Matched existing listener %s with fd %d...", | |
348 | + httpAddrString(&(lis->address), s, sizeof(s)), fd); | |
349 | + } | |
350 | + else | |
351 | + { | |
352 | + cupsdLogMessage(CUPSD_LOG_DEBUG, | |
353 | + "systemd_checkin: Adding new listener %s with fd %d...", | |
354 | + httpAddrString(&addr, s, sizeof(s)), fd); | |
355 | + | |
356 | + if ((lis = calloc(1, sizeof(cupsd_listener_t))) == NULL) | |
357 | + { | |
358 | + cupsdLogMessage(CUPSD_LOG_ERROR, | |
359 | + "systemd_checkin: Unable to allocate listener - " | |
360 | + "%s.", strerror(errno)); | |
361 | + exit(EXIT_FAILURE); | |
362 | + } | |
363 | + | |
364 | + cupsArrayAdd(Listeners, lis); | |
365 | + | |
366 | + memcpy(&lis->address, &addr, sizeof(lis->address)); | |
367 | + } | |
368 | + | |
369 | + lis->fd = fd; | |
370 | + lis->is_systemd = 1; | |
371 | + | |
372 | +# ifdef HAVE_SSL | |
373 | + if (_httpAddrPort(&(lis->address)) == 443) | |
374 | + lis->encryption = HTTP_ENCRYPT_ALWAYS; | |
375 | +# endif /* HAVE_SSL */ | |
376 | + } | |
377 | +} | |
378 | +#endif /* HAVE_SYSTEMD */ | |
379 | ||
380 | /* | |
381 | * 'parent_handler()' - Catch USR1/CHLD signals... | |
f2552845 AM |
382 | diff -up cups-1.7.2/scheduler/Makefile.systemd-socket cups-1.7.2/scheduler/Makefile |
383 | --- cups-1.7.2/scheduler/Makefile.systemd-socket 2013-05-29 13:51:34.000000000 +0200 | |
384 | +++ cups-1.7.2/scheduler/Makefile 2014-04-17 14:05:04.108471960 +0200 | |
3e1538e5 | 385 | @@ -381,7 +381,7 @@ cupsd: $(CUPSDOBJS) $(LIBCUPSMIME) ../cu |
304fa3b3 JR |
386 | $(CC) $(LDFLAGS) -o cupsd $(CUPSDOBJS) -L. -lcupsmime \ |
387 | $(LIBZ) $(SSLLIBS) $(LIBSLP) $(LIBLDAP) $(PAMLIBS) \ | |
388 | $(LIBPAPER) $(LIBMALLOC) $(SERVERLIBS) $(DNSSDLIBS) $(LIBS) \ | |
389 | - $(LIBGSSAPI) $(LIBWRAP) | |
390 | + $(LIBGSSAPI) $(LIBWRAP) $(SDLIBS) | |
391 | ||
392 | cupsd-static: $(CUPSDOBJS) libcupsmime.a ../cups/$(LIBCUPSSTATIC) | |
393 | echo Linking $@... | |
3e1538e5 | 394 | @@ -389,7 +389,7 @@ cupsd-static: $(CUPSDOBJS) libcupsmime.a |
304fa3b3 JR |
395 | $(LIBZ) $(SSLLIBS) $(LIBSLP) $(LIBLDAP) $(PAMLIBS) \ |
396 | ../cups/$(LIBCUPSSTATIC) $(COMMONLIBS) $(LIBZ) $(LIBPAPER) \ | |
397 | $(LIBMALLOC) $(SERVERLIBS) $(DNSSDLIBS) $(LIBGSSAPI) \ | |
398 | - $(LIBWRAP) | |
3e1538e5 | 399 | + $(LIBWRAP) $(SDLIBS) |
304fa3b3 | 400 | |
3e1538e5 | 401 | tls.o: tls-darwin.c tls-gnutls.c tls-openssl.c |
304fa3b3 | 402 |