summaryrefslogtreecommitdiff
path: root/src/test/test-fs-util.c
diff options
context:
space:
mode:
authorottopotto <otto_026@hotmail.com>2016-06-30 17:59:06 +0300
committerLennart Poettering <lennart@poettering.net>2016-06-30 07:59:06 -0700
commit34a8f0811c972aedd812468ae13bf9c18010c267 (patch)
tree2156ad1a1273bfdd22902a08939d539b33a72f24 /src/test/test-fs-util.c
parent30b42a9a36727ac6a5201d51b6d9cd9c788a559a (diff)
journalctl: Make temporary files directory configurable (#3574)
journalctl: Use env variable TMPDIR to save temporary files
Diffstat (limited to 'src/test/test-fs-util.c')
-rw-r--r--src/test/test-fs-util.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c
index 6db2c2b6f1..e0c040f39b 100644
--- a/src/test/test-fs-util.c
+++ b/src/test/test-fs-util.c
@@ -82,10 +82,56 @@ static void test_get_files_in_directory(void) {
assert_se(get_files_in_directory(".", NULL) >= 0);
}
+static void test_var_tmp(void) {
+ char *tmp_dir = NULL;
+ char *tmpdir_backup = NULL;
+ const char *default_var_tmp = NULL;
+ const char *var_name;
+ bool do_overwrite = true;
+
+ default_var_tmp = "/var/tmp";
+ var_name = "TMPDIR";
+
+ if (getenv(var_name) != NULL) {
+ tmpdir_backup = strdup(getenv(var_name));
+ assert_se(tmpdir_backup != NULL);
+ }
+
+ unsetenv(var_name);
+
+ var_tmp(&tmp_dir);
+ assert_se(!strcmp(tmp_dir, default_var_tmp));
+
+ free(tmp_dir);
+
+ setenv(var_name, "/tmp", do_overwrite);
+ assert_se(!strcmp(getenv(var_name), "/tmp"));
+
+ var_tmp(&tmp_dir);
+ assert_se(!strcmp(tmp_dir, "/tmp"));
+
+ free(tmp_dir);
+
+ setenv(var_name, "/88_does_not_exist_88", do_overwrite);
+ assert_se(!strcmp(getenv(var_name), "/88_does_not_exist_88"));
+
+ var_tmp(&tmp_dir);
+ assert_se(!strcmp(tmp_dir, default_var_tmp));
+
+ free(tmp_dir);
+
+ if (tmpdir_backup != NULL) {
+ setenv(var_name, tmpdir_backup, do_overwrite);
+ assert_se(!strcmp(getenv(var_name), tmpdir_backup));
+ free(tmpdir_backup);
+ }
+}
+
int main(int argc, char *argv[]) {
test_unlink_noerrno();
test_readlink_and_make_absolute();
test_get_files_in_directory();
+ test_var_tmp();
return 0;
}