]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/journal/test-catalog.c
tree-wide: remove Lennart's copyright lines
[thirdparty/systemd.git] / src / journal / test-catalog.c
index d5640c549cf6a68be29c0f5721e5e4afa03ade1b..55560b8bcbd7b4add90e14d4af67a4153c620a7b 100644 (file)
@@ -1,8 +1,5 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 /***
-  This file is part of systemd.
-
-  Copyright 2012 Lennart Poettering
   Copyright 2013 Zbigniew JÄ™drzejewski-Szmek
 ***/
 
@@ -16,6 +13,7 @@
 #include "alloc-util.h"
 #include "catalog.h"
 #include "fd-util.h"
+#include "fs-util.h"
 #include "fileio.h"
 #include "log.h"
 #include "macro.h"
@@ -32,9 +30,8 @@ static const char *no_catalog_dirs[] = {
         NULL
 };
 
-static Hashmap * test_import(const char* contents, ssize_t size, int code) {
-        int r;
-        char name[] = "/tmp/test-catalog.XXXXXX";
+static Hashmap* test_import(const char* contents, ssize_t size, int code) {
+        _cleanup_(unlink_tempfilep) char name[] = "/tmp/test-catalog.XXXXXX";
         _cleanup_close_ int fd;
         Hashmap *h;
 
@@ -47,10 +44,7 @@ static Hashmap * test_import(const char* contents, ssize_t size, int code) {
         assert_se(fd >= 0);
         assert_se(write(fd, contents, size) == size);
 
-        r = catalog_import_file(h, name);
-        assert_se(r == code);
-
-        unlink(name);
+        assert_se(catalog_import_file(h, name) == code);
 
         return h;
 }
@@ -164,17 +158,9 @@ static void test_catalog_import_merge_no_body(void) {
         }
 }
 
-static const char* database = NULL;
-
-static void test_catalog_update(void) {
-        static char name[] = "/tmp/test-catalog.XXXXXX";
+static void test_catalog_update(const char *database) {
         int r;
 
-        r = mkostemp_safe(name);
-        assert_se(r >= 0);
-
-        database = name;
-
         /* Test what happens if there are no files. */
         r = catalog_update(database, NULL, NULL);
         assert_se(r == 0);
@@ -218,6 +204,7 @@ static void test_catalog_file_lang(void) {
 }
 
 int main(int argc, char *argv[]) {
+        _cleanup_(unlink_tempfilep) char database[] = "/tmp/test-catalog.XXXXXX";
         _cleanup_free_ char *text = NULL;
         int r;
 
@@ -234,7 +221,9 @@ int main(int argc, char *argv[]) {
         test_catalog_import_merge();
         test_catalog_import_merge_no_body();
 
-        test_catalog_update();
+        assert_se(mkostemp_safe(database) >= 0);
+
+        test_catalog_update(database);
 
         r = catalog_list(stdout, database, true);
         assert_se(r >= 0);
@@ -245,8 +234,5 @@ int main(int argc, char *argv[]) {
         assert_se(catalog_get(database, SD_MESSAGE_COREDUMP, &text) >= 0);
         printf(">>>%s<<<\n", text);
 
-        if (database)
-                unlink(database);
-
         return 0;
 }