]> git.pld-linux.org Git - packages/cups.git/blame - cups-systemd-socket.patch
- up to 1.7.1
[packages/cups.git] / cups-systemd-socket.patch
CommitLineData
3e1538e5
JR
1diff -up cups-1.7rc1/config.h.in.systemd-socket cups-1.7rc1/config.h.in
2--- cups-1.7rc1/config.h.in.systemd-socket 2013-05-29 13:51:34.000000000 +0200
3+++ cups-1.7rc1/config.h.in 2013-07-12 11:16:53.257546263 +0200
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
3e1538e5
JR
18diff -up cups-1.7rc1/config-scripts/cups-systemd.m4.systemd-socket cups-1.7rc1/config-scripts/cups-systemd.m4
19--- cups-1.7rc1/config-scripts/cups-systemd.m4.systemd-socket 2013-07-12 11:16:53.257546263 +0200
20+++ cups-1.7rc1/config-scripts/cups-systemd.m4 2013-07-12 11:16:53.257546263 +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
3e1538e5
JR
58diff -up cups-1.7rc1/configure.in.systemd-socket cups-1.7rc1/configure.in
59--- cups-1.7rc1/configure.in.systemd-socket 2013-07-08 23:15:13.000000000 +0200
60+++ cups-1.7rc1/configure.in 2013-07-12 11:16:53.257546263 +0200
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
3e1538e5
JR
79diff -up cups-1.7rc1/cups/usersys.c.systemd-socket cups-1.7rc1/cups/usersys.c
80--- cups-1.7rc1/cups/usersys.c.systemd-socket 2013-07-10 16:08:39.000000000 +0200
81+++ cups-1.7rc1/cups/usersys.c 2013-07-12 11:16:53.258546249 +0200
82@@ -1046,7 +1046,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 */
3e1538e5
JR
91diff -up cups-1.7rc1/data/cups.path.in.systemd-socket cups-1.7rc1/data/cups.path.in
92--- cups-1.7rc1/data/cups.path.in.systemd-socket 2013-07-12 11:16:53.258546249 +0200
93+++ cups-1.7rc1/data/cups.path.in 2013-07-12 11:16:53.258546249 +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
3e1538e5
JR
103diff -up cups-1.7rc1/data/cups.service.in.systemd-socket cups-1.7rc1/data/cups.service.in
104--- cups-1.7rc1/data/cups.service.in.systemd-socket 2013-07-12 11:16:53.258546249 +0200
105+++ cups-1.7rc1/data/cups.service.in 2013-07-12 11:16:53.258546249 +0200
304fa3b3
JR
106@@ -0,0 +1,10 @@
107+[Unit]
108+Description=CUPS Printing Service
109+
110+[Service]
111+ExecStart=@sbindir@/cupsd -f
112+PrivateTmp=true
113+
114+[Install]
115+Also=cups.socket cups.path
116+WantedBy=printer.target
3e1538e5
JR
117diff -up cups-1.7rc1/data/cups.socket.in.systemd-socket cups-1.7rc1/data/cups.socket.in
118--- cups-1.7rc1/data/cups.socket.in.systemd-socket 2013-07-12 11:16:53.259546235 +0200
119+++ cups-1.7rc1/data/cups.socket.in 2013-07-12 11:16:53.259546235 +0200
120@@ -0,0 +1,8 @@
304fa3b3
JR
121+[Unit]
122+Description=CUPS Printing Service Sockets
123+
124+[Socket]
125+ListenStream=@CUPS_DEFAULT_DOMAINSOCKET@
304fa3b3
JR
126+
127+[Install]
128+WantedBy=sockets.target
3e1538e5
JR
129diff -up cups-1.7rc1/data/Makefile.systemd-socket cups-1.7rc1/data/Makefile
130--- cups-1.7rc1/data/Makefile.systemd-socket 2013-05-29 13:51:34.000000000 +0200
131+++ cups-1.7rc1/data/Makefile 2013-07-12 11:16:53.259546235 +0200
132@@ -100,6 +100,12 @@ install-data:
304fa3b3
JR
133 $(INSTALL_DATA) $$file $(DATADIR)/ppdc; \
134 done
135 $(INSTALL_DIR) -m 755 $(DATADIR)/profiles
136+ if test "x$(SYSTEMD_UNITS)" != "x" ; then \
137+ $(INSTALL_DIR) -m 755 $(SYSTEMDUNITDIR); \
138+ for file in $(SYSTEMD_UNITS); do \
139+ $(INSTALL_DATA) $$file $(SYSTEMDUNITDIR); \
140+ done; \
141+ fi
142
143
144 #
3e1538e5
JR
145@@ -143,6 +149,9 @@ uninstall:
146 -$(RMDIR) $(DATADIR)/data
304fa3b3
JR
147 -$(RMDIR) $(DATADIR)/banners
148 -$(RMDIR) $(DATADIR)
149+ for file in $(SYSTEMD_UNITS); do \
150+ $(RM) $(SYSTEMDUNITDIR)/$$file; \
151+ done
152
153
154 #
3e1538e5
JR
155diff -up cups-1.7rc1/Makedefs.in.systemd-socket cups-1.7rc1/Makedefs.in
156--- cups-1.7rc1/Makedefs.in.systemd-socket 2013-07-12 11:16:53.246546416 +0200
157+++ cups-1.7rc1/Makedefs.in 2013-07-12 11:17:49.327768742 +0200
158@@ -134,6 +134,7 @@ CXXFLAGS = @CPPFLAGS@ @CXXFLAGS@
304fa3b3
JR
159 CXXLIBS = @CXXLIBS@
160 DBUS_NOTIFIER = @DBUS_NOTIFIER@
161 DBUS_NOTIFIERLIBS = @DBUS_NOTIFIERLIBS@
162+SYSTEMD_UNITS = @SYSTEMD_UNITS@
163 DNSSD_BACKEND = @DNSSD_BACKEND@
164 DSOFLAGS = -L../cups @DSOFLAGS@
165 DSOLIBS = @DSOLIBS@ $(COMMONLIBS)
3e1538e5
JR
166@@ -141,6 +142,7 @@ DNSSDLIBS = @DNSSDLIBS@
167 IPPFIND_BIN = @IPPFIND_BIN@
168 IPPFIND_MAN = @IPPFIND_MAN@
304fa3b3
JR
169 LAUNCHDLIBS = @LAUNCHDLIBS@
170+SDLIBS = @SDLIBS@
171 LDFLAGS = -L../cgi-bin -L../cups -L../filter -L../ppdc \
172 -L../scheduler @LDARCHFLAGS@ \
173 @LDFLAGS@ @RELROFLAGS@ @PIEFLAGS@ $(OPTIM)
3e1538e5 174@@ -231,6 +233,7 @@ PAMFILE = @PAMFILE@
304fa3b3
JR
175
176 DEFAULT_LAUNCHD_CONF = @DEFAULT_LAUNCHD_CONF@
177 DBUSDIR = @DBUSDIR@
178+SYSTEMDUNITDIR = $(BUILDROOT)@systemdsystemunitdir@
179
180
181 #
3e1538e5
JR
182diff -up cups-1.7rc1/scheduler/client.h.systemd-socket cups-1.7rc1/scheduler/client.h
183--- cups-1.7rc1/scheduler/client.h.systemd-socket 2013-05-29 13:51:34.000000000 +0200
184+++ cups-1.7rc1/scheduler/client.h 2013-07-12 11:16:53.260546222 +0200
185@@ -77,6 +77,9 @@ typedef struct
304fa3b3
JR
186 int fd; /* File descriptor for this server */
187 http_addr_t address; /* Bind address of socket */
188 http_encryption_t encryption; /* To encrypt or not to encrypt... */
189+#ifdef HAVE_SYSTEMD
190+ int is_systemd; /* Is this a systemd socket? */
191+#endif /* HAVE_SYSTEMD */
192 } cupsd_listener_t;
193
194
3e1538e5
JR
195diff -up cups-1.7rc1/scheduler/listen.c.systemd-socket cups-1.7rc1/scheduler/listen.c
196--- cups-1.7rc1/scheduler/listen.c.systemd-socket 2013-05-29 13:51:34.000000000 +0200
197+++ cups-1.7rc1/scheduler/listen.c 2013-07-12 11:16:53.260546222 +0200
304fa3b3
JR
198@@ -401,7 +401,11 @@ cupsdStopListening(void)
199 lis;
200 lis = (cupsd_listener_t *)cupsArrayNext(Listeners))
201 {
202- if (lis->fd != -1)
203+ if (lis->fd != -1
204+#ifdef HAVE_SYSTEMD
205+ && !lis->is_systemd
206+#endif /* HAVE_SYSTEMD */
207+ )
208 {
209 #ifdef WIN32
210 closesocket(lis->fd);
3e1538e5
JR
211diff -up cups-1.7rc1/scheduler/main.c.systemd-socket cups-1.7rc1/scheduler/main.c
212--- cups-1.7rc1/scheduler/main.c.systemd-socket 2013-07-12 11:16:53.212546887 +0200
213+++ cups-1.7rc1/scheduler/main.c 2013-07-12 11:16:53.261546208 +0200
304fa3b3
JR
214@@ -26,6 +26,8 @@
215 * launchd_checkin() - Check-in with launchd and collect the listening
216 * fds.
217 * launchd_checkout() - Update the launchd KeepAlive file as needed.
218+ * systemd_checkin() - Check-in with systemd and collect the
219+ * listening fds.
220 * parent_handler() - Catch USR1/CHLD signals...
221 * process_children() - Process all dead children...
222 * select_timeout() - Calculate the select timeout value.
223@@ -62,6 +64,10 @@
224 # endif /* !LAUNCH_JOBKEY_SERVICEIPC */
225 #endif /* HAVE_LAUNCH_H */
226
227+#ifdef HAVE_SYSTEMD
228+#include <systemd/sd-daemon.h>
229+#endif /* HAVE_SYSTEMD */
230+
231 #if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
232 # include <malloc.h>
233 #endif /* HAVE_MALLOC_H && HAVE_MALLINFO */
3e1538e5 234@@ -83,6 +89,9 @@
304fa3b3
JR
235 static void launchd_checkin(void);
236 static void launchd_checkout(void);
237 #endif /* HAVE_LAUNCHD */
238+#ifdef HAVE_SYSTEMD
239+static void systemd_checkin(void);
240+#endif /* HAVE_SYSTEMD */
241 static void parent_handler(int sig);
242 static void process_children(void);
243 static void sigchld_handler(int sig);
3e1538e5 244@@ -574,6 +583,13 @@ main(int argc, /* I - Number of comm
304fa3b3
JR
245 }
246 #endif /* HAVE_LAUNCHD */
247
248+#ifdef HAVE_SYSTEMD
249+ /*
250+ * If we were started by systemd get the listen sockets file descriptors...
251+ */
252+ systemd_checkin();
253+#endif /* HAVE_SYSTEMD */
254+
255 /*
256 * Startup the server...
257 */
3e1538e5 258@@ -762,6 +778,15 @@ main(int argc, /* I - Number of comm
304fa3b3
JR
259 }
260 #endif /* HAVE_LAUNCHD */
261
262+#ifdef HAVE_SYSTEMD
263+ /*
264+ * If we were started by systemd get the listen sockets file
265+ * descriptors...
266+ */
267+
268+ systemd_checkin();
269+#endif /* HAVE_SYSTEMD */
270+
271 /*
272 * Startup the server...
273 */
3e1538e5 274@@ -1511,6 +1536,102 @@ launchd_checkout(void)
304fa3b3
JR
275 }
276 #endif /* HAVE_LAUNCHD */
277
278+#ifdef HAVE_SYSTEMD
279+static void
280+systemd_checkin(void)
281+{
282+ int n, fd;
283+
284+ n = sd_listen_fds(0);
285+ if (n < 0)
286+ {
287+ cupsdLogMessage(CUPSD_LOG_ERROR,
288+ "systemd_checkin: Failed to acquire sockets from systemd - %s",
289+ strerror(-n));
290+ exit(EXIT_FAILURE);
291+ return;
292+ }
293+
294+ if (n == 0)
295+ return;
296+
297+ for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd ++)
298+ {
299+ http_addr_t addr;
300+ socklen_t addrlen = sizeof (addr);
301+ int r;
302+ cupsd_listener_t *lis;
303+ char s[256];
304+
305+ r = sd_is_socket(fd, AF_UNSPEC, SOCK_STREAM, 1);
306+ if (r < 0)
307+ {
308+ cupsdLogMessage(CUPSD_LOG_ERROR,
309+ "systemd_checkin: Unable to verify socket type - %s",
310+ strerror(-r));
311+ continue;
312+ }
313+
314+ if (!r)
315+ {
316+ cupsdLogMessage(CUPSD_LOG_ERROR,
304fa3b3
JR
317+ "systemd_checkin: Socket not of the right type");
318+ continue;
319+ }
320+
321+ if (getsockname(fd, (struct sockaddr*) &addr, &addrlen))
322+ {
323+ cupsdLogMessage(CUPSD_LOG_ERROR,
324+ "systemd_checkin: Unable to get local address - %s",
325+ strerror(errno));
326+ continue;
327+ }
328+
329+ /*
330+ * Try to match the systemd socket address to one of the listeners...
331+ */
332+
333+ for (lis = (cupsd_listener_t *)cupsArrayFirst(Listeners);
334+ lis;
335+ lis = (cupsd_listener_t *)cupsArrayNext(Listeners))
336+ if (httpAddrEqual(&lis->address, &addr))
337+ break;
338+
339+ if (lis)
340+ {
341+ cupsdLogMessage(CUPSD_LOG_DEBUG,
342+ "systemd_checkin: Matched existing listener %s with fd %d...",
343+ httpAddrString(&(lis->address), s, sizeof(s)), fd);
344+ }
345+ else
346+ {
347+ cupsdLogMessage(CUPSD_LOG_DEBUG,
348+ "systemd_checkin: Adding new listener %s with fd %d...",
349+ httpAddrString(&addr, s, sizeof(s)), fd);
350+
351+ if ((lis = calloc(1, sizeof(cupsd_listener_t))) == NULL)
352+ {
353+ cupsdLogMessage(CUPSD_LOG_ERROR,
354+ "systemd_checkin: Unable to allocate listener - "
355+ "%s.", strerror(errno));
356+ exit(EXIT_FAILURE);
357+ }
358+
359+ cupsArrayAdd(Listeners, lis);
360+
361+ memcpy(&lis->address, &addr, sizeof(lis->address));
362+ }
363+
364+ lis->fd = fd;
365+ lis->is_systemd = 1;
366+
367+# ifdef HAVE_SSL
368+ if (_httpAddrPort(&(lis->address)) == 443)
369+ lis->encryption = HTTP_ENCRYPT_ALWAYS;
370+# endif /* HAVE_SSL */
371+ }
372+}
373+#endif /* HAVE_SYSTEMD */
374
375 /*
376 * 'parent_handler()' - Catch USR1/CHLD signals...
3e1538e5
JR
377diff -up cups-1.7rc1/scheduler/Makefile.systemd-socket cups-1.7rc1/scheduler/Makefile
378--- cups-1.7rc1/scheduler/Makefile.systemd-socket 2013-05-29 13:51:34.000000000 +0200
379+++ cups-1.7rc1/scheduler/Makefile 2013-07-12 11:16:53.261546208 +0200
380@@ -381,7 +381,7 @@ cupsd: $(CUPSDOBJS) $(LIBCUPSMIME) ../cu
304fa3b3
JR
381 $(CC) $(LDFLAGS) -o cupsd $(CUPSDOBJS) -L. -lcupsmime \
382 $(LIBZ) $(SSLLIBS) $(LIBSLP) $(LIBLDAP) $(PAMLIBS) \
383 $(LIBPAPER) $(LIBMALLOC) $(SERVERLIBS) $(DNSSDLIBS) $(LIBS) \
384- $(LIBGSSAPI) $(LIBWRAP)
385+ $(LIBGSSAPI) $(LIBWRAP) $(SDLIBS)
386
387 cupsd-static: $(CUPSDOBJS) libcupsmime.a ../cups/$(LIBCUPSSTATIC)
388 echo Linking $@...
3e1538e5 389@@ -389,7 +389,7 @@ cupsd-static: $(CUPSDOBJS) libcupsmime.a
304fa3b3
JR
390 $(LIBZ) $(SSLLIBS) $(LIBSLP) $(LIBLDAP) $(PAMLIBS) \
391 ../cups/$(LIBCUPSSTATIC) $(COMMONLIBS) $(LIBZ) $(LIBPAPER) \
392 $(LIBMALLOC) $(SERVERLIBS) $(DNSSDLIBS) $(LIBGSSAPI) \
393- $(LIBWRAP)
3e1538e5 394+ $(LIBWRAP) $(SDLIBS)
304fa3b3 395
3e1538e5 396 tls.o: tls-darwin.c tls-gnutls.c tls-openssl.c
304fa3b3 397
This page took 0.087462 seconds and 4 git commands to generate.