summaryrefslogtreecommitdiffstats
path: root/src/journal/journalctl-catalog.c
blob: 116e152be007bbd52f23cb433a61578cc443c48d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* SPDX-License-Identifier: LGPL-2.1-or-later */

#include "catalog.h"
#include "journalctl.h"
#include "journalctl-catalog.h"
#include "path-util.h"

int action_update_catalog(void) {
        _cleanup_free_ char *database = NULL;
        const char *e;
        int r;

        assert(arg_action == ACTION_UPDATE_CATALOG);

        database = path_join(arg_root, secure_getenv("SYSTEMD_CATALOG") ?: CATALOG_DATABASE);
        if (!database)
                return log_oom();

        e = secure_getenv("SYSTEMD_CATALOG_SOURCES");
        r = catalog_update(database,
                           arg_root,
                           e ? STRV_MAKE_CONST(e) : catalog_file_dirs);
        if (r < 0)
                return log_error_errno(r, "Failed to update catalog: %m");

        return 0;
}

int action_list_catalog(char **items) {
        _cleanup_free_ char *database = NULL;
        int r;

        assert(IN_SET(arg_action, ACTION_LIST_CATALOG, ACTION_DUMP_CATALOG));

        database = path_join(arg_root, secure_getenv("SYSTEMD_CATALOG") ?: CATALOG_DATABASE);
        if (!database)
                return log_oom();

        bool oneline = arg_action == ACTION_LIST_CATALOG;

        pager_open(arg_pager_flags);

        if (items)
                r = catalog_list_items(stdout, database, oneline, items);
        else
                r = catalog_list(stdout, database, oneline);
        if (r < 0)
                return log_error_errno(r, "Failed to list catalog: %m");

        return 0;
}