]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
support Upstart socket activation
authorBrian Norris <briannorris@google.com>
Fri, 27 May 2016 20:07:05 +0000 (13:07 -0700)
committerBrian Norris <briannorris@google.com>
Fri, 27 May 2016 20:07:05 +0000 (13:07 -0700)
Inspired by code here:

https://bugs.launchpad.net/upstart/+bug/1276713

With significant refactoring and bug-fixing.

Notably, Upstart only supports passing a single file descriptor via
UPSTART_FDS, so systems that want to use this support will need to
configure CUPS appropriately in order to use this.

config-scripts/cups-startup.m4
config.h.in
configure
scheduler/client.h
scheduler/main.c
vcnet/config.h
xcode/config.h

index bbd6b891db8378759956eb0a75bfb9ec7958d7fe..051339a5d0eef7c387a15c205fe77a173a99aeae 100644 (file)
@@ -85,6 +85,15 @@ if test x$enable_systemd != xno; then
         fi
 fi
 
+dnl Upstart is also used on Linux (e.g., Chrome OS)
+AC_ARG_ENABLE(upstart, [ --enable-upstart         enable upstart support])
+if test "x$enable_upstart" = "xyes"; then
+       if test "x$have_systemd" = "xyes"; then
+               AC_MSG_ERROR(Cannot support both systemd and upstart.)
+       fi
+       AC_DEFINE(HAVE_UPSTART)
+fi
+
 dnl Solaris uses smf
 SMFMANIFESTDIR=""
 AC_SUBST(SMFMANIFESTDIR)
index 526f91a5eb1611bf2198534b8f733bbc080691ad..918d90f08114f33ecab16d7f352986c1e246f292 100644 (file)
 
 #undef HAVE_SYSTEMD
 
+/*
+ * Do we have upstart support?
+ */
+
+#undef HAVE_UPSTART
+
 
 /*
  * Various scripting languages...
@@ -717,7 +723,7 @@ static __inline int _cups_abs(int i) { return (i < 0 ? -i : i); }
 #  endif /* __GNUC__ || __STDC_VERSION__ */
 #endif /* !HAVE_ABS && !abs */
 
-#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD)
+#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD) || defined(HAVE_UPSTART)
 #  define HAVE_ONDEMAND
 #else
 #  undef HAVE_ONDEMAND
index c3af70dd1c2f525b7daa71222865a2e175eb98f9..96adade7d32f50d4472be06fc21460dbc978bd11 100755 (executable)
--- a/configure
+++ b/configure
@@ -878,6 +878,7 @@ with_dnssd_includes
 enable_launchd
 enable_systemd
 with_systemd
+enable_upstart
 with_smfmanifestdir
 with_rcdir
 with_rclevels
@@ -1560,6 +1561,7 @@ Optional Features:
   --disable-dnssd         disable DNS Service Discovery support using mDNSResponder
   --disable-launchd       disable launchd support
   --disable-systemd       disable systemd support
+ --enable-upstart         enable upstart support
   --enable-page-logging   enable page_log by default
   --disable-browsing      disable Browsing by default
   --disable-default-shared
@@ -8750,7 +8752,7 @@ else
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     since some C++ compilers masquerading as C compilers
     incorrectly reject 9223372036854775807.  */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
                       && LARGE_OFF_T % 2147483647 == 1)
                      ? 1 : -1];
@@ -8796,7 +8798,7 @@ else
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     since some C++ compilers masquerading as C compilers
     incorrectly reject 9223372036854775807.  */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
                       && LARGE_OFF_T % 2147483647 == 1)
                      ? 1 : -1];
@@ -8820,7 +8822,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     since some C++ compilers masquerading as C compilers
     incorrectly reject 9223372036854775807.  */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
                       && LARGE_OFF_T % 2147483647 == 1)
                      ? 1 : -1];
@@ -8865,7 +8867,7 @@ else
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     since some C++ compilers masquerading as C compilers
     incorrectly reject 9223372036854775807.  */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
                       && LARGE_OFF_T % 2147483647 == 1)
                      ? 1 : -1];
@@ -8889,7 +8891,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     since some C++ compilers masquerading as C compilers
     incorrectly reject 9223372036854775807.  */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
                       && LARGE_OFF_T % 2147483647 == 1)
                      ? 1 : -1];
@@ -9210,6 +9212,19 @@ fi
         fi
 fi
 
+# Check whether --enable-upstart was given.
+if test "${enable_upstart+set}" = set; then :
+  enableval=$enable_upstart;
+fi
+
+if test "x$enable_upstart" = "xyes"; then
+       if test "x$have_systemd" = "xyes"; then
+               as_fn_error $? "Cannot support both systemd and upstart." "$LINENO" 5
+       fi
+       $as_echo "#define HAVE_UPSTART 1" >>confdefs.h
+
+fi
+
 SMFMANIFESTDIR=""
 
 
index 174b7271e7efb08b56f0bfaa39a8be2c9f292914..f97f41defa9e627e350a06f0915ec7c51e3111d0 100644 (file)
@@ -80,7 +80,7 @@ typedef struct
   http_addr_t          address;        /* Bind address of socket */
   http_encryption_t    encryption;     /* To encrypt or not to encrypt... */
 #if defined(HAVE_ONDEMAND)
-  int                  on_demand;      /* Is this a socket from launchd/systemd? */
+  int                  on_demand;      /* Is this a socket from launchd/systemd/upstart? */
 #endif /* HAVE_ONDEMAND */
 } cupsd_listener_t;
 
index 81e04ce4990b84241b53e5d3620192b65fbbe305..8d07e53968771c1fad9c04c8073802141cf71d56 100644 (file)
@@ -30,8 +30,6 @@
 #ifdef HAVE_LAUNCH_H
 #  include <launch.h>
 #  include <libgen.h>
-#  define CUPS_KEEPALIVE CUPS_CACHEDIR "/org.cups.cupsd"
-                                       /* Name of the launchd KeepAlive file */
 #  ifdef HAVE_LAUNCH_ACTIVATE_SOCKET
 /* Update when we have a public header we can include */
 extern int launch_activate_socket(const char *name, int **fds, size_t *cnt);
@@ -40,10 +38,13 @@ extern int launch_activate_socket(const char *name, int **fds, size_t *cnt);
 
 #ifdef HAVE_SYSTEMD
 #  include <systemd/sd-daemon.h>
-#  define CUPS_KEEPALIVE CUPS_CACHEDIR "/org.cups.cupsd"
-                                       /* Name of the systemd path file */
 #endif /* HAVE_SYSTEMD */
 
+#ifdef HAVE_ONDEMAND
+#  define CUPS_KEEPALIVE CUPS_CACHEDIR "/org.cups.cupsd"
+                                       /* Name of the KeepAlive file */
+#endif
+
 #if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
 #  include <malloc.h>
 #endif /* HAVE_MALLOC_H && HAVE_MALLINFO */
@@ -242,7 +243,7 @@ main(int  argc,                             /* I - Number of command-line args */
              usage(0);
              break;
 
-          case 'l' : /* Started by launchd/systemd... */
+          case 'l' : /* Started by launchd/systemd/upstart... */
 #if defined(HAVE_ONDEMAND)
              OnDemand   = 1;
              fg         = 1;
@@ -2026,7 +2027,7 @@ service_checkin(void)
   launch_data_free(ld_msg);
   launch_data_free(ld_resp);
 
-#  else /* HAVE_SYSTEMD */
+#  elif defined(HAVE_SYSTEMD)
   int                  i,              /* Looping var */
                        count;          /* Number of listeners */
 
@@ -2054,6 +2055,49 @@ service_checkin(void)
   {
     add_ondemand_listener(SD_LISTEN_FDS_START + i, i);
   }
+#  elif defined(HAVE_UPSTART)
+  const char           *e;             /* Environment var */
+  int                  fd;             /* File descriptor */
+
+  if (!(e = getenv("UPSTART_EVENTS")))
+  {
+    cupsdLogMessage(CUPSD_LOG_ERROR,
+                   "service_checkin: We did not get started via Upstart.");
+    exit(EXIT_FAILURE);
+    return;
+  }
+
+  if (strcasecmp(e, "socket"))
+  {
+    cupsdLogMessage(CUPSD_LOG_ERROR,
+                   "service_checkin: We did not get triggered via an Upstart socket event.");
+    exit(EXIT_FAILURE);
+    return;
+  }
+
+  if (!(e = getenv("UPSTART_FDS")))
+  {
+    cupsdLogMessage(CUPSD_LOG_ERROR,
+                   "service_checkin: Unable to get listener sockets from UPSTART_FDS.");
+    exit(EXIT_FAILURE);
+    return;
+  }
+
+  cupsdLogMessage(CUPSD_LOG_DEBUG, "service_checkin: UPSTART_FDS=%s", e);
+
+  fd = strtol(e, NULL, 10);
+  if (fd < 0) {
+    cupsdLogMessage(CUPSD_LOG_ERROR,
+                   "service_checkin: Could not parse UPSTART_FDS: %s", strerror(errno));
+    exit(EXIT_FAILURE);
+    return;
+  }
+
+  /* Upstart only supportst a single on-demand socket fd */
+  add_ondemand_listener(fd, 0);
+
+#  else
+#  error "Error: defined HAVE_ONDEMAND but no launchd/systemd/upstart selection"
 #  endif /* HAVE_LAUNCH_ACTIVATE_SOCKET */
 }
 
index 0f1291cc59a8cface894c8a689b7be1fe10741aa..a4b01138c2572399491354444d734330c752c52f 100644 (file)
@@ -777,7 +777,7 @@ static __inline int _cups_abs(int i) { return (i < 0 ? -i : i); }
 #  endif /* __GNUC__ || __STDC_VERSION__ */
 #endif /* !HAVE_ABS && !abs */
 
-#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD)
+#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD) || defined(HAVE_UPSTART)
 #  define HAVE_ONDEMAND
 #else
 #  undef HAVE_ONDEMAND
index a0c5c9b3d48c18fbae58441426943490ec701719..7e871a0d03d1df7619c9162306fafbe072cf3884 100644 (file)
@@ -733,7 +733,7 @@ static __inline int _cups_abs(int i) { return (i < 0 ? -i : i); }
 #  endif /* __GNUC__ || __STDC_VERSION__ */
 #endif /* !HAVE_ABS && !abs */
 
-#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD)
+#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD) || defined(HAVE_UPSTART)
 #  define HAVE_ONDEMAND
 #else
 #  undef HAVE_ONDEMAND