]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/env.c
Load cups into easysw/current.
[thirdparty/cups.git] / scheduler / env.c
index df13dab18bcc9b315c93fd7fadd6b898cd9fc96c..a7813f9f176f7b3f975a66e2aaa85a6d98c008c8 100644 (file)
@@ -1,34 +1,25 @@
 /*
- * "$Id: env.c 4719 2005-09-28 21:12:44Z mike $"
+ * "$Id: env.c 6649 2007-07-11 21:46:42Z mike $"
  *
  *   Environment management routines for the Common UNIX Printing System (CUPS).
  *
- *   Copyright 1997-2005 by Easy Software Products, all rights reserved.
+ *   Copyright 2007 by Apple Inc.
+ *   Copyright 1997-2006 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:
  *
- *   cupsdClearEnv() - Clear common environment variables.
  *   cupsdInitEnv()  - Initialize the current environment with standard
  *                     variables.
  *   cupsdLoadEnv()  - Copy common environment variables into an array.
  *   cupsdSetEnv()   - Set a common environment variable.
  *   cupsdSetEnvf()  - Set a formatted common environment variable.
+ *   clear_env()     - Clear common environment variables.
  */
 
 /*
  */
 
 static int     num_common_env = 0;     /* Number of common env vars */
-static char    *common_env[100];       /* Common env vars */
+static char    *common_env[MAX_ENV];   /* Common env vars */
 
 
 /*
- * 'cupsdClearEnv()' - Clear common environment variables.
+ * Local functions...
  */
 
-void
-cupsdClearEnv(void)
-{
-  int  i;                              /* Looping var */
-
-
-  for (i = 0; i < num_common_env; i ++)
-    cupsdClearString(common_env + i);
-
-  num_common_env = 0;
-}
+static void    clear_env(void);
 
 
 /*
@@ -74,12 +55,14 @@ cupsdInitEnv(void)
   * Clear existing environment variables...
   */
 
-  cupsdClearEnv();
+  clear_env();
 
-#ifdef __APPLE__
+#if defined(__APPLE__)
  /*
-  * Add special voodoo magic for MacOS X - this allows MacOS X programs
-  * to access their bundle resources properly...
+  * Add special voodoo magic for MacOS X - this allows MacOS X 
+  * programs to access their bundle resources properly...
+  *
+  * This string is replaced in cupsdStartProcess()...
   */
 
   cupsdSetString(common_env, "<CFProcessPath>");
@@ -103,7 +86,9 @@ cupsdInitEnv(void)
   cupsdSetEnv("LD_LIBRARY_PATH", NULL);
   cupsdSetEnv("LD_PRELOAD", NULL);
   cupsdSetEnv("NLSPATH", NULL);
-  cupsdSetEnvf("PATH", "%s/filter:/bin:/usr/bin", ServerBin);
+  cupsdSetEnvf("PATH", "%s/filter:" CUPS_BINDIR ":" CUPS_SBINDIR
+                       ":/bin:/usr/bin", ServerBin);
+  cupsdSetEnv("SERVER_ADMIN", ServerAdmin);
   cupsdSetEnv("SHLIB_PATH", NULL);
   cupsdSetEnv("SOFTWARE", CUPS_MINIMAL);
   cupsdSetEnv("TMPDIR", TempDir);
@@ -156,16 +141,9 @@ void
 cupsdSetEnv(const char *name,          /* I - Name of variable */
             const char *value)         /* I - Value of variable */
 {
- /*
-  * Check for room...
-  */
+  int  i,                              /* Looping var */
+       namelen;                        /* Length of name */
 
-  if (num_common_env >= (int)(sizeof(common_env) / sizeof(common_env[0])))
-  {
-    cupsdLogMessage(CUPSD_LOG_ERROR,
-                    "cupsdSetEnv: Too many environment variables set!");
-    return;
-  }
 
  /*
   * If "value" is NULL, try getting value from current environment...
@@ -178,15 +156,36 @@ cupsdSetEnv(const char *name,             /* I - Name of variable */
     return;
 
  /*
-  * Set the new environment variable...
+  * See if this variable has already been defined...
   */
 
-  cupsdSetStringf(common_env + num_common_env, "%s=%s", name, value);
+  for (i = 0, namelen = strlen(name); i < num_common_env; i ++)
+    if (!strncmp(common_env[i], name, namelen) && common_env[i][namelen] == '=')
+      break;
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdSetEnv: %s\n",
-                  common_env[num_common_env]);
+  if (i >= num_common_env)
+  {
+   /*
+    * Check for room...
+    */
+
+    if (num_common_env >= (int)(sizeof(common_env) / sizeof(common_env[0])))
+    {
+      cupsdLogMessage(CUPSD_LOG_ERROR,
+                      "cupsdSetEnv: Too many environment variables set!");
+      return;
+    }
+
+    num_common_env ++;
+  }
 
-  num_common_env ++;
+ /*
+  * Set the new environment variable...
+  */
+
+  cupsdSetStringf(common_env + i, "%s=%s", name, value);
+
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdSetEnv: %s\n", common_env[i]);
 }
 
 
@@ -220,5 +219,22 @@ cupsdSetEnvf(const char *name,             /* I - Name of variable */
 
 
 /*
- * End of "$Id: env.c 4719 2005-09-28 21:12:44Z mike $".
+ * 'clear_env()' - Clear common environment variables.
+ */
+
+static void
+clear_env(void)
+{
+  int  i;                              /* Looping var */
+
+
+  for (i = 0; i < num_common_env; i ++)
+    cupsdClearString(common_env + i);
+
+  num_common_env = 0;
+}
+
+
+/*
+ * End of "$Id: env.c 6649 2007-07-11 21:46:42Z mike $".
  */