]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/env.c
Merge changes from CUPS 1.4svn-r7874.
[thirdparty/cups.git] / scheduler / env.c
index ec3a8817ddc3770c198404daa3fdaa93300c7b45..3eb9213a56baf3d0d393c44f014f3e872060169d 100644 (file)
@@ -1,34 +1,25 @@
 /*
- * "$Id: env.c 5046 2006-02-01 22:11:58Z mike $"
+ * "$Id: env.c 7673 2008-06-18 22:31:26Z mike $"
  *
  *   Environment management routines for the Common UNIX Printing System (CUPS).
  *
+ *   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.
  */
 
 /*
@@ -47,20 +38,10 @@ 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,17 +55,19 @@ cupsdInitEnv(void)
   * Clear existing environment variables...
   */
 
-  cupsdClearEnv();
+  clear_env();
 
-#if defined(__APPLE__) && __GNUC__ > 3
+#if defined(__APPLE__)
  /*
-  * Add special voodoo magic for MacOS X 10.4 and later - 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>");
   num_common_env = 1;
-#endif /* __APPLE__ && __GNUC__ > 3 */
+#endif /* __APPLE__ */
 
  /*
   * Set common variables...
@@ -158,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...
@@ -180,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", common_env[i]);
 }
 
 
@@ -222,5 +219,22 @@ cupsdSetEnvf(const char *name,             /* I - Name of variable */
 
 
 /*
- * End of "$Id: env.c 5046 2006-02-01 22:11:58Z 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 7673 2008-06-18 22:31:26Z mike $".
  */