• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 14895667988

07 May 2025 08:57PM UTC coverage: 72.225% (-0.007%) from 72.232%
14895667988

push

github

yuwata
network: log_link_message_debug_errno() automatically append %m if necessary

Follow-up for d28746ef5.
Fixes CID#1609753.

0 of 1 new or added line in 1 file covered. (0.0%)

20297 existing lines in 338 files now uncovered.

297407 of 411780 relevant lines covered (72.22%)

695716.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.84
/src/shared/parse-argument.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include "alloc-util.h"
4
#include "format-table.h"
5
#include "log.h"
6
#include "parse-argument.h"
7
#include "parse-util.h"
8
#include "path-util.h"
9
#include "signal-util.h"
10
#include "stdio-util.h"
11
#include "string-table.h"
12
#include "string-util.h"
13

14
/* All functions in this file emit warnings. */
15

16
int parse_boolean_argument(const char *optname, const char *s, bool *ret) {
1,087✔
17
        int r;
1,087✔
18

19
        /* Returns the result through *ret and the return value. */
20

21
        if (s) {
1,087✔
22
                r = parse_boolean(s);
1,082✔
23
                if (r < 0)
1,082✔
24
                        return log_error_errno(r, "Failed to parse boolean argument to %s: %s.", optname, s);
33✔
25

26
                if (ret)
1,049✔
27
                        *ret = r;
822✔
28
                return r;
1,049✔
29
        } else {
30
                /* s may be NULL. This is controlled by getopt_long() parameters. */
31
                if (ret)
5✔
32
                        *ret = true;
5✔
33
                return true;
5✔
34
        }
35
}
36

37
int parse_tristate_argument(const char *optname, const char *s, int *ret) {
2✔
38
        int r;
2✔
39

40
        if (s) {
2✔
41
                r = parse_boolean(s);
2✔
42
                if (r < 0)
2✔
UNCOV
43
                        return log_error_errno(r, "Failed to parse boolean argument to %s: %s.", optname, s);
×
44

45
                if (ret)
2✔
46
                        *ret = r;
2✔
47

48
                return r;
2✔
49
        } else {
50
                if (ret)
×
UNCOV
51
                        *ret = -1;
×
52

UNCOV
53
                return 0;
×
54
        }
55
}
56

57
int parse_json_argument(const char *s, sd_json_format_flags_t *ret) {
290✔
58
        assert(s);
290✔
59
        assert(ret);
290✔
60

61
        if (streq(s, "pretty"))
290✔
62
                *ret = SD_JSON_FORMAT_PRETTY|SD_JSON_FORMAT_COLOR_AUTO;
98✔
63
        else if (streq(s, "short"))
192✔
64
                *ret = SD_JSON_FORMAT_NEWLINE;
170✔
65
        else if (streq(s, "off"))
22✔
66
                *ret = SD_JSON_FORMAT_OFF;
11✔
67
        else if (streq(s, "help")) {
11✔
68
                puts("pretty\n"
3✔
69
                     "short\n"
70
                     "off");
71
                return 0; /* 0 means → we showed a brief help, exit now */
3✔
72
        } else
73
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown argument to --json= switch: %s", s);
8✔
74

75
        return 1; /* 1 means → properly parsed */
76
}
77

78
int parse_path_argument(const char *path, bool suppress_root, char **arg) {
2,111✔
79
        char *p;
2,111✔
80
        int r;
2,111✔
81

82
        /*
83
         * This function is intended to be used in command line parsers, to handle paths that are passed
84
         * in. It makes the path absolute, and reduces it to NULL if omitted or root (the latter optionally).
85
         *
86
         * NOTE THAT THIS WILL FREE THE PREVIOUS ARGUMENT POINTER ON SUCCESS!
87
         * Hence, do not pass in uninitialized pointers.
88
         */
89

90
        if (isempty(path)) {
2,111✔
91
                *arg = mfree(*arg);
8✔
92
                return 0;
8✔
93
        }
94

95
        r = path_make_absolute_cwd(path, &p);
2,103✔
96
        if (r < 0)
2,103✔
UNCOV
97
                return log_error_errno(r, "Failed to parse path \"%s\" and make it absolute: %m", path);
×
98

99
        path_simplify(p);
2,103✔
100
        if (suppress_root && empty_or_root(p))
2,103✔
101
                p = mfree(p);
3✔
102

103
        return free_and_replace(*arg, p);
2,103✔
104
}
105

106
int parse_signal_argument(const char *s, int *ret) {
30✔
107
        int r;
30✔
108

109
        assert(s);
30✔
110
        assert(ret);
30✔
111

112
        if (streq(s, "help")) {
30✔
113
                DUMP_STRING_TABLE(signal, int, _NSIG);
132✔
114
                return 0;
2✔
115
        }
116

117
        if (streq(s, "list")) {
28✔
118
                _cleanup_(table_unrefp) Table *table = NULL;
1✔
119

120
                table = table_new("signal", "name");
1✔
121
                if (!table)
1✔
UNCOV
122
                        return log_oom();
×
123

124
                for (int i = 1; i < _NSIG; i++) {
65✔
125
                        r = table_add_many(
64✔
126
                                        table,
127
                                        TABLE_INT, i,
128
                                        TABLE_SIGNAL, i);
129
                        if (r < 0)
64✔
UNCOV
130
                                return table_log_add_error(r);
×
131
                }
132

133
                r = table_print(table, NULL);
1✔
134
                if (r < 0)
1✔
UNCOV
135
                        return table_log_print_error(r);
×
136

137
                return 0;
138
        }
139

140
        r = signal_from_string(s);
27✔
141
        if (r < 0)
27✔
UNCOV
142
                return log_error_errno(r, "Failed to parse signal string \"%s\".", s);
×
143

144
        *ret = r;
27✔
145
        return 1; /* work to do */
27✔
146
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc