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