chiark / gitweb /
test-journal-flush: avoid predictable names in /var/tmp
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 25 Apr 2014 23:58:21 +0000 (19:58 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 26 Apr 2014 12:16:35 +0000 (08:16 -0400)
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;
 }