chiark / gitweb /
test-journal-flush: avoid predictable names in /var/tmp
[elogind.git] / src / journal / test-journal-flush.c
index e61e87a..0ca24e0 100644 (file)
 
 int main(int argc, char *argv[]) {
 
-        char fn[sizeof("/var/tmp/test-journal-flush-")-1 + DECIMAL_STR_MAX(pid_t) + sizeof(".journal")];
+        char dn[] = "/var/tmp/test-journal-flush.XXXXXX", *fn;
         JournalFile *new_journal = NULL;
         sd_journal *j = NULL;
         unsigned n = 0;
         int r;
 
-        sprintf(fn, "/var/tmp/test-journal-flush-%lu.journal", (unsigned long) getpid());
+        assert_se(mkdtemp(dn));
+        fn = strappend(dn, "/test.journal");
 
         r = journal_file_open(fn, O_CREAT|O_RDWR, 0644, false, false, NULL, NULL, NULL, &new_journal);
         assert_se(r >= 0);
@@ -67,5 +68,7 @@ int main(int argc, char *argv[]) {
 
         journal_file_close(new_journal);
 
+        assert_se(rmdir(dn) == 0);
+
         return 0;
 }