]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/env.c
2 * "$Id: env.c 7673 2008-06-18 22:31:26Z mike $"
4 * Environment management routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 by Apple Inc.
7 * Copyright 1997-2006 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * cupsdInitEnv() - Initialize the current environment with standard
19 * cupsdLoadEnv() - Copy common environment variables into an array.
20 * cupsdSetEnv() - Set a common environment variable.
21 * cupsdSetEnvf() - Set a formatted common environment variable.
22 * clear_env() - Clear common environment variables.
26 * Include necessary headers...
36 static int num_common_env
= 0; /* Number of common env vars */
37 static char *common_env
[MAX_ENV
]; /* Common env vars */
44 static void clear_env(void);
48 * 'cupsdInitEnv()' - Initialize the current environment with standard variables.
55 * Clear existing environment variables...
60 #if defined(__APPLE__)
62 * Add special voodoo magic for MacOS X - this allows MacOS X
63 * programs to access their bundle resources properly...
65 * This string is replaced in cupsdStartProcess()...
68 cupsdSetString(common_env
, "<CFProcessPath>");
70 #endif /* __APPLE__ */
73 * Set common variables...
76 cupsdSetEnv("CUPS_CACHEDIR", CacheDir
);
77 cupsdSetEnv("CUPS_DATADIR", DataDir
);
78 cupsdSetEnv("CUPS_DOCROOT", DocumentRoot
);
79 cupsdSetEnv("CUPS_FONTPATH", FontPath
);
80 cupsdSetEnv("CUPS_REQUESTROOT", RequestRoot
);
81 cupsdSetEnv("CUPS_SERVERBIN", ServerBin
);
82 cupsdSetEnv("CUPS_SERVERROOT", ServerRoot
);
83 cupsdSetEnv("CUPS_STATEDIR", StateDir
);
84 cupsdSetEnv("DYLD_LIBRARY_PATH", NULL
);
85 cupsdSetEnv("LD_ASSUME_KERNEL", NULL
);
86 cupsdSetEnv("LD_LIBRARY_PATH", NULL
);
87 cupsdSetEnv("LD_PRELOAD", NULL
);
88 cupsdSetEnv("NLSPATH", NULL
);
89 cupsdSetEnvf("PATH", "%s/filter:" CUPS_BINDIR
":" CUPS_SBINDIR
90 ":/bin:/usr/bin", ServerBin
);
91 cupsdSetEnv("SERVER_ADMIN", ServerAdmin
);
92 cupsdSetEnv("SHLIB_PATH", NULL
);
93 cupsdSetEnv("SOFTWARE", CUPS_MINIMAL
);
94 cupsdSetEnv("TMPDIR", TempDir
);
95 cupsdSetEnv("TZ", NULL
);
96 cupsdSetEnv("USER", "root");
97 cupsdSetEnv("VG_ARGS", NULL
);
102 * 'cupsdLoadEnv()' - Copy common environment variables into an array.
105 int /* O - Number of environment variables */
106 cupsdLoadEnv(char *envp
[], /* I - Environment array */
107 int envmax
) /* I - Maximum number of elements */
109 int i
; /* Looping var */
113 * Leave room for a NULL pointer at the end...
119 * Copy pointers to the environment...
122 for (i
= 0; i
< num_common_env
&& i
< envmax
; i
++)
123 envp
[i
] = common_env
[i
];
126 * NULL terminate the environment array and return the number of
127 * elements we added...
137 * 'cupsdSetEnv()' - Set a common environment variable.
141 cupsdSetEnv(const char *name
, /* I - Name of variable */
142 const char *value
) /* I - Value of variable */
144 int i
, /* Looping var */
145 namelen
; /* Length of name */
149 * If "value" is NULL, try getting value from current environment...
153 value
= getenv(name
);
159 * See if this variable has already been defined...
162 for (i
= 0, namelen
= strlen(name
); i
< num_common_env
; i
++)
163 if (!strncmp(common_env
[i
], name
, namelen
) && common_env
[i
][namelen
] == '=')
166 if (i
>= num_common_env
)
172 if (num_common_env
>= (int)(sizeof(common_env
) / sizeof(common_env
[0])))
174 cupsdLogMessage(CUPSD_LOG_ERROR
,
175 "cupsdSetEnv: Too many environment variables set!");
183 * Set the new environment variable...
186 cupsdSetStringf(common_env
+ i
, "%s=%s", name
, value
);
188 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdSetEnv: %s", common_env
[i
]);
193 * 'cupsdSetEnvf()' - Set a formatted common environment variable.
197 cupsdSetEnvf(const char *name
, /* I - Name of variable */
198 const char *value
, /* I - Printf-style value of variable */
199 ...) /* I - Additional args as needed */
201 char v
[4096]; /* Formatting string value */
202 va_list ap
; /* Argument pointer */
206 * Format the value string...
210 vsnprintf(v
, sizeof(v
), value
, ap
);
214 * Set the env variable...
217 cupsdSetEnv(name
, v
);
222 * 'clear_env()' - Clear common environment variables.
228 int i
; /* Looping var */
231 for (i
= 0; i
< num_common_env
; i
++)
232 cupsdClearString(common_env
+ i
);
239 * End of "$Id: env.c 7673 2008-06-18 22:31:26Z mike $".