1 diff -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
8 + * Do we have systemd support?
15 * Various scripting languages...
18 diff -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
25 +dnl systemd stuff for CUPS.
27 +dnl Find whether systemd is available
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
37 + SDCFLAGS=`$PKGCONFIG --cflags libsystemd-daemon`
38 + SDLIBS=`$PKGCONFIG --libs libsystemd-daemon`
39 + AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
40 + AC_DEFINE(HAVE_SYSTEMD)
46 +if test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno ; then
47 + SYSTEMD_UNITS="cups.service cups.socket cups.path"
52 +AC_SUBST(SYSTEMD_UNITS)
58 diff -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)
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)
69 @@ -67,6 +68,9 @@ AC_OUTPUT(Makedefs
77 doc/help/ref-cups-files-conf.html
78 doc/help/ref-cupsd-conf.html
79 diff -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(
83 struct stat sockinfo; /* Domain socket information */
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;
90 #endif /* CUPS_DEFAULT_DOMAINSOCKET */
91 diff -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
96 +Description=CUPS Printer Service Spool
99 +PathExistsGlob=@CUPS_REQUESTS@/d*
102 +WantedBy=multi-user.target
103 diff -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
108 +Description=CUPS Printing Service
111 +ExecStart=@sbindir@/cupsd -f
115 +Also=cups.socket cups.path
116 +WantedBy=printer.target
117 diff -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
122 +Description=CUPS Printing Service Sockets
125 +ListenStream=@CUPS_DEFAULT_DOMAINSOCKET@
128 +WantedBy=sockets.target
129 diff -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:
133 $(INSTALL_DATA) $$file $(DATADIR)/ppdc; \
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); \
145 @@ -143,6 +149,9 @@ uninstall:
146 -$(RMDIR) $(DATADIR)/data
147 -$(RMDIR) $(DATADIR)/banners
149 + for file in $(SYSTEMD_UNITS); do \
150 + $(RM) $(SYSTEMDUNITDIR)/$$file; \
155 diff -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@
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)
166 @@ -141,6 +142,7 @@ DNSSDLIBS = @DNSSDLIBS@
167 IPPFIND_BIN = @IPPFIND_BIN@
168 IPPFIND_MAN = @IPPFIND_MAN@
169 LAUNCHDLIBS = @LAUNCHDLIBS@
171 LDFLAGS = -L../cgi-bin -L../cups -L../filter -L../ppdc \
172 -L../scheduler @LDARCHFLAGS@ \
173 @LDFLAGS@ @RELROFLAGS@ @PIEFLAGS@ $(OPTIM)
174 @@ -231,6 +233,7 @@ PAMFILE = @PAMFILE@
176 DEFAULT_LAUNCHD_CONF = @DEFAULT_LAUNCHD_CONF@
178 +SYSTEMDUNITDIR = $(BUILDROOT)@systemdsystemunitdir@
182 diff -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
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... */
190 + int is_systemd; /* Is this a systemd socket? */
191 +#endif /* HAVE_SYSTEMD */
195 diff -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
198 @@ -401,7 +401,11 @@ cupsdStopListening(void)
200 lis = (cupsd_listener_t *)cupsArrayNext(Listeners))
205 + && !lis->is_systemd
206 +#endif /* HAVE_SYSTEMD */
210 closesocket(lis->fd);
211 diff -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
215 * launchd_checkin() - Check-in with launchd and collect the listening
217 * launchd_checkout() - Update the launchd KeepAlive file as needed.
218 + * systemd_checkin() - Check-in with systemd and collect the
220 * parent_handler() - Catch USR1/CHLD signals...
221 * process_children() - Process all dead children...
222 * select_timeout() - Calculate the select timeout value.
224 # endif /* !LAUNCH_JOBKEY_SERVICEIPC */
225 #endif /* HAVE_LAUNCH_H */
228 +#include <systemd/sd-daemon.h>
229 +#endif /* HAVE_SYSTEMD */
231 #if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
233 #endif /* HAVE_MALLOC_H && HAVE_MALLINFO */
235 static void launchd_checkin(void);
236 static void launchd_checkout(void);
237 #endif /* HAVE_LAUNCHD */
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);
244 @@ -574,6 +583,13 @@ main(int argc, /* I - Number of comm
246 #endif /* HAVE_LAUNCHD */
250 + * If we were started by systemd get the listen sockets file descriptors...
253 +#endif /* HAVE_SYSTEMD */
256 * Startup the server...
258 @@ -762,6 +778,15 @@ main(int argc, /* I - Number of comm
260 #endif /* HAVE_LAUNCHD */
264 + * If we were started by systemd get the listen sockets file
269 +#endif /* HAVE_SYSTEMD */
272 * Startup the server...
274 @@ -1511,6 +1536,102 @@ launchd_checkout(void)
276 #endif /* HAVE_LAUNCHD */
280 +systemd_checkin(void)
284 + n = sd_listen_fds(0);
287 + cupsdLogMessage(CUPSD_LOG_ERROR,
288 + "systemd_checkin: Failed to acquire sockets from systemd - %s",
290 + exit(EXIT_FAILURE);
297 + for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd ++)
300 + socklen_t addrlen = sizeof (addr);
302 + cupsd_listener_t *lis;
305 + r = sd_is_socket(fd, AF_UNSPEC, SOCK_STREAM, 1);
308 + cupsdLogMessage(CUPSD_LOG_ERROR,
309 + "systemd_checkin: Unable to verify socket type - %s",
316 + cupsdLogMessage(CUPSD_LOG_ERROR,
317 + "systemd_checkin: Socket not of the right type");
321 + if (getsockname(fd, (struct sockaddr*) &addr, &addrlen))
323 + cupsdLogMessage(CUPSD_LOG_ERROR,
324 + "systemd_checkin: Unable to get local address - %s",
330 + * Try to match the systemd socket address to one of the listeners...
333 + for (lis = (cupsd_listener_t *)cupsArrayFirst(Listeners);
335 + lis = (cupsd_listener_t *)cupsArrayNext(Listeners))
336 + if (httpAddrEqual(&lis->address, &addr))
341 + cupsdLogMessage(CUPSD_LOG_DEBUG,
342 + "systemd_checkin: Matched existing listener %s with fd %d...",
343 + httpAddrString(&(lis->address), s, sizeof(s)), fd);
347 + cupsdLogMessage(CUPSD_LOG_DEBUG,
348 + "systemd_checkin: Adding new listener %s with fd %d...",
349 + httpAddrString(&addr, s, sizeof(s)), fd);
351 + if ((lis = calloc(1, sizeof(cupsd_listener_t))) == NULL)
353 + cupsdLogMessage(CUPSD_LOG_ERROR,
354 + "systemd_checkin: Unable to allocate listener - "
355 + "%s.", strerror(errno));
356 + exit(EXIT_FAILURE);
359 + cupsArrayAdd(Listeners, lis);
361 + memcpy(&lis->address, &addr, sizeof(lis->address));
365 + lis->is_systemd = 1;
368 + if (_httpAddrPort(&(lis->address)) == 443)
369 + lis->encryption = HTTP_ENCRYPT_ALWAYS;
370 +# endif /* HAVE_SSL */
373 +#endif /* HAVE_SYSTEMD */
376 * 'parent_handler()' - Catch USR1/CHLD signals...
377 diff -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
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)
387 cupsd-static: $(CUPSDOBJS) libcupsmime.a ../cups/$(LIBCUPSSTATIC)
389 @@ -389,7 +389,7 @@ cupsd-static: $(CUPSDOBJS) libcupsmime.a
390 $(LIBZ) $(SSLLIBS) $(LIBSLP) $(LIBLDAP) $(PAMLIBS) \
391 ../cups/$(LIBCUPSSTATIC) $(COMMONLIBS) $(LIBZ) $(LIBPAPER) \
392 $(LIBMALLOC) $(SERVERLIBS) $(DNSSDLIBS) $(LIBGSSAPI) \
394 + $(LIBWRAP) $(SDLIBS)
396 tls.o: tls-darwin.c tls-gnutls.c tls-openssl.c