Gentoo Archives: gentoo-commits

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