summaryrefslogtreecommitdiff
path: root/src/test/test-env-util.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-01-31 23:33:06 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-02-01 01:13:44 +0900
commitcfd1c6e26280f27454a0759853befee08382bf7d (patch)
tree30e43e868aacea8b98bec27f46481353d5163cde /src/test/test-env-util.c
parent2824374f952ef23d82403ee33b8604cac907903f (diff)
downloadsystemd-cfd1c6e26280f27454a0759853befee08382bf7d.tar.gz
env-util: introduce env_update_systemd_exec_pid()
Will be used in later commits.
Diffstat (limited to 'src/test/test-env-util.c')
-rw-r--r--src/test/test-env-util.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/test/test-env-util.c b/src/test/test-env-util.c
index 755aa069de..ce215fdd36 100644
--- a/src/test/test-env-util.c
+++ b/src/test/test-env-util.c
@@ -4,6 +4,8 @@
#include "fd-util.h"
#include "fileio.h"
#include "fs-util.h"
+#include "parse-util.h"
+#include "process-util.h"
#include "serialize.h"
#include "string-util.h"
#include "strv.h"
@@ -335,6 +337,41 @@ static void test_env_assignment_is_valid(void) {
assert_se(!env_assignment_is_valid("głąb=printf \"\x1b]0;<mock-chroot>\x07<mock-chroot>\""));
}
+static void test_setenv_systemd_exec_pid(void) {
+ _cleanup_free_ char *saved = NULL;
+ const char *e;
+ pid_t p;
+
+ log_info("/* %s */", __func__);
+
+ e = getenv("SYSTEMD_EXEC_PID");
+ if (e)
+ assert_se(saved = strdup(e));
+
+ assert_se(unsetenv("SYSTEMD_EXEC_PID") >= 0);
+ assert_se(setenv_systemd_exec_pid(true) == 0);
+ assert_se(!getenv("SYSTEMD_EXEC_PID"));
+
+ assert_se(setenv("SYSTEMD_EXEC_PID", "*", 1) >= 0);
+ assert_se(setenv_systemd_exec_pid(true) == 0);
+ assert_se(e = getenv("SYSTEMD_EXEC_PID"));
+ assert_se(streq(e, "*"));
+
+ assert_se(setenv("SYSTEMD_EXEC_PID", "123abc", 1) >= 0);
+ assert_se(setenv_systemd_exec_pid(true) == 1);
+ assert_se(e = getenv("SYSTEMD_EXEC_PID"));
+ assert_se(parse_pid(e, &p) >= 0);
+ assert_se(p == getpid_cached());
+
+ assert_se(unsetenv("SYSTEMD_EXEC_PID") >= 0);
+ assert_se(setenv_systemd_exec_pid(false) == 1);
+ assert_se(e = getenv("SYSTEMD_EXEC_PID"));
+ assert_se(parse_pid(e, &p) >= 0);
+ assert_se(p == getpid_cached());
+
+ assert_se(set_unset_env("SYSTEMD_EXEC_PID", saved, 1) >= 0);
+}
+
int main(int argc, char *argv[]) {
test_setup_logging(LOG_DEBUG);
@@ -353,6 +390,7 @@ int main(int argc, char *argv[]) {
test_env_name_is_valid();
test_env_value_is_valid();
test_env_assignment_is_valid();
+ test_setenv_systemd_exec_pid();
return 0;
}