At least glibc setenv(3) can fail when system runs out of memory.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
static inline void xsetenv(char const *name, char const *val, int overwrite)
{
if (setenv(name, val, overwrite) != 0)
- err(EXIT_FAILURE, "failed to set the %s environment variable", name);
+ err(EXIT_FAILURE, _("failed to set the %s environment variable"), name);
}
#endif /* UTIL_LINUX_ENV_H */
FD_SET(STDIN_FILENO, &in);
select(1, &in, NULL, &in, NULL);
- setenv("LESS", "FRSX", 0);
+ if (setenv("LESS", "FRSX", 0) != 0)
+ warn(_("failed to set the %s environment variable"), "LESS");
}
static void wait_for_pager(void)
#include "pathnames.h"
#include "strutils.h"
#include "nls.h"
+#include "env.h"
#include "xalloc.h"
#include "all-io.h"
#include "fileutils.h"
memset(environ, 0, sizeof(char *));
}
- setenv("HOME", pwd->pw_dir, 0); /* legal to override */
- setenv("USER", pwd->pw_name, 1);
- setenv("SHELL", pwd->pw_shell, 1);
- setenv("TERM", termenv ? termenv : "dumb", 1);
+ xsetenv("HOME", pwd->pw_dir, 0); /* legal to override */
+ xsetenv("USER", pwd->pw_name, 1);
+ xsetenv("SHELL", pwd->pw_shell, 1);
+ xsetenv("TERM", termenv ? termenv : "dumb", 1);
free(termenv);
if (pwd->pw_uid)
- logindefs_setenv("PATH", "ENV_PATH", _PATH_DEFPATH);
+ if (logindefs_setenv("PATH", "ENV_PATH", _PATH_DEFPATH) != 0)
+ err(EXIT_FAILURE, _("failed to set the %s environment variable"), "PATH");
else if (logindefs_setenv("PATH", "ENV_ROOTPATH", NULL) != 0)
- logindefs_setenv("PATH", "ENV_SUPATH", _PATH_DEFPATH_ROOT);
+ if (logindefs_setenv("PATH", "ENV_SUPATH", _PATH_DEFPATH_ROOT) != 0)
+ err(EXIT_FAILURE, _("failed to set the %s environment variable"), "PATH");
/* mailx will give a funny error msg if you forget this one */
len = snprintf(tmp, sizeof(tmp), "%s/%s", _PATH_MAILDIR, pwd->pw_name);
if (len > 0 && (size_t) len < sizeof(tmp))
- setenv("MAIL", tmp, 0);
+ xsetenv("MAIL", tmp, 0);
/* LOGNAME is not documented in login(1) but HP-UX 6.5 does it. We'll
* not allow modifying it.
*/
- setenv("LOGNAME", pwd->pw_name, 1);
+ xsetenv("LOGNAME", pwd->pw_name, 1);
env = pam_getenvlist(cxt->pamh);
for (i = 0; env && env[i]; i++)
r = logindefs_setenv("PATH", "ENV_SUPATH", _PATH_DEFPATH_ROOT);
if (r != 0)
- err (EXIT_FAILURE, _("failed to set PATH"));
+ err (EXIT_FAILURE, _("failed to set the %s environment variable"), "PATH");
}
/* Update `environ' for the new shell based on PW, with SHELL being
#include "c.h"
#include "closestream.h"
+#include "env.h"
#include "nls.h"
#include "pathnames.h"
#ifdef USE_PLYMOUTH_SUPPORT
int fd;
if ((con->flags & CON_SERIAL) == 0) {
- setenv("TERM", "linux", 1);
+ xsetenv("TERM", "linux", 1);
return;
}
if (con->flags & CON_NOTTY) {
- setenv("TERM", "dumb", 1);
+ xsetenv("TERM", "dumb", 1);
return;
}
#if defined (__s390__) || defined (__s390x__)
- setenv("TERM", "dumb", 1);
+ xsetenv("TERM", "dumb", 1);
#else
- setenv("TERM", "vt102", 1);
+ xsetenv("TERM", "vt102", 1);
#endif
tio = &con->tio;
fd = con->fd;
if (getcwd(home, sizeof(home)) == NULL)
strcpy(home, "/");
- setenv("HOME", home, 1);
- setenv("LOGNAME", "root", 1);
- setenv("USER", "root", 1);
+ xsetenv("HOME", home, 1);
+ xsetenv("LOGNAME", "root", 1);
+ xsetenv("USER", "root", 1);
if (!profile)
- setenv("SHLVL","0",1);
+ xsetenv("SHLVL","0",1);
/*
* Try to execute a shell.
*/
- setenv("SHELL", su_shell, 1);
+ xsetenv("SHELL", su_shell, 1);
unmask_signal(SIGINT, &saved_sigint);
unmask_signal(SIGTSTP, &saved_sigtstp);
unmask_signal(SIGQUIT, &saved_sigquit);
execl(su_shell, shell, NULL);
warn(_("failed to execute %s"), su_shell);
- setenv("SHELL", "/bin/sh", 1);
+ xsetenv("SHELL", "/bin/sh", 1);
execl("/bin/sh", profile ? "-sh" : "sh", NULL);
warn(_("failed to execute %s"), "/bin/sh");
}
#include "strutils.h"
#include "hwclock.h"
#include "timeutils.h"
+#include "env.h"
#ifdef HAVE_LIBAUDIT
#include <libaudit.h>
zone = getenv("TZ"); /* remember original time zone */
if (universal) {
/* Set timezone to UTC */
- setenv("TZ", "", TRUE);
+ xsetenv("TZ", "", TRUE);
/*
* Note: tzset() gets called implicitly by the time code,
* but only the first time. When changing the environment
}
/* now put back the original zone. */
if (zone)
- setenv("TZ", zone, TRUE);
+ xsetenv("TZ", zone, TRUE);
else
unsetenv("TZ");
tzset();
#include "c.h"
#include "closestream.h"
+#include "env.h"
#include "nls.h"
#include "optutils.h"
#include "pathnames.h"
* with the system clock (which always uses UTC).
*/
if (ctl->clock_mode == CM_UTC)
- setenv("TZ", "UTC", 1);
+ xsetenv("TZ", "UTC", 1);
tzset();
/* Read rtc and system clocks "at the same time", or as
* precisely (+/- a second) as we can read them.
#include "widechar.h"
#include "ttyutils.h"
#include "color-names.h"
+#include "env.h"
#ifdef USE_PLYMOUTH_SUPPORT
# include "plymouth-ctrl.h"
op->term = DEFAULT_STERM;
}
- setenv("TERM", op->term, 1);
+ if (setenv("TERM", op->term, 1) != 0)
+ log_err(_("failed to set the %s environment variable"), "TERM");
}
/* Initialize termios settings. */