mirror of
https://github.com/systemd/systemd
synced 2024-09-06 16:56:43 +00:00
tree-wide: unsetenv cannot fail
... when called with a valid environment variable name. This means that any time we call it with a fixed string, it is guaranteed to return 0. (Also when the variable is not present in the environment block.)
This commit is contained in:
parent
063f9f0da9
commit
44ee03d111
|
@ -1418,9 +1418,8 @@ static int fixup_environment(void) {
|
|||
return -errno;
|
||||
|
||||
/* The kernels sets HOME=/ for init. Let's undo this. */
|
||||
if (path_equal_ptr(getenv("HOME"), "/") &&
|
||||
unsetenv("HOME") < 0)
|
||||
log_warning_errno(errno, "Failed to unset $HOME: %m");
|
||||
if (path_equal_ptr(getenv("HOME"), "/"))
|
||||
assert_se(unsetenv("HOME") == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -215,9 +215,7 @@ static int acquire_existing_password(const char *user_name, UserRecord *hr, bool
|
|||
return log_error_errno(r, "Failed to store password: %m");
|
||||
|
||||
string_erase(e);
|
||||
|
||||
if (unsetenv("PASSWORD") < 0)
|
||||
return log_error_errno(errno, "Failed to unset $PASSWORD: %m");
|
||||
assert_se(unsetenv("PASSWORD") == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -255,9 +253,7 @@ static int acquire_token_pin(const char *user_name, UserRecord *hr) {
|
|||
return log_error_errno(r, "Failed to store token PIN: %m");
|
||||
|
||||
string_erase(e);
|
||||
|
||||
if (unsetenv("PIN") < 0)
|
||||
return log_error_errno(errno, "Failed to unset $PIN: %m");
|
||||
assert_se(unsetenv("PIN") == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -997,9 +993,7 @@ static int acquire_new_password(
|
|||
return log_error_errno(r, "Failed to store password: %m");
|
||||
|
||||
string_erase(e);
|
||||
|
||||
if (unsetenv("NEWPASSWORD") < 0)
|
||||
return log_error_errno(errno, "Failed to unset $NEWPASSWORD: %m");
|
||||
assert_se(unsetenv("NEWPASSWORD") == 0);
|
||||
|
||||
if (ret)
|
||||
*ret = TAKE_PTR(copy);
|
||||
|
|
|
@ -30,13 +30,12 @@
|
|||
#define SNDBUF_SIZE (8*1024*1024)
|
||||
|
||||
static void unsetenv_all(bool unset_environment) {
|
||||
|
||||
if (!unset_environment)
|
||||
return;
|
||||
|
||||
unsetenv("LISTEN_PID");
|
||||
unsetenv("LISTEN_FDS");
|
||||
unsetenv("LISTEN_FDNAMES");
|
||||
assert_se(unsetenv("LISTEN_PID") == 0);
|
||||
assert_se(unsetenv("LISTEN_FDS") == 0);
|
||||
assert_se(unsetenv("LISTEN_FDNAMES") == 0);
|
||||
}
|
||||
|
||||
_public_ int sd_listen_fds(int unset_environment) {
|
||||
|
@ -548,7 +547,7 @@ _public_ int sd_pid_notify_with_fds(
|
|||
|
||||
finish:
|
||||
if (unset_environment)
|
||||
unsetenv("NOTIFY_SOCKET");
|
||||
assert_se(unsetenv("NOTIFY_SOCKET") == 0);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
@ -672,9 +671,9 @@ _public_ int sd_watchdog_enabled(int unset_environment, uint64_t *usec) {
|
|||
|
||||
finish:
|
||||
if (unset_environment && s)
|
||||
unsetenv("WATCHDOG_USEC");
|
||||
assert_se(unsetenv("WATCHDOG_USEC") == 0);
|
||||
if (unset_environment && p)
|
||||
unsetenv("WATCHDOG_PID");
|
||||
assert_se(unsetenv("WATCHDOG_PID") == 0);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -898,11 +898,11 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
#endif
|
||||
|
||||
(void) unsetenv("USER");
|
||||
(void) unsetenv("LOGNAME");
|
||||
(void) unsetenv("SHELL");
|
||||
(void) unsetenv("HOME");
|
||||
(void) unsetenv("TMPDIR");
|
||||
assert_se(unsetenv("USER") == 0);
|
||||
assert_se(unsetenv("LOGNAME") == 0);
|
||||
assert_se(unsetenv("SHELL") == 0);
|
||||
assert_se(unsetenv("HOME") == 0);
|
||||
assert_se(unsetenv("TMPDIR") == 0);
|
||||
|
||||
can_unshare = have_namespaces();
|
||||
|
||||
|
|
|
@ -184,7 +184,7 @@ static void test_find_executable_full(void) {
|
|||
if (p)
|
||||
assert_se(oldpath = strdup(p));
|
||||
|
||||
assert_se(unsetenv("PATH") >= 0);
|
||||
assert_se(unsetenv("PATH") == 0);
|
||||
|
||||
assert_se(find_executable_full("sh", true, &p) == 0);
|
||||
puts(p);
|
||||
|
@ -347,7 +347,7 @@ static void test_fsck_exists(void) {
|
|||
log_info("/* %s */", __func__);
|
||||
|
||||
/* Ensure we use a sane default for PATH. */
|
||||
unsetenv("PATH");
|
||||
assert_se(unsetenv("PATH") == 0);
|
||||
|
||||
/* fsck.minix is provided by util-linux and will probably exist. */
|
||||
assert_se(fsck_exists("minix") == 1);
|
||||
|
|
|
@ -480,7 +480,7 @@ static void test_in_utc_timezone(void) {
|
|||
assert_se(streq(tzname[0], "CET"));
|
||||
assert_se(streq(tzname[1], "CEST"));
|
||||
|
||||
assert_se(unsetenv("TZ") >= 0);
|
||||
assert_se(unsetenv("TZ") == 0);
|
||||
}
|
||||
|
||||
static void test_map_clock_usec(void) {
|
||||
|
|
|
@ -565,7 +565,7 @@ static int worker_main(Manager *_manager, sd_device_monitor *monitor, sd_device
|
|||
assert(monitor);
|
||||
assert(dev);
|
||||
|
||||
unsetenv("NOTIFY_SOCKET");
|
||||
assert_se(unsetenv("NOTIFY_SOCKET") == 0);
|
||||
|
||||
assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGTERM, -1) >= 0);
|
||||
|
||||
|
|
|
@ -780,10 +780,8 @@ static int run(int argc, char *argv[]) {
|
|||
return log_error_errno(r, "Failed to set $SYSTEMD_ONLY_USERDB: %m");
|
||||
|
||||
log_info("Enabled services: %s", e);
|
||||
} else {
|
||||
if (unsetenv("SYSTEMD_ONLY_USERDB") < 0)
|
||||
return log_error_errno(r, "Failed to unset $SYSTEMD_ONLY_USERDB: %m");
|
||||
}
|
||||
} else
|
||||
assert_se(unsetenv("SYSTEMD_ONLY_USERDB") == 0);
|
||||
|
||||
return dispatch_verb(argc, argv, verbs, NULL);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue