]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/process.c
Load cups into easysw/current.
[thirdparty/cups.git] / scheduler / process.c
index 614ee7ad2b8c80b7b3fb5de5ad23b799f32eeb4f..6ea6e150aa1c79fba8bfeafd48f64a8367ccc8e2 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: process.c 5046 2006-02-01 22:11:58Z mike $"
+ * "$Id: process.c 6649 2007-07-11 21:46:42Z mike $"
  *
  *   Process management routines for the Common UNIX Printing System (CUPS).
  *
- *   Copyright 1997-2006 by Easy Software Products, all rights reserved.
+ *   Copyright 2007 by Apple Inc.
+ *   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
- *   copyright law.  Distribution and use rights are outlined in the file
- *   "LICENSE.txt" which should have been included with this file.  If this
- *   file is missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
+ *   property of Apple Inc. and are protected by Federal copyright
+ *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ *   which should have been included with this file.  If this file is
+ *   file is missing or damaged, see the license at "http://www.cups.org/".
  *
  * Contents:
  *
@@ -35,6 +26,9 @@
 
 #include "cupsd.h"
 #include <grp.h>
+#if defined(__APPLE__)
+#  include <libgen.h>
+#endif /* __APPLE__ */ 
 
 
 /*
@@ -118,6 +112,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 */
 {
@@ -125,34 +120,26 @@ 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...
-  */
-
-  for (envc = 0; envc < MAX_ENV && envp[envc]; envc ++);
-    /* All callers pass in a MAX_ENV element array of environment strings */
-
-  if (envc < (MAX_ENV - 1))
+#if defined(__APPLE__)
+  if (envp)
   {
    /*
-    * We have room, try to read the symlink path for this command...
+    * Add special voodoo magic for MacOS X - this allows MacOS X 
+    * programs to access their bundle resources properly...
     */
 
-    if ((linkbytes = readlink(linkpath, sizeof(linkpath) - 1)) > 0)
+    if ((linkbytes = readlink(command, linkpath, sizeof(linkpath) - 1)) > 0)
     {
      /*
       * Yes, this is a symlink to the actual program, nul-terminate and
@@ -162,19 +149,18 @@ cupsdStartProcess(
       linkpath[linkbytes] = '\0';
 
       if (linkpath[0] == '/')
-        snprintf(processPath, sizeof(processPath), "CFProcessPath=%s",
-                linkpath);
+       snprintf(processPath, sizeof(processPath), "CFProcessPath=%s",
+                linkpath);
       else
-        snprintf(processPath, sizeof(processPath), "CFProcessPath=%s/%s",
-                dirname(command), linkpath);
+       snprintf(processPath, sizeof(processPath), "CFProcessPath=%s/%s",
+                dirname((char *)command), linkpath);
     }
     else
       snprintf(processPath, sizeof(processPath), "CFProcessPath=%s", command);
 
-    envp[envc++] = processPath;
-    envp[envc]   = NULL;
+    envp[0] = processPath;             /* Replace <CFProcessPath> string */
   }
-#endif /* __APPLE__ && __GNUC__ > 3 */
+#endif /* __APPLE__ */
 
  /*
   * Block signals before forking...
@@ -223,6 +209,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.
@@ -350,5 +342,5 @@ compare_procs(cupsd_proc_t *a,              /* I - First process */
 
 
 /*
- * End of "$Id: process.c 5046 2006-02-01 22:11:58Z mike $".
+ * End of "$Id: process.c 6649 2007-07-11 21:46:42Z mike $".
  */