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

systemd / systemd / 15720680019

17 Jun 2025 07:58PM UTC coverage: 72.087% (-0.02%) from 72.109%
15720680019

push

github

web-flow
sd-lldp: several improvements (#37845)

This makes
- sd-lldp-tx not send machine ID as chassis ID, but use application
specific machine ID,
- sd-lldp-tx emit vlan ID if it is running on a vlan interface,
- Describe() DBus method also reply LLDP configurations,
- io.systemd.Network.GetLLDPNeighbors varlink method provides vlan ID,
if received.

Closes #37613.

59 of 76 new or added lines in 3 files covered. (77.63%)

4663 existing lines in 75 files now uncovered.

300494 of 416851 relevant lines covered (72.09%)

704683.58 hits per line

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

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

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

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

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

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

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

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

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

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

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

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

UNCOV
54
                return 0;
×
55
        }
56
}
57

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

138
                return 0;
139
        }
140

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

145
        *ret = r;
27✔
146
        return 1; /* work to do */
27✔
147
}
148

149
int parse_machine_argument(const char *s, const char **ret_host, BusTransport *ret_transport) {
73✔
150
        int r;
73✔
151

152
        assert(s);
73✔
153
        assert(ret_host);
73✔
154

155
        r = machine_spec_valid(s);
73✔
156
        if (r < 0)
73✔
UNCOV
157
                return log_error_errno(r, "Failed to validate --machine= argument '%s': %m", s);
×
158
        if (r == 0)
73✔
UNCOV
159
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid --machine= specified: %s", s);
×
160

161
        *ret_host = s;
73✔
162

163
        if (ret_transport)
73✔
164
                *ret_transport = BUS_TRANSPORT_MACHINE;
73✔
165

166
        return 0;
167
}
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