]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/env.c
b9c49dc3fabd5ab16821c9a3db2c29acdd2fd2b7
2 * "$Id: env.c 5305 2006-03-18 03:05:12Z 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 * cupsdInitEnv() - Initialize the current environment with standard
28 * cupsdLoadEnv() - Copy common environment variables into an array.
29 * cupsdSetEnv() - Set a common environment variable.
30 * cupsdSetEnvf() - Set a formatted common environment variable.
31 * clear_env() - Clear common environment variables.
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 */
53 static void clear_env(void);
57 * 'cupsdInitEnv()' - Initialize the current environment with standard variables.
64 * Clear existing environment variables...
69 #if defined(__APPLE__)
71 * Add special voodoo magic for MacOS X 10.4 and later - this allows MacOS
72 * X programs to access their bundle resources properly...
74 * This string is replaced in cupsdStartProcess() when we are running on
75 * versions of MacOS X prior to 10.4...
78 cupsdSetString(common_env
, "<CFProcessPath>");
80 #endif /* __APPLE__ */
83 * Set common variables...
86 cupsdSetEnv("CUPS_CACHEDIR", CacheDir
);
87 cupsdSetEnv("CUPS_DATADIR", DataDir
);
88 cupsdSetEnv("CUPS_DOCROOT", DocumentRoot
);
89 cupsdSetEnv("CUPS_FONTPATH", FontPath
);
90 cupsdSetEnv("CUPS_REQUESTROOT", RequestRoot
);
91 cupsdSetEnv("CUPS_SERVERBIN", ServerBin
);
92 cupsdSetEnv("CUPS_SERVERROOT", ServerRoot
);
93 cupsdSetEnv("CUPS_STATEDIR", StateDir
);
94 cupsdSetEnv("DYLD_LIBRARY_PATH", NULL
);
95 cupsdSetEnv("LD_ASSUME_KERNEL", NULL
);
96 cupsdSetEnv("LD_LIBRARY_PATH", NULL
);
97 cupsdSetEnv("LD_PRELOAD", NULL
);
98 cupsdSetEnv("NLSPATH", NULL
);
99 cupsdSetEnvf("PATH", "%s/filter:" CUPS_BINDIR
":" CUPS_SBINDIR
100 ":/bin:/usr/bin", ServerBin
);
101 cupsdSetEnv("SERVER_ADMIN", ServerAdmin
);
102 cupsdSetEnv("SHLIB_PATH", NULL
);
103 cupsdSetEnv("SOFTWARE", CUPS_MINIMAL
);
104 cupsdSetEnv("TMPDIR", TempDir
);
105 cupsdSetEnv("TZ", NULL
);
106 cupsdSetEnv("USER", "root");
107 cupsdSetEnv("VG_ARGS", NULL
);
112 * 'cupsdLoadEnv()' - Copy common environment variables into an array.
115 int /* O - Number of environment variables */
116 cupsdLoadEnv(char *envp
[], /* I - Environment array */
117 int envmax
) /* I - Maximum number of elements */
119 int i
; /* Looping var */
123 * Leave room for a NULL pointer at the end...
129 * Copy pointers to the environment...
132 for (i
= 0; i
< num_common_env
&& i
< envmax
; i
++)
133 envp
[i
] = common_env
[i
];
136 * NULL terminate the environment array and return the number of
137 * elements we added...
147 * 'cupsdSetEnv()' - Set a common environment variable.
151 cupsdSetEnv(const char *name
, /* I - Name of variable */
152 const char *value
) /* I - Value of variable */
154 int i
, /* Looping var */
155 namelen
; /* Length of name */
159 * If "value" is NULL, try getting value from current environment...
163 value
= getenv(name
);
169 * See if this variable has already been defined...
172 for (i
= 0, namelen
= strlen(name
); i
< num_common_env
; i
++)
173 if (!strncmp(common_env
[i
], name
, namelen
) && common_env
[i
][namelen
] == '=')
176 if (i
>= num_common_env
)
182 if (num_common_env
>= (int)(sizeof(common_env
) / sizeof(common_env
[0])))
184 cupsdLogMessage(CUPSD_LOG_ERROR
,
185 "cupsdSetEnv: Too many environment variables set!");
193 * Set the new environment variable...
196 cupsdSetStringf(common_env
+ i
, "%s=%s", name
, value
);
198 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdSetEnv: %s\n", common_env
[i
]);
203 * 'cupsdSetEnvf()' - Set a formatted common environment variable.
207 cupsdSetEnvf(const char *name
, /* I - Name of variable */
208 const char *value
, /* I - Printf-style value of variable */
209 ...) /* I - Additional args as needed */
211 char v
[4096]; /* Formatting string value */
212 va_list ap
; /* Argument pointer */
216 * Format the value string...
220 vsnprintf(v
, sizeof(v
), value
, ap
);
224 * Set the env variable...
227 cupsdSetEnv(name
, v
);
232 * 'clear_env()' - Clear common environment variables.
238 int i
; /* Looping var */
241 for (i
= 0; i
< num_common_env
; i
++)
242 cupsdClearString(common_env
+ i
);
249 * End of "$Id: env.c 5305 2006-03-18 03:05:12Z mike $".