]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/env.c
2 * "$Id: env.c 5245 2006-03-08 13:09:49Z mike $"
4 * Environment management routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 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
[MAX_ENV
]; /* 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...
79 #if defined(__APPLE__)
81 * Add special voodoo magic for MacOS X 10.4 and later - this allows MacOS
82 * X programs to access their bundle resources properly...
84 * This string is replaced in cupsdStartProcess() when we are running on
85 * versions of MacOS X prior to 10.4...
88 cupsdSetString(common_env
, "<CFProcessPath>");
90 #endif /* __APPLE__ */
93 * Set common variables...
96 cupsdSetEnv("CUPS_CACHEDIR", CacheDir
);
97 cupsdSetEnv("CUPS_DATADIR", DataDir
);
98 cupsdSetEnv("CUPS_DOCROOT", DocumentRoot
);
99 cupsdSetEnv("CUPS_FONTPATH", FontPath
);
100 cupsdSetEnv("CUPS_REQUESTROOT", RequestRoot
);
101 cupsdSetEnv("CUPS_SERVERBIN", ServerBin
);
102 cupsdSetEnv("CUPS_SERVERROOT", ServerRoot
);
103 cupsdSetEnv("CUPS_STATEDIR", StateDir
);
104 cupsdSetEnv("DYLD_LIBRARY_PATH", NULL
);
105 cupsdSetEnv("LD_ASSUME_KERNEL", NULL
);
106 cupsdSetEnv("LD_LIBRARY_PATH", NULL
);
107 cupsdSetEnv("LD_PRELOAD", NULL
);
108 cupsdSetEnv("NLSPATH", NULL
);
109 cupsdSetEnvf("PATH", "%s/filter:" CUPS_BINDIR
":" CUPS_SBINDIR
110 ":/bin:/usr/bin", ServerBin
);
111 cupsdSetEnv("SERVER_ADMIN", ServerAdmin
);
112 cupsdSetEnv("SHLIB_PATH", NULL
);
113 cupsdSetEnv("SOFTWARE", CUPS_MINIMAL
);
114 cupsdSetEnv("TMPDIR", TempDir
);
115 cupsdSetEnv("TZ", NULL
);
116 cupsdSetEnv("USER", "root");
117 cupsdSetEnv("VG_ARGS", NULL
);
122 * 'cupsdLoadEnv()' - Copy common environment variables into an array.
125 int /* O - Number of environment variables */
126 cupsdLoadEnv(char *envp
[], /* I - Environment array */
127 int envmax
) /* I - Maximum number of elements */
129 int i
; /* Looping var */
133 * Leave room for a NULL pointer at the end...
139 * Copy pointers to the environment...
142 for (i
= 0; i
< num_common_env
&& i
< envmax
; i
++)
143 envp
[i
] = common_env
[i
];
146 * NULL terminate the environment array and return the number of
147 * elements we added...
157 * 'cupsdSetEnv()' - Set a common environment variable.
161 cupsdSetEnv(const char *name
, /* I - Name of variable */
162 const char *value
) /* I - Value of variable */
164 int i
, /* Looping var */
165 namelen
; /* Length of name */
169 * If "value" is NULL, try getting value from current environment...
173 value
= getenv(name
);
179 * See if this variable has already been defined...
182 for (i
= 0, namelen
= strlen(name
); i
< num_common_env
; i
++)
183 if (!strncmp(common_env
[i
], name
, namelen
) && common_env
[i
][namelen
] == '=')
186 if (i
>= num_common_env
)
192 if (num_common_env
>= (int)(sizeof(common_env
) / sizeof(common_env
[0])))
194 cupsdLogMessage(CUPSD_LOG_ERROR
,
195 "cupsdSetEnv: Too many environment variables set!");
203 * Set the new environment variable...
206 cupsdSetStringf(common_env
+ i
, "%s=%s", name
, value
);
208 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdSetEnv: %s\n", common_env
[i
]);
213 * 'cupsdSetEnvf()' - Set a formatted common environment variable.
217 cupsdSetEnvf(const char *name
, /* I - Name of variable */
218 const char *value
, /* I - Printf-style value of variable */
219 ...) /* I - Additional args as needed */
221 char v
[4096]; /* Formatting string value */
222 va_list ap
; /* Argument pointer */
226 * Format the value string...
230 vsnprintf(v
, sizeof(v
), value
, ap
);
234 * Set the env variable...
237 cupsdSetEnv(name
, v
);
242 * End of "$Id: env.c 5245 2006-03-08 13:09:49Z mike $".