/*
- * "$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:
*
#include "cupsd.h"
#include <grp.h>
+#if defined(__APPLE__)
+# include <libgen.h>
+#endif /* __APPLE__ */
/*
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 */
{
#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
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...
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.
/*
- * 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 $".
*/