]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/process.c
Load cups into easysw/current.
[thirdparty/cups.git] / scheduler / process.c
index d891adf170890945c6ffbb16c98ebc481d360e8a..7462472a6e0a5571c138a428254bbdd5ffd7b1a0 100644 (file)
@@ -1,9 +1,9 @@
 /*
- * "$Id: process.c 5094 2006-02-09 01:00:26Z mike $"
+ * "$Id: process.c 6326 2007-03-11 17:50:18Z mike $"
  *
  *   Process management routines for the Common UNIX Printing System (CUPS).
  *
- *   Copyright 1997-2006 by Easy Software Products, all rights reserved.
+ *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
  *   property of Easy Software Products and are protected by Federal
@@ -35,9 +35,9 @@
 
 #include "cupsd.h"
 #include <grp.h>
-#if defined(__APPLE__) && __GNUC__ < 4
+#if defined(__APPLE__)
 #  include <libgen.h>
-#endif /* __APPLE__ && __GNUC__ < 4 */ 
+#endif /* __APPLE__ */ 
 
 
 /*
@@ -121,6 +121,7 @@ cupsdStartProcess(
     int        outfd,                  /* I - Standard output file descriptor */
     int        errfd,                  /* I - Standard error file descriptor */
     int        backfd,                 /* I - Backchannel file descriptor */
+    int        sidefd,                 /* I - Sidechannel file descriptor */
     int        root,                   /* I - Run as root? */
     int        *pid)                   /* O - Process ID */
 {
@@ -128,45 +129,47 @@ cupsdStartProcess(
 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
   struct sigaction action;             /* POSIX signal handler */
 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
-#if defined(__APPLE__) && __GNUC__ < 4
-  int          envc;                   /* Number of environment variables */
+#if defined(__APPLE__)
   char         processPath[1024],      /* CFProcessPath environment variable */
                linkpath[1024];         /* Link path for symlinks... */
   int          linkbytes;              /* Bytes for link path */
-#endif /* __APPLE__ && __GNUC__ < 4 */
+#endif /* __APPLE__ */
 
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2,
                   "cupsdStartProcess(\"%s\", %p, %p, %d, %d, %d)",
                   command, argv, envp, infd, outfd, errfd);
 
-#if defined(__APPLE__) && __GNUC__ < 4
- /*
-  * Add special voodoo magic for MacOS X 10.3 and earlier - this allows
-  * MacOS X programs to access their bundle resources properly...
-  */
-
-  if ((linkbytes = readlink(command, linkpath, sizeof(linkpath) - 1)) > 0)
+#if defined(__APPLE__)
+  if (envp)
   {
    /*
-    * Yes, this is a symlink to the actual program, nul-terminate and
-    * use it...
+    * Add special voodoo magic for MacOS X - this allows MacOS X 
+    * programs to access their bundle resources properly...
     */
 
-    linkpath[linkbytes] = '\0';
+    if ((linkbytes = readlink(command, linkpath, sizeof(linkpath) - 1)) > 0)
+    {
+     /*
+      * Yes, this is a symlink to the actual program, nul-terminate and
+      * use it...
+      */
+
+      linkpath[linkbytes] = '\0';
 
-    if (linkpath[0] == '/')
-      snprintf(processPath, sizeof(processPath), "CFProcessPath=%s",
-              linkpath);
+      if (linkpath[0] == '/')
+       snprintf(processPath, sizeof(processPath), "CFProcessPath=%s",
+                linkpath);
+      else
+       snprintf(processPath, sizeof(processPath), "CFProcessPath=%s/%s",
+                dirname((char *)command), linkpath);
+    }
     else
-      snprintf(processPath, sizeof(processPath), "CFProcessPath=%s/%s",
-              dirname(command), linkpath);
-  }
-  else
-    snprintf(processPath, sizeof(processPath), "CFProcessPath=%s", command);
+      snprintf(processPath, sizeof(processPath), "CFProcessPath=%s", command);
 
-  envp[0] = processPath;               /* Replace <CFProcessPath> string */
-#endif /* __APPLE__ && __GNUC__ > 3 */
+    envp[0] = processPath;             /* Replace <CFProcessPath> string */
+  }
+#endif /* __APPLE__ */
 
  /*
   * Block signals before forking...
@@ -215,6 +218,12 @@ cupsdStartProcess(
         open("/dev/null", O_RDWR);
       fcntl(3, F_SETFL, O_NDELAY);
     }
+    if (sidefd != 4 && sidefd > 0)
+    {
+      close(4);
+      dup(sidefd);
+      fcntl(4, F_SETFL, O_NDELAY);
+    }
 
    /*
     * Change the priority of the process based on the FilterNice setting.
@@ -342,5 +351,5 @@ compare_procs(cupsd_proc_t *a,              /* I - First process */
 
 
 /*
- * End of "$Id: process.c 5094 2006-02-09 01:00:26Z mike $".
+ * End of "$Id: process.c 6326 2007-03-11 17:50:18Z mike $".
  */