Debian Codegraph @

src/journal/journalctl-catalog.c

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include <stdlib.h>
4
5 #include "alloc-util.h"
6 #include "catalog.h"
7 #include "journalctl.h"
8 #include "journalctl-catalog.h"
9 #include "log.h"
10 #include "pager.h"
11 #include "path-util.h"
12
13 int action_update_catalog(void) {
14 _cleanup_free_ char *database = NULL;
15 const char *e;
16 int r;
17
18 assert(arg_action == ACTION_UPDATE_CATALOG);
19
20 database = path_join(arg_root, secure_getenv("SYSTEMD_CATALOG") ?: CATALOG_DATABASE);
21 if (!database)
22 return log_oom();
23
24 e = secure_getenv("SYSTEMD_CATALOG_SOURCES");
25 r = catalog_update(database,
26 arg_root,
27 e ? STRV_MAKE_CONST(e) : NULL);
28 if (r < 0)
29 return log_error_errno(r, "Failed to update catalog: %m");
30
31 return 0;
32 }
33
34 int action_list_catalog(char **items) {
35 _cleanup_free_ char *database = NULL;
36 int r;
37
38 assert(IN_SET(arg_action, ACTION_LIST_CATALOG, ACTION_DUMP_CATALOG));
39
40 database = path_join(arg_root, secure_getenv("SYSTEMD_CATALOG") ?: CATALOG_DATABASE);
41 if (!database)
42 return log_oom();
43
44 bool oneline = arg_action == ACTION_LIST_CATALOG;
45
46 pager_open(arg_pager_flags);
47
48 if (items)
49 r = catalog_list_items(/* f= */ NULL, database, oneline, items);
50 else
51 r = catalog_list(/* f= */ NULL, database, oneline);
52 if (r < 0)
53 return log_error_errno(r, "Failed to list catalog: %m");
54
55 return 0;
56 }