]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/env.c
df13dab18bcc9b315c93fd7fadd6b898cd9fc96c
2 * "$Id: env.c 4719 2005-09-28 21:12:44Z mike $"
4 * Environment management routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2005 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * cupsdClearEnv() - Clear common environment variables.
27 * cupsdInitEnv() - Initialize the current environment with standard
29 * cupsdLoadEnv() - Copy common environment variables into an array.
30 * cupsdSetEnv() - Set a common environment variable.
31 * cupsdSetEnvf() - Set a formatted common environment variable.
35 * Include necessary headers...
45 static int num_common_env
= 0; /* Number of common env vars */
46 static char *common_env
[100]; /* Common env vars */
50 * 'cupsdClearEnv()' - Clear common environment variables.
56 int i
; /* Looping var */
59 for (i
= 0; i
< num_common_env
; i
++)
60 cupsdClearString(common_env
+ i
);
67 * 'cupsdInitEnv()' - Initialize the current environment with standard variables.
74 * Clear existing environment variables...
81 * Add special voodoo magic for MacOS X - this allows MacOS X programs
82 * to access their bundle resources properly...
85 cupsdSetString(common_env
, "<CFProcessPath>");
87 #endif /* __APPLE__ */
90 * Set common variables...
93 cupsdSetEnv("CUPS_CACHEDIR", CacheDir
);
94 cupsdSetEnv("CUPS_DATADIR", DataDir
);
95 cupsdSetEnv("CUPS_DOCROOT", DocumentRoot
);
96 cupsdSetEnv("CUPS_FONTPATH", FontPath
);
97 cupsdSetEnv("CUPS_REQUESTROOT", RequestRoot
);
98 cupsdSetEnv("CUPS_SERVERBIN", ServerBin
);
99 cupsdSetEnv("CUPS_SERVERROOT", ServerRoot
);
100 cupsdSetEnv("CUPS_STATEDIR", StateDir
);
101 cupsdSetEnv("DYLD_LIBRARY_PATH", NULL
);
102 cupsdSetEnv("LD_ASSUME_KERNEL", NULL
);
103 cupsdSetEnv("LD_LIBRARY_PATH", NULL
);
104 cupsdSetEnv("LD_PRELOAD", NULL
);
105 cupsdSetEnv("NLSPATH", NULL
);
106 cupsdSetEnvf("PATH", "%s/filter:/bin:/usr/bin", ServerBin
);
107 cupsdSetEnv("SHLIB_PATH", NULL
);
108 cupsdSetEnv("SOFTWARE", CUPS_MINIMAL
);
109 cupsdSetEnv("TMPDIR", TempDir
);
110 cupsdSetEnv("TZ", NULL
);
111 cupsdSetEnv("USER", "root");
112 cupsdSetEnv("VG_ARGS", NULL
);
117 * 'cupsdLoadEnv()' - Copy common environment variables into an array.
120 int /* O - Number of environment variables */
121 cupsdLoadEnv(char *envp
[], /* I - Environment array */
122 int envmax
) /* I - Maximum number of elements */
124 int i
; /* Looping var */
128 * Leave room for a NULL pointer at the end...
134 * Copy pointers to the environment...
137 for (i
= 0; i
< num_common_env
&& i
< envmax
; i
++)
138 envp
[i
] = common_env
[i
];
141 * NULL terminate the environment array and return the number of
142 * elements we added...
152 * 'cupsdSetEnv()' - Set a common environment variable.
156 cupsdSetEnv(const char *name
, /* I - Name of variable */
157 const char *value
) /* I - Value of variable */
163 if (num_common_env
>= (int)(sizeof(common_env
) / sizeof(common_env
[0])))
165 cupsdLogMessage(CUPSD_LOG_ERROR
,
166 "cupsdSetEnv: Too many environment variables set!");
171 * If "value" is NULL, try getting value from current environment...
175 value
= getenv(name
);
181 * Set the new environment variable...
184 cupsdSetStringf(common_env
+ num_common_env
, "%s=%s", name
, value
);
186 cupsdLogMessage(CUPSD_LOG_DEBUG
, "cupsdSetEnv: %s\n",
187 common_env
[num_common_env
]);
194 * 'cupsdSetEnvf()' - Set a formatted common environment variable.
198 cupsdSetEnvf(const char *name
, /* I - Name of variable */
199 const char *value
, /* I - Printf-style value of variable */
200 ...) /* I - Additional args as needed */
202 char v
[4096]; /* Formatting string value */
203 va_list ap
; /* Argument pointer */
207 * Format the value string...
211 vsnprintf(v
, sizeof(v
), value
, ap
);
215 * Set the env variable...
218 cupsdSetEnv(name
, v
);
223 * End of "$Id: env.c 4719 2005-09-28 21:12:44Z mike $".