]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Resolve more simple critical TODOs fort2
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Wed, 21 May 2025 00:05:14 +0000 (18:05 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Wed, 21 May 2025 00:05:14 +0000 (18:05 -0600)
- Rename `file_exists()` to `file_stat_errno()`
- Make result string `node2file()` consistently free-able
- Move `valid_file_or_dir()` to file.c, rename to `file_is_valid()`
- Make cache threshold configurable
- Recover from errors in `__vfprintf()`
- Remove recursion from `cer_cleanup()` and `cer_free()`
- Delete snapshots and deltas after exploding them

16 files changed:
src/cache.c
src/cache.h
src/common.c
src/common.h
src/config.c
src/file.c
src/file.h
src/log.c
src/object/certificate.c
src/object/manifest.c
src/rrdp.c
test/cache_test.c
test/file_test.c
test/mock.c
test/rtr/db/vrps_test.c
test/rtr/pdu_handler_test.c

index 7fa67cb3a8b7303f29617dd240b53028bc148c0e..b3bcd60dcb8c59eeb1597037d987794ab533c569 100644 (file)
@@ -95,7 +95,7 @@ struct cache_node {
        enum node_state state;
        /* Result code of recent dl attempt (DLS_FRESH only) */
        validation_verdict verdict;
-       time_t attempt_ts;      /* Refresh: Dl attempt. Fallback: Unused */
+       time_t attempt_ts;      /* Refresh: Dl attempt. Fallback: Commit */
        time_t success_ts;      /* Refresh: Dl success. Fallback: Commit */
 
        struct mft_meta mft;    /* RPP fallbacks only */
@@ -357,7 +357,7 @@ static void
 init_cachedir_tag(void)
 {
        static char const *filename = "CACHEDIR.TAG";
-       if (file_exists(filename) == ENOENT)
+       if (file_stat_errno(filename) == ENOENT)
                file_write_txt(filename,
                   "Signature: 8a477f597d28d172789f06886806bc55\n"
                   "# This file is a cache directory tag created by Fort.\n"
@@ -1102,18 +1102,19 @@ refresh_success:
        return VV_CONTINUE;
 }
 
-static char const *
+/* Result needs free() */
+static char *
 node2file(struct cache_node const *node, struct uri const *url)
 {
        if (node == NULL)
                return NULL;
-       // XXX RRDP is const, rsync needs to be freed
        return (node->rrdp)
-           ? /* RRDP  */ rrdp_file(node->rrdp, url)
+           ? /* RRDP  */ pstrdup(rrdp_file(node->rrdp, url))
            : /* rsync */ path_join(node->path, strip_rsync_module(uri_str(url)));
 }
 
-char const *
+/* Result needs free() */
+char *
 cage_map_file(struct cache_cage *cage, struct uri const *url)
 {
        /*
@@ -1122,7 +1123,7 @@ cage_map_file(struct cache_cage *cage, struct uri const *url)
         * modified either.
         */
 
-       char const *file;
+       char *file;
 
        file = node2file(cage->refresh, url);
        if (!file)
@@ -1400,6 +1401,7 @@ commit_fallbacks(time_t now)
                        fb = provide_node(&cache.fallback,
                            &commit->rpkiNotify,
                            &commit->caRepository);
+                       fb->attempt_ts = now;
                        fb->success_ts = now;
 
                        pr_op_debug("mkdir -f %s", fb->path);
@@ -1424,6 +1426,7 @@ commit_fallbacks(time_t now)
                            uri_str(&map->url));
 
                        fb = provide_node(&cache.fallback, &map->url, NULL);
+                       fb->attempt_ts = now;
                        fb->success_ts = now;
                        if (is_fallback(map->path))
                                goto freshen;
@@ -1466,7 +1469,7 @@ static void
 remove_orphaned_nodes(struct cache_table *table, struct cache_node *node,
     void *arg)
 {
-       if (file_exists(node->path) == ENOENT) {
+       if (file_stat_errno(node->path) == ENOENT) {
                pr_op_debug("Missing file; deleting node: %s", node->path);
                delete_node(table, node, NULL);
        }
index 1e30014cfb0547e76284e866156c1dbb31463a32..9d04a1da4fc37751e1e88fc1396898af7d9476c7 100644 (file)
@@ -44,7 +44,7 @@ validation_verdict cache_get_fallback(struct uri const *, char const **);
 struct cache_cage;
 validation_verdict cache_refresh_by_uris(struct extension_uris *,
     struct cache_cage **);
-char const *cage_map_file(struct cache_cage *, struct uri const *);
+char *cage_map_file(struct cache_cage *, struct uri const *);
 bool cage_downgrade(struct cache_cage *);
 struct mft_meta const *cage_mft_fallback(struct cache_cage *);
 void cache_commit_rpp(struct uri const *, struct uri const *, struct rpp *);
index 297f6c1d1504f0c9f9ecac207b9c9e8eab9e02e7..12383c7a078020cfaf3995e16a64650118d6b5f0 100644 (file)
@@ -220,29 +220,6 @@ foreach_file(char const *location, char const *file_ext, bool empty_err,
        return process_dir_files(location, file_ext, empty_err, cb, arg);
 }
 
-bool
-valid_file_or_dir(char const *location, bool check_file)
-{
-       struct stat attr;
-       bool is_file, is_dir;
-       bool result;
-
-       if (stat(location, &attr) == -1) {
-               pr_op_err("stat(%s) failed: %s", location, strerror(errno));
-               return false;
-       }
-
-       is_file = check_file && S_ISREG(attr.st_mode);
-       is_dir = S_ISDIR(attr.st_mode);
-
-       result = is_file || is_dir;
-       if (!result)
-               pr_op_err("'%s' does not seem to be a %s", location,
-                   check_file ? "file or directory" : "directory");
-
-       return result;
-}
-
 time_t
 time_nonfatal(void)
 {
index 7068281ecfbed03e711275729a52fbf5b2b1fd64..09eb8e43b8078190f40235a9c1b49db043a126fb 100644 (file)
@@ -40,9 +40,6 @@ void rwlock_unlock(pthread_rwlock_t *);
 typedef int (*foreach_file_cb)(char const *, void *);
 int foreach_file(char const *, char const *, bool, foreach_file_cb, void *);
 
-// XXX
-bool valid_file_or_dir(char const *, bool);
-
 time_t time_nonfatal(void);
 time_t time_fatal(void);
 
index de0f8dc42a708d4d79c1e9eee04433ae2c75f6e5..ea8b14e29354ef488a750ab7fbdb1ee118d834bc 100644 (file)
@@ -10,7 +10,6 @@
 #include <syslog.h>
 
 #include "alloc.h"
-#include "common.h"
 #include "config/boolean.h"
 #include "config/incidences.h"
 #include "config/str.h"
@@ -19,6 +18,7 @@
 #include "config/work_offline.h"
 #include "configure_ac.h"
 #include "daemon.h"
+#include "file.h"
 #include "init.h"
 #include "json_handler.h"
 #include "log.h"
@@ -30,7 +30,7 @@
  * To add a member to this structure,
  *
  * 1. Add it.
- * 2. Add its metadata somewhere in @groups.
+ * 2. Add its metadata somewhere in @options.
  * 3. Add default value to set_default_values().
  * 4. Create the getter.
  *
 struct rpki_config {
        /** TAL file name or directory. */
        char *tal;
-       /** Path of our local clone of the repository */
-       char *local_repository;
+
+       struct {
+               /* Path of our local clone of the repository */
+               char *path;
+               /* Cache content expiration seconds (after last refresh) */
+               unsigned int threshold;
+       } cache;
+
        /* Deprecated; does nothing. */
        bool shuffle_tal_uris;
        /**
@@ -288,10 +294,16 @@ static const struct option_field options[] = {
                .id = 'r',
                .name = "local-repository",
                .type = &gt_string,
-               .offset = offsetof(struct rpki_config, local_repository),
+               .offset = offsetof(struct rpki_config, cache.path),
                .doc = "Directory where the repository local cache will be stored/read",
                .arg_doc = "<directory>",
                .json_null_allowed = false,
+       }, {
+               .id = 1001,
+               .name = "cache.threshold",
+               .type = &gt_uint,
+               .offset = offsetof(struct rpki_config, cache.threshold),
+               .doc = "Cache content expiration seconds (after last refresh)",
        }, {
                .id = 2001,
                .name = "shuffle-uris",
@@ -942,7 +954,8 @@ set_default_values(void)
         */
 
        rpki_config.tal = NULL;
-       rpki_config.local_repository = pstrdup("/tmp/fort/repository");
+       rpki_config.cache.path = pstrdup("/tmp/fort/repository");
+       rpki_config.cache.threshold = 86400;
        rpki_config.shuffle_tal_uris = false;
        rpki_config.maximum_certificate_depth = 32;
        rpki_config.slurm = NULL;
@@ -1024,7 +1037,7 @@ validate_config(void)
                return pr_op_err("The TAL(s) location (--tal) is mandatory.");
 
        /* A file location at --tal isn't valid when --init-tals is set */
-       if (!valid_file_or_dir(rpki_config.tal, !rpki_config.init_tals))
+       if (!file_is_valid(rpki_config.tal, !rpki_config.init_tals))
                return pr_op_err("Invalid TAL(s) location.");
 
        /* Ignore the other checks */
@@ -1037,7 +1050,7 @@ validate_config(void)
            rpki_config.server.interval.retry)
                return pr_op_err("Expire interval must be greater than refresh and retry intervals");
 
-       if (rpki_config.slurm != NULL && !valid_file_or_dir(rpki_config.slurm, true))
+       if (rpki_config.slurm != NULL && !file_is_valid(rpki_config.slurm, true))
                return pr_op_err("Invalid slurm location.");
 
        return 0;
@@ -1272,13 +1285,13 @@ config_get_tal(void)
 char const *
 config_get_local_repository(void)
 {
-       return rpki_config.local_repository;
+       return rpki_config.cache.path;
 }
 
 time_t
 cfg_cache_threshold(void)
 {
-       return 86400; // XXX
+       return rpki_config.cache.threshold;
 }
 
 unsigned int
index 59775f44c4f06ae0d842799dafefe9bb08a18b22..a46a9bd1768599396449c27e65f632793a6e5230 100644 (file)
@@ -165,14 +165,36 @@ file_free(struct file_contents *fc)
 }
 
 /* Wrapper for stat(), mostly for the sake of unit test mocking. */
-/* XXX needs a rename, because it returns errno. */
 int
-file_exists(char const *path)
+file_stat_errno(char const *path)
 {
        struct stat meta;
        return (stat(path, &meta) == 0) ? 0 : errno;
 }
 
+bool
+file_is_valid(char const *location, bool allow_file)
+{
+       struct stat attr;
+       bool is_file, is_dir;
+       bool result;
+
+       if (stat(location, &attr) == -1) {
+               pr_op_err("stat(%s) failed: %s", location, strerror(errno));
+               return false;
+       }
+
+       is_file = allow_file && S_ISREG(attr.st_mode);
+       is_dir = S_ISDIR(attr.st_mode);
+
+       result = is_file || is_dir;
+       if (!result)
+               pr_op_err("'%s' does not seem to be a %s", location,
+                   allow_file ? "file or directory" : "directory");
+
+       return result;
+}
+
 /*
  * Like remove(), but don't care if the file is already deleted.
  */
index 013779b22dd41ed765602349dd215f143bd1221d..8041c6958828b27718510b8eed6c7c59071b95de 100644 (file)
@@ -32,7 +32,8 @@ void file_close(FILE *);
 int file_load(char const *, struct file_contents *, bool);
 void file_free(struct file_contents *);
 
-int file_exists(char const *);
+int file_stat_errno(char const *);
+bool file_is_valid(char const *, bool);
 
 int file_rm_f(char const *);
 int file_rm_rf(char const *);
index 9c3c86794096d05da78fd9a261e5485ff0b65e74..66b0de1e17e6901a932cb7fca8554d0c3be4a63a 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -272,13 +272,28 @@ unlock_mutex(void)
                print_stack_trace(strerror(error)); /* Same as above. */
 }
 
+static void
+print_time(struct level const *lvl)
+{
+       time_t now;
+       struct tm components;
+       char str[16];
+
+       now = time(NULL);
+       if (now == ((time_t) -1))
+               return;
+       if (localtime_r(&now, &components) == NULL)
+               return;
+       if (strftime(str, sizeof(str), "%m-%d %H:%M:%S", &components) == 0)
+               return;
+
+       fprintf(lvl->stream, "%s ", str);
+}
+
 static void
 __vfprintf(int level, struct log_config *cfg, char const *format, va_list args)
 {
-       char time_buff[20];
        struct level const *lvl;
-       time_t now;
-       struct tm stm_buff;
        char const *file_name;
 
        lvl = level2struct(level);
@@ -288,13 +303,7 @@ __vfprintf(int level, struct log_config *cfg, char const *format, va_list args)
        if (cfg->color)
                fprintf(lvl->stream, "%s", lvl->color);
 
-       now = time(NULL);
-       if (now != ((time_t) -1)) {
-               // XXX not catching any errors
-               localtime_r(&now, &stm_buff);
-               strftime(time_buff, sizeof(time_buff), "%b %e %T", &stm_buff);
-               fprintf(lvl->stream, "%s ", time_buff);
-       }
+       print_time(lvl);
 
        fprintf(lvl->stream, "%s", lvl->label);
        if (cfg->tag)
index 80b903f3ea2d844b9137c5fb8c3f2aed8181ed7e..fce74a417853c93f4bf4108d40578060f12412ad 100644 (file)
@@ -789,27 +789,39 @@ cer_init_ee(struct rpki_certificate *ee, struct rpki_certificate *parent,
        atomic_fetch_add(&parent->refcount, 1);
 }
 
+static void
+__cer_cleanup(struct rpki_certificate *cer)
+{
+       map_cleanup(&cer->map);
+       if (cer->x509 != NULL)
+               X509_free(cer->x509);
+       resources_destroy(cer->resources);
+       exturis_cleanup(&cer->uris);
+       rpp_cleanup(&cer->rpp);
+}
+
 void
-cer_cleanup(struct rpki_certificate *cert)
+cer_cleanup(struct rpki_certificate *cer)
 {
-       map_cleanup(&cert->map);
-       if (cert->x509 != NULL)
-               X509_free(cert->x509);
-       resources_destroy(cert->resources);
-       exturis_cleanup(&cert->uris);
-       // XXX Recursive. Try refcounting the resources.
-       if (cert->parent)
-               cer_free(cert->parent);
-       rpp_cleanup(&cert->rpp);
+       __cer_cleanup(cer);
+       if (cer->parent)
+               cer_free(cer->parent);
 }
 
 void
-cer_free(struct rpki_certificate *cert)
+cer_free(struct rpki_certificate *cer)
 {
-       if (atomic_fetch_sub(&cert->refcount, 1) == 1) {
-               cer_cleanup(cert);
-               free(cert);
-       }
+       struct rpki_certificate *parent;
+
+       do {
+               if (atomic_fetch_sub(&cer->refcount, 1) != 1)
+                       return;
+
+               __cer_cleanup(cer);
+               parent = cer->parent;
+               free(cer);
+               cer = parent;
+       } while (cer != NULL);
 }
 
 /*
@@ -1941,6 +1953,7 @@ cer_traverse(struct rpki_certificate *ca)
        struct cache_mapping *map;
        unsigned int queued;
        validation_verdict vv;
+       int error;
 
        if (!ca->x509) {
                if (validate_certificate(ca) != 0)
@@ -1961,7 +1974,7 @@ cer_traverse(struct rpki_certificate *ca)
        }
 
        mft.url = ca->uris.rpkiManifest;
-retry: mft.path = (char *)cage_map_file(cage, &mft.url); /* Will not edit */
+retry: mft.path = cage_map_file(cage, &mft.url);
        if (!mft.path) {
                if (cage_downgrade(cage))
                        goto retry;
@@ -1971,7 +1984,9 @@ retry:    mft.path = (char *)cage_map_file(cage, &mft.url); /* Will not edit */
                goto end;
        }
 
-       if (manifest_traverse(&mft, cage, ca) != 0) {
+       error = manifest_traverse(&mft, cage, ca);
+       free(mft.path);
+       if (error) {
                if (cage_downgrade(cage))
                        goto retry;
                vv = VV_FAIL;
index 1eb9bbadf67b4702f04779dde2d33f3c342dba31..514db9bcaa8445deb1d7927c2144d630022f85bb 100644 (file)
@@ -292,7 +292,6 @@ collect_files(struct cache_mapping const *map,
        struct FileAndHash *src;
        struct cache_mapping *dst;
        char const *ext;
-       char const *path;
        int error;
 
        if (mft->fileList.list.count == 0)
@@ -338,14 +337,13 @@ collect_files(struct cache_mapping const *map,
                uri_child(&rpp_url, (char const *)src->file.buf, src->file.size,
                    &dst->url);
 
-               path = cage_map_file(cage, &dst->url);
-               if (!path) {
+               dst->path = cage_map_file(cage, &dst->url);
+               if (!dst->path) {
                        error = pr_val_err(
                            "Manifest file '%s' is absent from the cache.",
                            uri_str(&dst->url));
                        goto revert;
                }
-               dst->path = pstrdup(path);
 
                error = check_file_and_hash(src, dst->path);
                if (error)
index 1016161eba5148dbb518b328487a040fb0442975..8795364f09c4900757310d3920531677efa78244 100644 (file)
@@ -944,7 +944,7 @@ handle_snapshot(struct update_notification *new, struct rrdp_state *state)
        if (error)
                goto end;
        error = parse_snapshot(&new->session, tmppath, state);
-//     delete_file(tmppath); XXX
+       file_rm_f(tmppath);
 
 end:   fnstack_pop();
        return error;
@@ -1016,7 +1016,7 @@ handle_delta(struct update_notification *notif,
        if (error)
                goto end;
        error = parse_delta(notif, delta, tmppath, state);
-//     delete_file(tmppath); XXX
+       file_rm_f(tmppath);
 
 end:   fnstack_pop();
        return error;
index 6908c05a37d69680978d7d47ca4d3550a7f28a36..a094f7b86cc0ad51b1af747c7046c4846083950a 100644 (file)
@@ -96,7 +96,7 @@ setup_test(void)
        init_tables();
 
        for (d = dirs; *d; d++) {
-               if (file_exists(*d) == 0)
+               if (file_stat_errno(*d) == 0)
                        ck_assert_int_eq(0, file_rm_rf(*d));
                ck_assert_int_eq(0, mkdir(*d, CACHE_FILEMODE));
        }
@@ -192,9 +192,9 @@ ck_cage_map(struct cache_cage *cage, char const *url,
        refresh = cage->refresh;
        fallback = cage->fallback;
 
-       ck_assert_pstr_eq(opt1, cage_map_file(cage, &uri));
+       ck_assert_pstr_eq_free(opt1, cage_map_file(cage, &uri));
        ck_assert_uint_eq(!!opt2, cage_downgrade(cage));
-       ck_assert_pstr_eq(opt2, cage_map_file(cage, &uri));
+       ck_assert_pstr_eq_free(opt2, cage_map_file(cage, &uri));
 
        cage->refresh = refresh;
        cage->fallback = fallback;
@@ -866,9 +866,9 @@ START_TEST(test_context)
        ck_assert_ptr_eq(NULL, uri_init(&sias.caRepository, CA_REPOSITORY));
        ck_assert_str_eq(VV_CONTINUE, cache_refresh_by_uris(&sias, &cage));
        ck_assert_str_eq(RPKI_NOTIFY, uri_str(&cage->rpkiNotify));
-       ck_assert_str_eq(FILE_RRDP_PATH, cage_map_file(cage, &file_url));
+       ck_assert_pstr_eq_free(FILE_RRDP_PATH, cage_map_file(cage, &file_url));
        ck_assert_int_eq(false, cage_downgrade(cage));
-       ck_assert_ptr_eq(NULL, cage_map_file(cage, &file_url));
+       ck_assert_pstr_eq_free(NULL, cage_map_file(cage, &file_url));
 
        printf("2. 2nd CA points to the same caRepository,\n");
        printf("   but does not provide RRDP as an option.\n");
@@ -880,9 +880,9 @@ START_TEST(test_context)
        ck_assert_str_eq(VV_CONTINUE, cache_refresh_by_uris(&sias, &cage));
 
        ck_assert_ptr_eq(NULL, uri_str(&cage->rpkiNotify));
-       ck_assert_str_eq(FILE_RSYNC_PATH, cage_map_file(cage, &file_url));
+       ck_assert_pstr_eq_free(FILE_RSYNC_PATH, cage_map_file(cage, &file_url));
        ck_assert_int_eq(false, cage_downgrade(cage));
-       ck_assert_ptr_eq(NULL, cage_map_file(cage, &file_url));
+       ck_assert_pstr_eq_free(NULL, cage_map_file(cage, &file_url));
 
        printf("3. Commit\n");
 
@@ -907,16 +907,16 @@ START_TEST(test_context)
        print_tree();
        ck_assert_str_eq(VV_CONTINUE, cache_refresh_by_uris(&sias, &cage));
        ck_assert_ptr_eq(NULL, uri_str(&cage->rpkiNotify));
-       ck_assert_str_eq(FILE_RSYNC_PATH, cage_map_file(cage, &file_url));
+       ck_assert_pstr_eq_free(FILE_RSYNC_PATH, cage_map_file(cage, &file_url));
        ck_assert_int_eq(true, cage_downgrade(cage));
-       ck_assert_str_eq("fallback/1/0", cage_map_file(cage, &file_url));
+       ck_assert_pstr_eq_free("fallback/1/0", cage_map_file(cage, &file_url));
 
        ck_assert_ptr_eq(NULL, uri_init(&sias.rpkiNotify, RPKI_NOTIFY));
        ck_assert_str_eq(VV_CONTINUE, cache_refresh_by_uris(&sias, &cage));
        ck_assert_str_eq(RPKI_NOTIFY, uri_str(&cage->rpkiNotify));
-       ck_assert_str_eq(FILE_RRDP_PATH, cage_map_file(cage, &file_url));
+       ck_assert_pstr_eq_free(FILE_RRDP_PATH, cage_map_file(cage, &file_url));
        ck_assert_int_eq(true, cage_downgrade(cage));
-       ck_assert_str_eq("fallback/0/0", cage_map_file(cage, &file_url));
+       ck_assert_pstr_eq_free("fallback/0/0", cage_map_file(cage, &file_url));
 
        uri_cleanup(&sias.rpkiNotify);
        uri_cleanup(&sias.caRepository);
index a18a1b3b14c6b64d5a5d4be9375b8d7ac562fccc..6603123240bea9f2f854e38da1894a7bee15e256 100644 (file)
@@ -24,9 +24,9 @@ START_TEST(test_rm)
 {
        create_test_sandbox();
 
-       ck_assert_int_eq(0, file_exists("tmp/file/abc"));
+       ck_assert_int_eq(0, file_stat_errno("tmp/file/abc"));
        ck_assert_int_eq(0, file_rm_rf("tmp/file/abc"));
-       ck_assert_int_eq(ENOENT, file_exists("tmp/file/abc"));
+       ck_assert_int_eq(ENOENT, file_stat_errno("tmp/file/abc"));
 }
 END_TEST
 
index 72827402679492db931ca92e09992bea22c93615..8aaf4bd264357d2229e20ea11b9058c43bff9004 100644 (file)
@@ -2,10 +2,15 @@
 
 #include <errno.h>
 #include <arpa/inet.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <time.h>
-#include "config.h"
+
+#include "common.h"
 #include "log.h"
-#include "thread_var.h"
+#include "types/map.h"
 
 /* Some core functions, as linked from unit tests. */
 
@@ -113,7 +118,6 @@ v6addr2str2(struct in6_addr const *addr)
 MOCK_NULL(config_get_slurm, char const *, void)
 MOCK(config_get_tal, char const *, "tal/", void)
 MOCK(cfg_cache_threshold, time_t, 2, void)
-MOCK(config_get_mode, enum mode, STANDALONE, void)
 MOCK_UINT(config_get_rrdp_delta_threshold, 5, void)
 MOCK_TRUE(config_get_rsync_enabled, void)
 MOCK_UINT(config_get_rsync_priority, 50, void)
@@ -121,8 +125,6 @@ MOCK_TRUE(config_get_http_enabled, void)
 MOCK_UINT(config_get_http_priority, 60, void)
 MOCK_NULL(config_get_output_roa, char const *, void)
 MOCK_NULL(config_get_output_bgpsec, char const *, void)
-MOCK(config_get_op_log_file_format, enum filename_format, FNF_NAME, void)
-MOCK(config_get_val_log_file_format, enum filename_format, FNF_NAME, void)
 MOCK(logv_filename, char const *, path, char const *path)
 MOCK_VOID(free_rpki_config, void)
 
@@ -132,6 +134,13 @@ MOCK_VOID(fnstack_push_map, struct cache_mapping const *map)
 MOCK_VOID(fnstack_pop, void)
 MOCK_VOID(fnstack_cleanup, void)
 
+void
+ck_assert_pstr_eq_free(char const *expected, char *actual)
+{
+       ck_assert_pstr_eq(expected, actual);
+       free(actual);
+}
+
 void
 ck_assert_uri(char const *expected, struct uri const *actual)
 {
@@ -142,7 +151,7 @@ ck_assert_uri(char const *expected, struct uri const *actual)
 void
 touch_dir(char const *dir)
 {
-       ck_assert_int_eq(0, file_mkdir(dir, true));
+       ck_assert(mkdir(dir, CACHE_FILEMODE) == 0 || errno == EEXIST);
 }
 
 void
index c529f385eed583d4072e2c836f1c9e07211539c3..cd969b9567090829da9b0906a3d9511e0e4cdfec 100644 (file)
@@ -62,6 +62,7 @@ static const bool deltas_4to4[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
 
 static unsigned int deltas_lifetime = 5;
 
+MOCK(config_get_mode, enum mode, STANDALONE, void)
 MOCK_UINT(config_get_deltas_lifetime, deltas_lifetime, void)
 MOCK_ABORT_ENUM(config_get_output_format, output_format, void)
 MOCK_ABORT_VOID(db_slurm_destroy, struct db_slurm *db)
index df78195853280ac4a0513b9569b0873e1a343c2e..1390e34fb1418c653ab5cea03d4d8cf50f3362cf 100644 (file)
@@ -23,6 +23,7 @@ MOCK_INT(slurm_apply, 0, struct db_table *base, struct db_slurm **slurm)
 MOCK_ABORT_VOID(db_slurm_destroy, struct db_slurm *db)
 MOCK_VOID(output_print_data, struct db_table const *db)
 __MOCK_ABORT(config_get_local_repository, char const *, "tmp/pdu", void)
+MOCK(config_get_mode, enum mode, STANDALONE, void)
 
 /* Mocks end */