-#if SETENV_LEAKS
-/* We set environment *before* vfork (because we want to use vfork),
- * so we cannot use setenv() - repeated calls to setenv() may leak memory!
- * Using putenv(), and freeing memory after unsetenv() won't leak */
-static void safe_setenv(char **pvar_val, const char *var, const char *val)
-{
- char *var_val = *pvar_val;
-
- if (var_val) {
- bb_unsetenv_and_free(var_val);
- }
- *pvar_val = xasprintf("%s=%s", var, val);
- putenv(*pvar_val);
-}
-#endif
-
-static void SetEnv(struct passwd *pas)
-{
-#if SETENV_LEAKS
- safe_setenv(&G.env_var_user, "USER", pas->pw_name);
- safe_setenv(&G.env_var_home, "HOME", pas->pw_dir);
- /* if we want to set user's shell instead: */
- /*safe_setenv(G.env_var_shell, "SHELL", pas->pw_shell);*/
-#else
- xsetenv("USER", pas->pw_name);
- xsetenv("HOME", pas->pw_dir);
-#endif
- /* currently, we use constant one: */
- /*setenv("SHELL", DEFAULT_SHELL, 1); - done earlier */
-}
-
-static void ChangeUser(struct passwd *pas)
-{
- /* careful: we're after vfork! */
- change_identity(pas); /* - initgroups, setgid, setuid */
- if (chdir(pas->pw_dir) < 0) {
- crondlog(WARN9 "chdir(%s)", pas->pw_dir);
- if (chdir(TMPDIR) < 0) {
- crondlog(DIE9 "chdir(%s)", TMPDIR); /* exits */
- }
- }
-}
-