c880263
diff -up cups-1.5.2/config.h.in.systemd-socket cups-1.5.2/config.h.in
c880263
--- cups-1.5.2/config.h.in.systemd-socket	2012-03-16 14:50:57.089449755 +0000
c880263
+++ cups-1.5.2/config.h.in	2012-03-16 14:50:57.146449787 +0000
dbd9e73
@@ -503,6 +503,13 @@
dbd9e73
 
dbd9e73
 
dbd9e73
 /*
dbd9e73
+ * Do we have systemd support?
dbd9e73
+ */
dbd9e73
+
dbd9e73
+#undef HAVE_SYSTEMD
dbd9e73
+
dbd9e73
+
dbd9e73
+/*
dbd9e73
  * Various scripting languages...
dbd9e73
  */
dbd9e73
 
c880263
diff -up cups-1.5.2/config-scripts/cups-systemd.m4.systemd-socket cups-1.5.2/config-scripts/cups-systemd.m4
c880263
--- cups-1.5.2/config-scripts/cups-systemd.m4.systemd-socket	2012-03-16 14:50:57.146449787 +0000
c880263
+++ cups-1.5.2/config-scripts/cups-systemd.m4	2012-03-16 14:50:57.146449787 +0000
dbd9e73
@@ -0,0 +1,36 @@
Lennart Poettering 55dcb25
+dnl
Lennart Poettering 55dcb25
+dnl "$Id$"
Lennart Poettering 55dcb25
+dnl
Lennart Poettering 55dcb25
+dnl   systemd stuff for CUPS.
Lennart Poettering 55dcb25
+
Lennart Poettering 55dcb25
+dnl Find whether systemd is available
Lennart Poettering 55dcb25
+
dbd9e73
+SDLIBS=""
Lennart Poettering 55dcb25
+AC_ARG_WITH([systemdsystemunitdir],
Lennart Poettering 55dcb25
+        AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files]),
Lennart Poettering 55dcb25
+        [], [with_systemdsystemunitdir=$($PKGCONFIG --variable=systemdsystemunitdir systemd)])
Lennart Poettering 55dcb25
+if test "x$with_systemdsystemunitdir" != xno; then
dbd9e73
+        AC_MSG_CHECKING(for libsystemd-daemon)
dbd9e73
+        if $PKGCONFIG --exists libsystemd-daemon; then
dbd9e73
+		AC_MSG_RESULT(yes)
dbd9e73
+        	SDCFLAGS=`$PKGCONFIG --cflags libsystemd-daemon`
dbd9e73
+        	SDLIBS=`$PKGCONFIG --libs libsystemd-daemon`
dbd9e73
+		AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
dbd9e73
+		AC_DEFINE(HAVE_SYSTEMD)
dbd9e73
+	else
dbd9e73
+		AC_MSG_RESULT(no)
dbd9e73
+	fi
Lennart Poettering 55dcb25
+fi
Lennart Poettering 55dcb25
+
Lennart Poettering 55dcb25
+if test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno ; then
Lennart Poettering 55dcb25
+        SYSTEMD_UNITS="cups.service cups.socket cups.path"
Lennart Poettering 55dcb25
+else
Lennart Poettering 55dcb25
+        SYSTEMD_UNITS=""
Lennart Poettering 55dcb25
+fi
Lennart Poettering 55dcb25
+
Lennart Poettering 55dcb25
+AC_SUBST(SYSTEMD_UNITS)
dbd9e73
+AC_SUBST(SDLIBS)
Lennart Poettering 55dcb25
+
Lennart Poettering 55dcb25
+dnl
Lennart Poettering 55dcb25
+dnl "$Id$"
Lennart Poettering 55dcb25
+dnl
c880263
diff -up cups-1.5.2/configure.in.systemd-socket cups-1.5.2/configure.in
c880263
--- cups-1.5.2/configure.in.systemd-socket	2011-08-31 02:36:33.000000000 +0100
c880263
+++ cups-1.5.2/configure.in	2012-03-16 14:50:57.146449787 +0000
Lennart Poettering 55dcb25
@@ -37,6 +37,7 @@ sinclude(config-scripts/cups-pam.m4)
Lennart Poettering 55dcb25
 sinclude(config-scripts/cups-largefile.m4)
Lennart Poettering 55dcb25
 sinclude(config-scripts/cups-dnssd.m4)
Lennart Poettering 55dcb25
 sinclude(config-scripts/cups-launchd.m4)
Lennart Poettering 55dcb25
+sinclude(config-scripts/cups-systemd.m4)
Lennart Poettering 55dcb25
 sinclude(config-scripts/cups-defaults.m4)
Lennart Poettering 55dcb25
 sinclude(config-scripts/cups-pdf.m4)
Lennart Poettering 55dcb25
 sinclude(config-scripts/cups-scripting.m4)
Lennart Poettering 55dcb25
@@ -71,6 +72,9 @@ AC_OUTPUT(Makedefs
Lennart Poettering 55dcb25
 	  conf/snmp.conf
Lennart Poettering 55dcb25
 	  cups-config
Lennart Poettering 55dcb25
 	  data/testprint
Lennart Poettering 55dcb25
+          data/cups.service
Lennart Poettering 55dcb25
+          data/cups.socket
Lennart Poettering 55dcb25
+          data/cups.path
Lennart Poettering 55dcb25
 	  desktop/cups.desktop
Lennart Poettering 55dcb25
 	  doc/help/ref-cupsd-conf.html
Lennart Poettering 55dcb25
 	  doc/help/standard.html
c880263
diff -up cups-1.5.2/cups/usersys.c.systemd-socket cups-1.5.2/cups/usersys.c
c880263
--- cups-1.5.2/cups/usersys.c.systemd-socket	2012-03-16 14:50:57.054449734 +0000
c880263
+++ cups-1.5.2/cups/usersys.c	2012-03-16 14:50:57.148449788 +0000
c880263
@@ -778,7 +778,7 @@ cups_read_client_conf(
3bce791
     struct stat	sockinfo;		/* Domain socket information */
3bce791
 
3bce791
     if (!stat(CUPS_DEFAULT_DOMAINSOCKET, &sockinfo) &&
3bce791
-	(sockinfo.st_mode & S_IRWXO) == S_IRWXO)
3bce791
+	(sockinfo.st_mode & (S_IROTH | S_IWOTH)) == (S_IROTH | S_IWOTH))
3bce791
       cups_server = CUPS_DEFAULT_DOMAINSOCKET;
3bce791
     else
3bce791
 #endif /* CUPS_DEFAULT_DOMAINSOCKET */
c880263
diff -up cups-1.5.2/data/cups.path.in.systemd-socket cups-1.5.2/data/cups.path.in
c880263
--- cups-1.5.2/data/cups.path.in.systemd-socket	2012-03-16 14:50:57.148449788 +0000
c880263
+++ cups-1.5.2/data/cups.path.in	2012-03-16 14:50:57.148449788 +0000
Lennart Poettering 55dcb25
@@ -0,0 +1,8 @@
Lennart Poettering 55dcb25
+[Unit]
Lennart Poettering 55dcb25
+Description=CUPS Printer Service Spool
Lennart Poettering 55dcb25
+
Lennart Poettering 55dcb25
+[Path]
929e106
+PathExistsGlob=@CUPS_REQUESTS@/d*
Lennart Poettering 55dcb25
+
Lennart Poettering 55dcb25
+[Install]
Lennart Poettering 55dcb25
+WantedBy=multi-user.target
c880263
diff -up cups-1.5.2/data/cups.service.in.systemd-socket cups-1.5.2/data/cups.service.in
c880263
--- cups-1.5.2/data/cups.service.in.systemd-socket	2012-03-16 14:50:57.149449788 +0000
c880263
+++ cups-1.5.2/data/cups.service.in	2012-03-16 14:50:57.149449788 +0000
f0db99c
@@ -0,0 +1,10 @@
Lennart Poettering 55dcb25
+[Unit]
Lennart Poettering 55dcb25
+Description=CUPS Printing Service
Lennart Poettering 55dcb25
+
Lennart Poettering 55dcb25
+[Service]
Lennart Poettering 55dcb25
+ExecStart=@sbindir@/cupsd -f
f0db99c
+PrivateTmp=true
Lennart Poettering 55dcb25
+
Lennart Poettering 55dcb25
+[Install]
Lennart Poettering 55dcb25
+Also=cups.socket cups.path
Lennart Poettering 55dcb25
+WantedBy=printer.target
c880263
diff -up cups-1.5.2/data/cups.socket.in.systemd-socket cups-1.5.2/data/cups.socket.in
c880263
--- cups-1.5.2/data/cups.socket.in.systemd-socket	2012-03-16 14:50:57.150449788 +0000
c880263
+++ cups-1.5.2/data/cups.socket.in	2012-03-16 14:50:57.150449788 +0000
843ebb9
@@ -0,0 +1,11 @@
Lennart Poettering 55dcb25
+[Unit]
Lennart Poettering 55dcb25
+Description=CUPS Printing Service Sockets
Lennart Poettering 55dcb25
+
Lennart Poettering 55dcb25
+[Socket]
Lennart Poettering 55dcb25
+ListenStream=@CUPS_DEFAULT_DOMAINSOCKET@
Lennart Poettering 55dcb25
+ListenStream=631
843ebb9
+ListenDatagram=0.0.0.0:631
0928f7c
+BindIPv6Only=ipv6-only
Lennart Poettering 55dcb25
+
Lennart Poettering 55dcb25
+[Install]
Lennart Poettering 55dcb25
+WantedBy=sockets.target
c880263
diff -up cups-1.5.2/data/Makefile.systemd-socket cups-1.5.2/data/Makefile
c880263
--- cups-1.5.2/data/Makefile.systemd-socket	2011-05-12 06:21:56.000000000 +0100
c880263
+++ cups-1.5.2/data/Makefile	2012-03-16 14:50:57.151449789 +0000
9829b01
@@ -112,6 +112,12 @@ install-data:
9829b01
 		$(INSTALL_DATA) $$file $(DATADIR)/ppdc; \
9829b01
 	done
9829b01
 	$(INSTALL_DIR) -m 755 $(DATADIR)/profiles
9829b01
+	if test "x$(SYSTEMD_UNITS)" != "x" ; then \
9829b01
+		$(INSTALL_DIR) -m 755 $(SYSTEMDUNITDIR); \
9829b01
+		for file in $(SYSTEMD_UNITS); do \
9829b01
+			$(INSTALL_DATA) $$file $(SYSTEMDUNITDIR); \
9829b01
+		done; \
9829b01
+	fi
Lennart Poettering 55dcb25
 
Lennart Poettering 55dcb25
 
Lennart Poettering 55dcb25
 #
9829b01
@@ -159,6 +165,9 @@ uninstall:
9829b01
 	-$(RMDIR) $(DATADIR)/charsets
9829b01
 	-$(RMDIR) $(DATADIR)/banners
9829b01
 	-$(RMDIR) $(DATADIR)
9829b01
+	for file in $(SYSTEMD_UNITS); do \
9829b01
+		$(RM) $(SYSTEMDUNITDIR)/$$file; \
9829b01
+	done
9829b01
 
9829b01
 
Lennart Poettering 55dcb25
 #
c880263
diff -up cups-1.5.2/Makedefs.in.systemd-socket cups-1.5.2/Makedefs.in
c880263
--- cups-1.5.2/Makedefs.in.systemd-socket	2012-03-16 14:50:57.081449751 +0000
c880263
+++ cups-1.5.2/Makedefs.in	2012-03-16 14:50:57.152449790 +0000
9829b01
@@ -143,6 +143,7 @@ CXXFLAGS	=	@CPPFLAGS@ @CXXFLAGS@
9829b01
 CXXLIBS		=	@CXXLIBS@
9829b01
 DBUS_NOTIFIER	=	@DBUS_NOTIFIER@
9829b01
 DBUS_NOTIFIERLIBS =	@DBUS_NOTIFIERLIBS@
9829b01
+SYSTEMD_UNITS   =       @SYSTEMD_UNITS@
9829b01
 DNSSD_BACKEND	=	@DNSSD_BACKEND@
9829b01
 DSOFLAGS	=	-L../cups @DSOFLAGS@
9829b01
 DSOLIBS		=	@DSOLIBS@ $(COMMONLIBS)
dbd9e73
@@ -151,6 +152,7 @@ FONTS		=	@FONTS@
dbd9e73
 IMGLIBS		=	@IMGLIBS@
dbd9e73
 IMGFILTERS	=	@IMGFILTERS@
dbd9e73
 LAUNCHDLIBS	=	@LAUNCHDLIBS@
dbd9e73
+SDLIBS		=	@SDLIBS@
dbd9e73
 LDFLAGS		=	-L../cgi-bin -L../cups -L../filter -L../ppdc \
dbd9e73
 			-L../scheduler @LDARCHFLAGS@ \
dbd9e73
 			@LDFLAGS@ @RELROFLAGS@ @PIEFLAGS@ $(OPTIM)
dbd9e73
@@ -267,6 +269,7 @@ PAMFILE		=	@PAMFILE@
Lennart Poettering 55dcb25
 
9829b01
 DEFAULT_LAUNCHD_CONF =	@DEFAULT_LAUNCHD_CONF@
9829b01
 DBUSDIR		=	@DBUSDIR@
9829b01
+SYSTEMDUNITDIR  =       $(BUILDROOT)@systemdsystemunitdir@
9829b01
 
9829b01
 
9829b01
 #
c880263
diff -up cups-1.5.2/scheduler/client.h.systemd-socket cups-1.5.2/scheduler/client.h
c880263
--- cups-1.5.2/scheduler/client.h.systemd-socket	2011-03-25 21:25:38.000000000 +0000
c880263
+++ cups-1.5.2/scheduler/client.h	2012-03-16 14:50:57.153449791 +0000
dbd9e73
@@ -75,6 +75,9 @@ typedef struct
3188be0
   int			fd;		/* File descriptor for this server */
3188be0
   http_addr_t		address;	/* Bind address of socket */
3188be0
   http_encryption_t	encryption;	/* To encrypt or not to encrypt... */
dbd9e73
+#ifdef HAVE_SYSTEMD
3188be0
+  int			is_systemd;	/* Is this a systemd socket? */
dbd9e73
+#endif /* HAVE_SYSTEMD */
3188be0
 } cupsd_listener_t;
3188be0
 
3188be0
 
c880263
diff -up cups-1.5.2/scheduler/dirsvc.c.systemd-socket cups-1.5.2/scheduler/dirsvc.c
c880263
--- cups-1.5.2/scheduler/dirsvc.c.systemd-socket	2012-03-16 14:50:57.112449768 +0000
c880263
+++ cups-1.5.2/scheduler/dirsvc.c	2012-03-16 14:50:57.155449792 +0000
843ebb9
@@ -1512,7 +1512,7 @@ cupsdStartBrowsing(void)
843ebb9
       }
843ebb9
     }
843ebb9
 
843ebb9
-    if (BrowseSocket >= 0)
843ebb9
+    if (BrowseSocket >= 0 && !BrowseSocketIsSystemd)
843ebb9
     {
843ebb9
      /*
843ebb9
       * Bind the socket to browse port...
843ebb9
@@ -1556,13 +1556,17 @@ cupsdStartBrowsing(void)
843ebb9
 	cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to set broadcast mode - %s.",
843ebb9
 			strerror(errno));
843ebb9
 
843ebb9
+	if (!BrowseSocketIsSystemd)
843ebb9
+	{
843ebb9
 #ifdef WIN32
843ebb9
-	closesocket(BrowseSocket);
843ebb9
+	  closesocket(BrowseSocket);
843ebb9
 #else
843ebb9
-	close(BrowseSocket);
843ebb9
+	  close(BrowseSocket);
843ebb9
 #endif /* WIN32 */
843ebb9
 
843ebb9
-	BrowseSocket = -1;
843ebb9
+	  BrowseSocket = -1;
843ebb9
+	}
843ebb9
+
843ebb9
 	BrowseLocalProtocols &= ~BROWSE_CUPS;
843ebb9
 	BrowseRemoteProtocols &= ~BROWSE_CUPS;
843ebb9
 
843ebb9
@@ -1885,15 +1889,22 @@ cupsdStopBrowsing(void)
843ebb9
   if (((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_CUPS) &&
843ebb9
       BrowseSocket >= 0)
843ebb9
   {
843ebb9
-   /*
843ebb9
-    * Close the socket and remove it from the input selection set.
843ebb9
-    */
843ebb9
+    if (!BrowseSocketIsSystemd)
843ebb9
+    {
843ebb9
+     /*
843ebb9
+      * Close the socket.
843ebb9
+      */
843ebb9
 
843ebb9
 #ifdef WIN32
843ebb9
-    closesocket(BrowseSocket);
843ebb9
+      closesocket(BrowseSocket);
843ebb9
 #else
843ebb9
-    close(BrowseSocket);
843ebb9
+      close(BrowseSocket);
843ebb9
 #endif /* WIN32 */
843ebb9
+    }
843ebb9
+
843ebb9
+   /*
843ebb9
+    * Remove it from the input selection set.
843ebb9
+    */
843ebb9
 
843ebb9
     cupsdRemoveSelect(BrowseSocket);
843ebb9
     BrowseSocket = -1;
c880263
@@ -5693,11 +5704,14 @@ update_cups_browse(void)
843ebb9
                       strerror(errno));
843ebb9
       cupsdLogMessage(CUPSD_LOG_ERROR, "CUPS browsing turned off.");
843ebb9
 
843ebb9
+      if (!BrowseSocketIsSystemd)
843ebb9
+      {
843ebb9
 #ifdef WIN32
843ebb9
-      closesocket(BrowseSocket);
843ebb9
+	closesocket(BrowseSocket);
843ebb9
 #else
843ebb9
-      close(BrowseSocket);
843ebb9
+	close(BrowseSocket);
843ebb9
 #endif /* WIN32 */
843ebb9
+      }
843ebb9
 
843ebb9
       cupsdRemoveSelect(BrowseSocket);
843ebb9
       BrowseSocket = -1;
c880263
diff -up cups-1.5.2/scheduler/dirsvc.h.systemd-socket cups-1.5.2/scheduler/dirsvc.h
c880263
--- cups-1.5.2/scheduler/dirsvc.h.systemd-socket	2012-03-16 14:50:57.113449769 +0000
c880263
+++ cups-1.5.2/scheduler/dirsvc.h	2012-03-16 14:50:57.157449792 +0000
843ebb9
@@ -100,6 +100,8 @@ VAR int			Browsing	VALUE(TRUE),
843ebb9
 					/* Short names for remote printers? */
843ebb9
 			BrowseSocket	VALUE(-1),
843ebb9
 					/* Socket for browsing */
843ebb9
+			BrowseSocketIsSystemd	VALUE(0),
843ebb9
+					/* BrowseSocket is systemd-provided? */
843ebb9
 			BrowsePort	VALUE(IPP_PORT),
843ebb9
 					/* Port number for broadcasts */
843ebb9
 			BrowseInterval	VALUE(DEFAULT_INTERVAL),
c880263
diff -up cups-1.5.2/scheduler/listen.c.systemd-socket cups-1.5.2/scheduler/listen.c
c880263
--- cups-1.5.2/scheduler/listen.c.systemd-socket	2011-04-16 00:38:13.000000000 +0100
c880263
+++ cups-1.5.2/scheduler/listen.c	2012-03-16 14:50:57.158449792 +0000
dbd9e73
@@ -401,7 +401,11 @@ cupsdStopListening(void)
3188be0
        lis;
3188be0
        lis = (cupsd_listener_t *)cupsArrayNext(Listeners))
3188be0
   {
3188be0
-    if (lis->fd != -1)
dbd9e73
+    if (lis->fd != -1
dbd9e73
+#ifdef HAVE_SYSTEMD
dbd9e73
+        && !lis->is_systemd
dbd9e73
+#endif /* HAVE_SYSTEMD */
dbd9e73
+        )
3188be0
     {
3188be0
 #ifdef WIN32
3188be0
       closesocket(lis->fd);
c880263
diff -up cups-1.5.2/scheduler/main.c.systemd-socket cups-1.5.2/scheduler/main.c
c880263
--- cups-1.5.2/scheduler/main.c.systemd-socket	2012-03-16 14:50:57.121449773 +0000
c880263
+++ cups-1.5.2/scheduler/main.c	2012-03-16 14:51:55.409483636 +0000
Lennart Poettering 55dcb25
@@ -26,6 +26,8 @@
Lennart Poettering 55dcb25
  *   launchd_checkin()     - Check-in with launchd and collect the listening
Lennart Poettering 55dcb25
  *                           fds.
Lennart Poettering 55dcb25
  *   launchd_checkout()    - Update the launchd KeepAlive file as needed.
Lennart Poettering 55dcb25
+ *   systemd_checkin()     - Check-in with systemd and collect the
Lennart Poettering 55dcb25
+ *                           listening fds.
Lennart Poettering 55dcb25
  *   parent_handler()      - Catch USR1/CHLD signals...
Lennart Poettering 55dcb25
  *   process_children()    - Process all dead children...
Lennart Poettering 55dcb25
  *   select_timeout()      - Calculate the select timeout value.
dbd9e73
@@ -62,6 +64,10 @@
Lennart Poettering 55dcb25
 #  endif /* !LAUNCH_JOBKEY_SERVICEIPC */
Lennart Poettering 55dcb25
 #endif /* HAVE_LAUNCH_H */
Lennart Poettering 55dcb25
 
dbd9e73
+#ifdef HAVE_SYSTEMD
dbd9e73
+#include <systemd/sd-daemon.h>
dbd9e73
+#endif /* HAVE_SYSTEMD */
Lennart Poettering 55dcb25
+
Lennart Poettering 55dcb25
 #if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
Lennart Poettering 55dcb25
 #  include <malloc.h>
Lennart Poettering 55dcb25
 #endif /* HAVE_MALLOC_H && HAVE_MALLINFO */
dbd9e73
@@ -78,6 +84,9 @@
Lennart Poettering 55dcb25
 static void		launchd_checkin(void);
Lennart Poettering 55dcb25
 static void		launchd_checkout(void);
Lennart Poettering 55dcb25
 #endif /* HAVE_LAUNCHD */
dbd9e73
+#ifdef HAVE_SYSTEMD
Lennart Poettering 55dcb25
+static void		systemd_checkin(void);
dbd9e73
+#endif /* HAVE_SYSTEMD */
Lennart Poettering 55dcb25
 static void		parent_handler(int sig);
Lennart Poettering 55dcb25
 static void		process_children(void);
Lennart Poettering 55dcb25
 static void		sigchld_handler(int sig);
dbd9e73
@@ -537,6 +546,13 @@ main(int  argc,				/* I - Number of comm
dbd9e73
   }
Lennart Poettering 55dcb25
 #endif /* HAVE_LAUNCHD */
Lennart Poettering 55dcb25
 
dbd9e73
+#ifdef HAVE_SYSTEMD
dbd9e73
+ /*
Lennart Poettering 55dcb25
+  * If we were started by systemd get the listen sockets file descriptors...
Lennart Poettering 55dcb25
+  */
Lennart Poettering 55dcb25
+  systemd_checkin();
dbd9e73
+#endif /* HAVE_SYSTEMD */
Lennart Poettering 55dcb25
+
dbd9e73
  /*
Lennart Poettering 55dcb25
   * Startup the server...
Lennart Poettering 55dcb25
   */
dbd9e73
@@ -759,6 +775,15 @@ main(int  argc,				/* I - Number of comm
dbd9e73
 	}
Lennart Poettering 55dcb25
 #endif /* HAVE_LAUNCHD */
Lennart Poettering 55dcb25
 
dbd9e73
+#ifdef HAVE_SYSTEMD
dbd9e73
+       /*
dbd9e73
+	* If we were started by systemd get the listen sockets file
dbd9e73
+	* descriptors...
Lennart Poettering 55dcb25
+        */
Lennart Poettering 55dcb25
+
Lennart Poettering 55dcb25
+        systemd_checkin();
dbd9e73
+#endif /* HAVE_SYSTEMD */
Lennart Poettering 55dcb25
+
dbd9e73
        /*
Lennart Poettering 55dcb25
         * Startup the server...
Lennart Poettering 55dcb25
         */
c880263
@@ -1584,6 +1609,139 @@ launchd_checkout(void)
Lennart Poettering 55dcb25
 }
Lennart Poettering 55dcb25
 #endif /* HAVE_LAUNCHD */
Lennart Poettering 55dcb25
 
dbd9e73
+#ifdef HAVE_SYSTEMD
Lennart Poettering 55dcb25
+static void
Lennart Poettering 55dcb25
+systemd_checkin(void)
Lennart Poettering 55dcb25
+{
Lennart Poettering 55dcb25
+  int n, fd;
Lennart Poettering 55dcb25
+
3188be0
+  n = sd_listen_fds(0);
Lennart Poettering 55dcb25
+  if (n < 0)
Lennart Poettering 55dcb25
+  {
Lennart Poettering 55dcb25
+    cupsdLogMessage(CUPSD_LOG_ERROR,
Lennart Poettering 55dcb25
+           "systemd_checkin: Failed to acquire sockets from systemd - %s",
Lennart Poettering 55dcb25
+           strerror(-n));
Lennart Poettering 55dcb25
+    exit(EXIT_FAILURE);
Lennart Poettering 55dcb25
+    return;
Lennart Poettering 55dcb25
+  }
Lennart Poettering 55dcb25
+
Lennart Poettering 55dcb25
+  if (n == 0)
Lennart Poettering 55dcb25
+    return;
Lennart Poettering 55dcb25
+
Lennart Poettering 55dcb25
+  for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd ++)
Lennart Poettering 55dcb25
+  {
Lennart Poettering 55dcb25
+    http_addr_t addr;
cd792f4
+    socklen_t addrlen = sizeof (addr);
Lennart Poettering 55dcb25
+    int r;
Lennart Poettering 55dcb25
+    cupsd_listener_t *lis;
Lennart Poettering 55dcb25
+    char s[256];
Lennart Poettering 55dcb25
+
Lennart Poettering 55dcb25
+    r = sd_is_socket(fd, AF_UNSPEC, SOCK_STREAM, 1);
843ebb9
+    if (r < 0)
843ebb9
+    {
Lennart Poettering 55dcb25
+      cupsdLogMessage(CUPSD_LOG_ERROR,
Lennart Poettering 55dcb25
+             "systemd_checkin: Unable to verify socket type - %s",
Lennart Poettering 55dcb25
+             strerror(-r));
Lennart Poettering 55dcb25
+      continue;
Lennart Poettering 55dcb25
+    }
Lennart Poettering 55dcb25
+
843ebb9
+    if (!r)
843ebb9
+    {
843ebb9
+      if (Browsing &&
843ebb9
+	  ((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_CUPS))
843ebb9
+      {
843ebb9
+	r = sd_is_socket(fd, AF_UNSPEC, SOCK_DGRAM, 0);
843ebb9
+	if (r < 0)
843ebb9
+	{
843ebb9
+	  cupsdLogMessage(CUPSD_LOG_ERROR,
843ebb9
+			  "systemd_checkin: Unable to verify socket type - %s",
843ebb9
+			  strerror(-r));
843ebb9
+	  continue;
843ebb9
+	}
843ebb9
+
843ebb9
+	if (r)
843ebb9
+	{
843ebb9
+	 /*
843ebb9
+	  * This is the browse socket.
843ebb9
+	  */
843ebb9
+
843ebb9
+	  char addrstr[256];
843ebb9
+	  if (getsockname(fd, (struct sockaddr*) &addr, &addrlen))
843ebb9
+	  {
843ebb9
+	    cupsdLogMessage(CUPSD_LOG_ERROR,
843ebb9
+			    "systemd_checkin: Unable to get local address - %s",
843ebb9
+			    strerror(errno));
843ebb9
+	    continue;
843ebb9
+	  }
843ebb9
+
843ebb9
+	  httpAddrString (&addr, addrstr, sizeof (addrstr));
843ebb9
+	  BrowseSocket = fd;
843ebb9
+	  BrowseSocketIsSystemd = 1;
843ebb9
+	  cupsdLogMessage(CUPSD_LOG_DEBUG,
843ebb9
+			  "systemd_checkin: Matched browse (port %d) with fd %d:%s...",
843ebb9
+			  BrowsePort, fd, addrstr);
843ebb9
+	  continue;
843ebb9
+	}
843ebb9
+
843ebb9
+      }
Lennart Poettering 55dcb25
+      cupsdLogMessage(CUPSD_LOG_ERROR,
Lennart Poettering 55dcb25
+             "systemd_checkin: Socket not of the right type");
Lennart Poettering 55dcb25
+      continue;
Lennart Poettering 55dcb25
+    }
Lennart Poettering 55dcb25
+
Lennart Poettering 55dcb25
+    if (getsockname(fd, (struct sockaddr*) &addr, &addrlen))
Lennart Poettering 55dcb25
+    {
Lennart Poettering 55dcb25
+      cupsdLogMessage(CUPSD_LOG_ERROR,
Lennart Poettering 55dcb25
+             "systemd_checkin: Unable to get local address - %s",
Lennart Poettering 55dcb25
+             strerror(errno));
Lennart Poettering 55dcb25
+      continue;
Lennart Poettering 55dcb25
+    }
Lennart Poettering 55dcb25
+
843ebb9
+   /*
Lennart Poettering 55dcb25
+    * Try to match the systemd socket address to one of the listeners...
Lennart Poettering 55dcb25
+    */
Lennart Poettering 55dcb25
+
Lennart Poettering 55dcb25
+    for (lis = (cupsd_listener_t *)cupsArrayFirst(Listeners);
Lennart Poettering 55dcb25
+       lis;
Lennart Poettering 55dcb25
+       lis = (cupsd_listener_t *)cupsArrayNext(Listeners))
Lennart Poettering 55dcb25
+      if (httpAddrEqual(&lis->address, &addr))
843ebb9
+	break;
Lennart Poettering 55dcb25
+
Lennart Poettering 55dcb25
+    if (lis)
Lennart Poettering 55dcb25
+    {
Lennart Poettering 55dcb25
+      cupsdLogMessage(CUPSD_LOG_DEBUG,
Lennart Poettering 55dcb25
+                      "systemd_checkin: Matched existing listener %s with fd %d...",
Lennart Poettering 55dcb25
+                      httpAddrString(&(lis->address), s, sizeof(s)), fd);
Lennart Poettering 55dcb25
+    }
Lennart Poettering 55dcb25
+    else
Lennart Poettering 55dcb25
+    {
Lennart Poettering 55dcb25
+      cupsdLogMessage(CUPSD_LOG_DEBUG,
Lennart Poettering 55dcb25
+                      "systemd_checkin: Adding new listener %s with fd %d...",
Lennart Poettering 55dcb25
+                      httpAddrString(&addr, s, sizeof(s)), fd);
Lennart Poettering 55dcb25
+
Lennart Poettering 55dcb25
+      if ((lis = calloc(1, sizeof(cupsd_listener_t))) == NULL)
Lennart Poettering 55dcb25
+      {
Lennart Poettering 55dcb25
+        cupsdLogMessage(CUPSD_LOG_ERROR,
Lennart Poettering 55dcb25
+                        "systemd_checkin: Unable to allocate listener - "
Lennart Poettering 55dcb25
+                        "%s.", strerror(errno));
Lennart Poettering 55dcb25
+        exit(EXIT_FAILURE);
Lennart Poettering 55dcb25
+      }
Lennart Poettering 55dcb25
+
Lennart Poettering 55dcb25
+      cupsArrayAdd(Listeners, lis);
Lennart Poettering 55dcb25
+
Lennart Poettering 55dcb25
+      memcpy(&lis->address, &addr, sizeof(lis->address));
Lennart Poettering 55dcb25
+    }
Lennart Poettering 55dcb25
+
Lennart Poettering 55dcb25
+    lis->fd = fd;
3188be0
+    lis->is_systemd = 1;
Lennart Poettering 55dcb25
+
Lennart Poettering 55dcb25
+#  ifdef HAVE_SSL
Lennart Poettering 55dcb25
+    if (_httpAddrPort(&(lis->address)) == 443)
Lennart Poettering 55dcb25
+      lis->encryption = HTTP_ENCRYPT_ALWAYS;
Lennart Poettering 55dcb25
+#  endif /* HAVE_SSL */
Lennart Poettering 55dcb25
+  }
Lennart Poettering 55dcb25
+}
dbd9e73
+#endif /* HAVE_SYSTEMD */
Lennart Poettering 55dcb25
 
Lennart Poettering 55dcb25
 /*
Lennart Poettering 55dcb25
  * 'parent_handler()' - Catch USR1/CHLD signals...
c880263
diff -up cups-1.5.2/scheduler/Makefile.systemd-socket cups-1.5.2/scheduler/Makefile
c880263
--- cups-1.5.2/scheduler/Makefile.systemd-socket	2012-03-16 14:50:57.130449778 +0000
c880263
+++ cups-1.5.2/scheduler/Makefile	2012-03-16 14:50:57.160449794 +0000
dbd9e73
@@ -382,7 +382,7 @@ cupsd:	$(CUPSDOBJS) $(LIBCUPSMIME) ../cu
dbd9e73
 	$(CC) $(LDFLAGS) -o cupsd $(CUPSDOBJS) -L. -lcupsmime \
dbd9e73
 		$(LIBZ) $(SSLLIBS) $(LIBSLP) $(LIBLDAP) $(PAMLIBS) \
dbd9e73
 		$(LIBPAPER) $(LIBMALLOC) $(SERVERLIBS) $(DNSSDLIBS) $(LIBS) \
dbd9e73
-		$(LIBGSSAPI) $(LIBWRAP)
dbd9e73
+		$(LIBGSSAPI) $(LIBWRAP) $(SDLIBS)
9829b01
 
dbd9e73
 cupsd-static:	$(CUPSDOBJS) libcupsmime.a ../cups/$(LIBCUPSSTATIC)
dbd9e73
 	echo Linking $@...
dbd9e73
@@ -390,7 +390,7 @@ cupsd-static:	$(CUPSDOBJS) libcupsmime.a
dbd9e73
 		$(LIBZ) $(SSLLIBS) $(LIBSLP) $(LIBLDAP) $(PAMLIBS) \
dbd9e73
 		../cups/$(LIBCUPSSTATIC) $(COMMONLIBS) $(LIBZ) $(LIBPAPER) \
dbd9e73
 		$(LIBMALLOC) $(SERVERLIBS) $(DNSSDLIBS) $(LIBGSSAPI) \
dbd9e73
-		$(LIBWRAP)
dbd9e73
+		$(LIBWRAP) $(SDLIBS)
9829b01
 
9829b01
 
dbd9e73
 #