]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Fix a random crash in the scheduler when not using systemd (STR #4484)
authormsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Wed, 12 Nov 2014 14:35:59 +0000 (14:35 +0000)
committermsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Wed, 12 Nov 2014 14:35:59 +0000 (14:35 +0000)
git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@12245 a1ca3aef-8c08-0410-bb20-df032aa958be

CHANGES-2.0.txt
scheduler/main.c
xcode/CUPS.xcodeproj/project.pbxproj
xcode/config.h

index 52dc04cf4a3b9ff32cd98aaf297c99520e86c614..41e5fca203ed0df86f5f4054bd479c43681b8d92 100644 (file)
@@ -13,6 +13,8 @@ CHANGES IN CUPS V2.0.1
        - Fixed a crash in ippAttributeString (<rdar://problem/17903871>)
        - Fixed a crash in the scheduler on Linux/*BSD if colord was not running
          (STR #4496)
+       - Fixed a random crash in the scheduler when not using systemd
+         (STR #4484)
        - Added systemd support for cups-lpd (STR #4493)
        - The scheduler did not honor the FatalErrors directive for mis-
          configured Group and SystemGroup values (STR #4495)
index 78243def0e54ae3eb06590ad3ee45b614ba0dea9..21985b228b708399f95f067b1879add8ec3fd1ab 100644 (file)
@@ -100,7 +100,11 @@ main(int  argc,                            /* I - Number of command-line args */
 {
   int                  i;              /* Looping var */
   char                 *opt;           /* Option character */
-  int                  fg;             /* Run in the foreground */
+  int                  close_all = 1,  /* Close all file descriptors? */
+                       disconnect = 1, /* Disconnect from controlling terminal? */
+                       fg = 0,         /* Run in foreground? */
+                       run_as_child = 0;
+                                       /* Running as child process? */
   int                  fds;            /* Number of ready descriptors */
   cupsd_client_t       *con;           /* Current client */
   cupsd_job_t          *job;           /* Current job */
@@ -116,8 +120,6 @@ main(int  argc,                             /* I - Number of command-line args */
 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
   struct sigaction     action;         /* Actions for POSIX signals */
 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
-  int                  run_as_child = 0;
-                                       /* Needed for background fork/exec */
 #ifdef __APPLE__
   int                  use_sysman = 1; /* Use system management functions? */
 #else
@@ -150,8 +152,10 @@ main(int  argc,                            /* I - Number of command-line args */
 #ifdef HAVE_LAUNCHD
   if (getenv("CUPSD_LAUNCHD"))
   {
-    OnDemand = 1;
-    fg       = 1;
+    OnDemand   = 1;
+    fg         = 1;
+    close_all  = 0;
+    disconnect = 0;
   }
 #endif /* HAVE_LAUNCHD */
 
@@ -162,7 +166,8 @@ main(int  argc,                             /* I - Number of command-line args */
        {
          case 'C' : /* Run as child with config file */
               run_as_child = 1;
-             fg           = -1;
+             fg           = 1;
+             close_all    = 0;
 
          case 'c' : /* Configuration file */
              i ++;
@@ -217,11 +222,14 @@ main(int  argc,                           /* I - Number of command-line args */
              break;
 
           case 'f' : /* Run in foreground... */
-             fg = 1;
+             fg         = 1;
+             disconnect = 0;
+             close_all  = 0;
              break;
 
           case 'F' : /* Run in foreground, but disconnect from terminal... */
-             fg = -1;
+             fg        = 1;
+             close_all = 0;
              break;
 
           case 'h' : /* Show usage/help */
@@ -230,12 +238,16 @@ main(int  argc,                           /* I - Number of command-line args */
 
           case 'l' : /* Started by launchd/systemd... */
 #if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD)
-             OnDemand = 1;
-             fg       = 1;
+             OnDemand   = 1;
+             fg         = 1;
+             close_all  = 0;
+             disconnect = 0;
 #else
              _cupsLangPuts(stderr, _("cupsd: On-demand support not compiled "
                                      "in, running in normal mode."));
-              fg = 0;
+              fg         = 0;
+             disconnect = 1;
+             close_all  = 1;
 #endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */
              break;
 
@@ -244,6 +256,8 @@ main(int  argc,                             /* I - Number of command-line args */
                     "use only!\n", stderr);
              stop_scheduler = 1;
              fg             = 1;
+             disconnect     = 0;
+             close_all      = 0;
              break;
 
           case 'P' : /* Disable security profiles */
@@ -285,6 +299,8 @@ main(int  argc,                             /* I - Number of command-line args */
           case 't' : /* Test the cupsd.conf file... */
              TestConfigFile = 1;
              fg             = 1;
+             disconnect     = 0;
+             close_all      = 0;
              break;
 
          default : /* Unknown option */
@@ -332,8 +348,57 @@ main(int  argc,                            /* I - Number of command-line args */
     free(filename);
   }
 
+  if (disconnect)
+  {
+   /*
+    * Make sure we aren't tying up any filesystems...
+    */
+
+    chdir("/");
+
+   /*
+    * Disconnect from the controlling terminal...
+    */
+
+    setsid();
+  }
+
+  if (close_all)
+  {
+   /*
+    * Close all open files...
+    */
+
+    getrlimit(RLIMIT_NOFILE, &limit);
+
+    for (i = 0; i < (int)limit.rlim_cur && i < 1024; i ++)
+      close(i);
+
+   /*
+    * Redirect stdin/out/err to /dev/null...
+    */
+
+    if ((i = open("/dev/null", O_RDONLY)) != 0)
+    {
+      dup2(i, 0);
+      close(i);
+    }
+
+    if ((i = open("/dev/null", O_WRONLY)) != 1)
+    {
+      dup2(i, 1);
+      close(i);
+    }
+
+    if ((i = open("/dev/null", O_WRONLY)) != 2)
+    {
+      dup2(i, 2);
+      close(i);
+    }
+  }
+
  /*
-  * If the user hasn't specified "-f", run in the background...
+  * Run in the background as needed...
   */
 
   if (!fg)
@@ -408,74 +473,17 @@ main(int  argc,                           /* I - Number of command-line args */
 #endif /* __OpenBSD__ && OpenBSD < 201211 */
 
    /*
-    * Since CoreFoundation and DBUS both create fork-unsafe data on execution of
-    * a program, and since this kind of really unfriendly behavior seems to be
-    * more common these days in system libraries, we need to re-execute the
-    * background cupsd with the "-C" option to avoid problems.  Unfortunately,
-    * we also have to assume that argv[0] contains the name of the cupsd
-    * executable - there is no portable way to get the real pathname...
+    * Since many system libraries create fork-unsafe data on execution of a
+    * program, we need to re-execute the background cupsd with the "-C" and "-s"
+    * options to avoid problems.  Unfortunately, we also have to assume that
+    * argv[0] contains the name of the cupsd executable - there is no portable
+    * way to get the real pathname...
     */
 
-    execlp(argv[0], argv[0], "-C", ConfigurationFile, (char *)0);
+    execlp(argv[0], argv[0], "-C", ConfigurationFile, "-s", CupsFilesFile, (char *)0);
     exit(errno);
   }
 
-  if (fg < 1)
-  {
-   /*
-    * Make sure we aren't tying up any filesystems...
-    */
-
-    chdir("/");
-
-#ifndef DEBUG
-   /*
-    * Disable core dumps...
-    */
-
-    getrlimit(RLIMIT_CORE, &limit);
-    limit.rlim_cur = 0;
-    setrlimit(RLIMIT_CORE, &limit);
-
-   /*
-    * Disconnect from the controlling terminal...
-    */
-
-    setsid();
-
-   /*
-    * Close all open files...
-    */
-
-    getrlimit(RLIMIT_NOFILE, &limit);
-
-    for (i = 0; i < limit.rlim_cur && i < 1024; i ++)
-      close(i);
-
-   /*
-    * Redirect stdin/out/err to /dev/null...
-    */
-
-    if ((i = open("/dev/null", O_RDONLY)) != 0)
-    {
-      dup2(i, 0);
-      close(i);
-    }
-
-    if ((i = open("/dev/null", O_WRONLY)) != 1)
-    {
-      dup2(i, 1);
-      close(i);
-    }
-
-    if ((i = open("/dev/null", O_WRONLY)) != 2)
-    {
-      dup2(i, 2);
-      close(i);
-    }
-#endif /* DEBUG */
-  }
-
  /*
   * Set the timezone info...
   */
index 52509f2c35f2aba5b81f853add2e40b8c7af8c02..e48390b2b4996aaccf5c92d1e87472552e4d00b0 100644 (file)
                724379C41333FFC7009631B9 /* usb-darwin.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "usb-darwin.c"; path = "../backend/usb-darwin.c"; sourceTree = "<group>"; };
                724379C51333FFC7009631B9 /* usb.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = usb.c; path = ../backend/usb.c; sourceTree = "<group>"; };
                724379CA1334000E009631B9 /* ieee1284.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ieee1284.c; path = ../backend/ieee1284.c; sourceTree = "<group>"; };
+               72496E161A13A03B0051899C /* org.cups.cups-lpd.socket */ = {isa = PBXFileReference; lastKnownFileType = text; name = "org.cups.cups-lpd.socket"; path = "../scheduler/org.cups.cups-lpd.socket"; sourceTree = SOURCE_ROOT; };
+               72496E171A13A03B0051899C /* org.cups.cups-lpdAT.service.in */ = {isa = PBXFileReference; lastKnownFileType = text; name = "org.cups.cups-lpdAT.service.in"; path = "../scheduler/org.cups.cups-lpdAT.service.in"; sourceTree = SOURCE_ROOT; };
                7258EAE2134594C4009286F1 /* rastertopwg */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = rastertopwg; sourceTree = BUILT_PRODUCTS_DIR; };
                7258EAEC134594EB009286F1 /* rastertopwg.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = rastertopwg.c; path = ../filter/rastertopwg.c; sourceTree = "<group>"; };
                726AD6F7135E88F0002C930D /* ippserver */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = ippserver; sourceTree = BUILT_PRODUCTS_DIR; };
                                72E65BDC18DC852700097E89 /* Makefile */,
                                7226369B18AE6D19004ED309 /* org.cups.cups-lpd.plist */,
                                72E65BD518DC818400097E89 /* org.cups.cups-lpd.plist.in */,
+                               72496E171A13A03B0051899C /* org.cups.cups-lpdAT.service.in */,
+                               72496E161A13A03B0051899C /* org.cups.cups-lpd.socket */,
                                72E65BD618DC818400097E89 /* org.cups.cupsd.path.in */,
                                7226369C18AE6D19004ED309 /* org.cups.cupsd.plist */,
                                72E65BD718DC818400097E89 /* org.cups.cupsd.service.in */,
index affa9bc9b28981bb4f81d05a5b2f3eff5bc66f2f..58b9c9b463b6a41624f8f881b27cab5c8761e3a5 100644 (file)
 
 #define HAVE_LAUNCH_H 1
 #define HAVE_LAUNCHD 1
-#undef HAVE_LAUNCH_ACTIVATE_SOCKET
+#define HAVE_LAUNCH_ACTIVATE_SOCKET 1
 
 
 /*