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

systemd / systemd / 14554080340

19 Apr 2025 11:46AM UTC coverage: 72.101% (-0.03%) from 72.13%
14554080340

push

github

web-flow
Add two new paragraphs to coding style about header files (#37188)

296880 of 411754 relevant lines covered (72.1%)

687547.52 hits per line

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

62.5
/src/network/networkctl.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <getopt.h>
4

5
#include "build.h"
6
#include "log.h"
7
#include "logs-show.h"
8
#include "main-func.h"
9
#include "networkctl.h"
10
#include "networkctl-address-label.h"
11
#include "networkctl-config-file.h"
12
#include "networkctl-list.h"
13
#include "networkctl-lldp.h"
14
#include "networkctl-misc.h"
15
#include "networkctl-status-link.h"
16
#include "networkctl-util.h"
17
#include "parse-argument.h"
18
#include "parse-util.h"
19
#include "path-util.h"
20
#include "pretty-print.h"
21
#include "verbs.h"
22

23
PagerFlags arg_pager_flags = 0;
24
bool arg_legend = true;
25
bool arg_no_reload = false;
26
bool arg_all = false;
27
bool arg_stats = false;
28
bool arg_full = false;
29
bool arg_runtime = false;
30
bool arg_stdin = false;
31
unsigned arg_lines = 10;
32
char *arg_drop_in = NULL;
33
sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF;
34
bool arg_ask_password = true;
35

36
STATIC_DESTRUCTOR_REGISTER(arg_drop_in, freep);
2,335✔
37

38
static int help(void) {
×
39
        _cleanup_free_ char *link = NULL;
×
40
        int r;
×
41

42
        r = terminal_urlify_man("networkctl", "1", &link);
×
43
        if (r < 0)
×
44
                return log_oom();
×
45

46
        printf("%s [OPTIONS...] COMMAND\n\n"
×
47
               "%sQuery and control the networking subsystem.%s\n"
48
               "\nCommands:\n"
49
               "  list [PATTERN...]      List links\n"
50
               "  status [PATTERN...]    Show link status\n"
51
               "  lldp [PATTERN...]      Show LLDP neighbors\n"
52
               "  label                  Show current address label entries in the kernel\n"
53
               "  delete DEVICES...      Delete virtual netdevs\n"
54
               "  up DEVICES...          Bring devices up\n"
55
               "  down DEVICES...        Bring devices down\n"
56
               "  renew DEVICES...       Renew dynamic configurations\n"
57
               "  forcerenew DEVICES...  Trigger DHCP reconfiguration of all connected clients\n"
58
               "  reconfigure DEVICES... Reconfigure interfaces\n"
59
               "  reload                 Reload .network and .netdev files\n"
60
               "  edit FILES|DEVICES...  Edit network configuration files\n"
61
               "  cat [FILES|DEVICES...] Show network configuration files\n"
62
               "  mask FILES...          Mask network configuration files\n"
63
               "  unmask FILES...        Unmask network configuration files\n"
64
               "  persistent-storage BOOL\n"
65
               "                         Notify systemd-networkd if persistent storage is ready\n"
66
               "\nOptions:\n"
67
               "  -h --help              Show this help\n"
68
               "     --version           Show package version\n"
69
               "     --no-pager          Do not pipe output into a pager\n"
70
               "     --no-legend         Do not show the headers and footers\n"
71
               "     --no-ask-password   Do not prompt for password\n"
72
               "  -a --all               Show status for all links\n"
73
               "  -s --stats             Show detailed link statistics\n"
74
               "  -l --full              Do not ellipsize output\n"
75
               "  -n --lines=INTEGER     Number of journal entries to show\n"
76
               "     --json=pretty|short|off\n"
77
               "                         Generate JSON output\n"
78
               "     --no-reload         Do not reload systemd-networkd or systemd-udevd\n"
79
               "                         after editing network config\n"
80
               "     --drop-in=NAME      Edit specified drop-in instead of main config file\n"
81
               "     --runtime           Edit runtime config files\n"
82
               "     --stdin             Read new contents of edited file from stdin\n"
83
               "\nSee the %s for details.\n",
84
               program_invocation_short_name,
85
               ansi_highlight(),
86
               ansi_normal(),
87
               link);
88

89
        return 0;
90
}
91

92
static int parse_argv(int argc, char *argv[]) {
2,335✔
93
        enum {
2,335✔
94
                ARG_VERSION = 0x100,
95
                ARG_NO_PAGER,
96
                ARG_NO_LEGEND,
97
                ARG_NO_ASK_PASSWORD,
98
                ARG_JSON,
99
                ARG_NO_RELOAD,
100
                ARG_DROP_IN,
101
                ARG_RUNTIME,
102
                ARG_STDIN,
103
        };
104

105
        static const struct option options[] = {
2,335✔
106
                { "help",            no_argument,       NULL, 'h'                 },
107
                { "version",         no_argument,       NULL, ARG_VERSION         },
108
                { "no-pager",        no_argument,       NULL, ARG_NO_PAGER        },
109
                { "no-legend",       no_argument,       NULL, ARG_NO_LEGEND       },
110
                { "no-ask-password", no_argument,       NULL, ARG_NO_ASK_PASSWORD },
111
                { "all",             no_argument,       NULL, 'a'                 },
112
                { "stats",           no_argument,       NULL, 's'                 },
113
                { "full",            no_argument,       NULL, 'l'                 },
114
                { "lines",           required_argument, NULL, 'n'                 },
115
                { "json",            required_argument, NULL, ARG_JSON            },
116
                { "no-reload",       no_argument,       NULL, ARG_NO_RELOAD       },
117
                { "drop-in",         required_argument, NULL, ARG_DROP_IN         },
118
                { "runtime",         no_argument,       NULL, ARG_RUNTIME         },
119
                { "stdin",           no_argument,       NULL, ARG_STDIN           },
120
                {}
121
        };
122

123
        int c, r;
2,335✔
124

125
        assert(argc >= 0);
2,335✔
126
        assert(argv);
2,335✔
127

128
        while ((c = getopt_long(argc, argv, "hasln:", options, NULL)) >= 0) {
3,629✔
129

130
                switch (c) {
1,294✔
131

132
                case 'h':
×
133
                        return help();
×
134

135
                case ARG_VERSION:
×
136
                        return version();
×
137

138
                case ARG_NO_PAGER:
×
139
                        arg_pager_flags |= PAGER_DISABLE;
×
140
                        break;
×
141

142
                case ARG_NO_LEGEND:
×
143
                        arg_legend = false;
×
144
                        break;
×
145

146
                case ARG_NO_RELOAD:
×
147
                        arg_no_reload = true;
×
148
                        break;
×
149

150
                case ARG_NO_ASK_PASSWORD:
×
151
                        arg_ask_password = false;
×
152
                        break;
×
153

154
                case ARG_RUNTIME:
7✔
155
                        arg_runtime = true;
7✔
156
                        break;
7✔
157

158
                case ARG_STDIN:
1✔
159
                        arg_stdin = true;
1✔
160
                        break;
1✔
161

162
                case ARG_DROP_IN:
3✔
163
                        if (isempty(optarg))
3✔
164
                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Empty drop-in file name.");
×
165

166
                        if (!endswith(optarg, ".conf")) {
3✔
167
                                char *conf;
1✔
168

169
                                conf = strjoin(optarg, ".conf");
1✔
170
                                if (!conf)
1✔
171
                                        return log_oom();
×
172

173
                                free_and_replace(arg_drop_in, conf);
1✔
174
                        } else {
175
                                r = free_and_strdup(&arg_drop_in, optarg);
2✔
176
                                if (r < 0)
2✔
177
                                        return log_oom();
×
178
                        }
179

180
                        if (!filename_is_valid(arg_drop_in))
3✔
181
                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
×
182
                                                       "Invalid drop-in file name '%s'.", arg_drop_in);
183

184
                        break;
185

186
                case 'a':
1✔
187
                        arg_all = true;
1✔
188
                        break;
1✔
189

190
                case 's':
1✔
191
                        arg_stats = true;
1✔
192
                        break;
1✔
193

194
                case 'l':
1✔
195
                        arg_full = true;
1✔
196
                        break;
1✔
197

198
                case 'n':
1,200✔
199
                        if (safe_atou(optarg, &arg_lines) < 0)
1,200✔
200
                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
×
201
                                                       "Failed to parse lines '%s'", optarg);
202
                        break;
203

204
                case ARG_JSON:
80✔
205
                        r = parse_json_argument(optarg, &arg_json_format_flags);
80✔
206
                        if (r <= 0)
80✔
207
                                return r;
208
                        break;
209

210
                case '?':
211
                        return -EINVAL;
212

213
                default:
×
214
                        assert_not_reached();
×
215
                }
216
        }
217

218
        return 1;
219
}
220

221
static int networkctl_main(int argc, char *argv[]) {
2,335✔
222
        static const Verb verbs[] = {
2,335✔
223
                { "list",               VERB_ANY, VERB_ANY, VERB_DEFAULT|VERB_ONLINE_ONLY, list_links              },
224
                { "status",             VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY,              link_status             },
225
                { "lldp",               VERB_ANY, VERB_ANY, 0,                             link_lldp_status        },
226
                { "label",              1,        1,        0,                             list_address_labels     },
227
                { "delete",             2,        VERB_ANY, 0,                             link_delete             },
228
                { "up",                 2,        VERB_ANY, 0,                             link_up_down            },
229
                { "down",               2,        VERB_ANY, 0,                             link_up_down            },
230
                { "renew",              2,        VERB_ANY, VERB_ONLINE_ONLY,              link_renew              },
231
                { "forcerenew",         2,        VERB_ANY, VERB_ONLINE_ONLY,              link_force_renew        },
232
                { "reconfigure",        2,        VERB_ANY, VERB_ONLINE_ONLY,              verb_reconfigure        },
233
                { "reload",             1,        1,        VERB_ONLINE_ONLY,              verb_reload             },
234
                { "edit",               2,        VERB_ANY, 0,                             verb_edit               },
235
                { "cat",                1,        VERB_ANY, 0,                             verb_cat                },
236
                { "mask",               2,        VERB_ANY, 0,                             verb_mask               },
237
                { "unmask",             2,        VERB_ANY, 0,                             verb_unmask             },
238
                { "persistent-storage", 2,        2,        0,                             verb_persistent_storage },
239
                {}
240
        };
241

242
        return dispatch_verb(argc, argv, verbs, NULL);
2,335✔
243
}
244

245
static int run(int argc, char* argv[]) {
2,335✔
246
        int r;
2,335✔
247

248
        log_setup();
2,335✔
249

250
        r = parse_argv(argc, argv);
2,335✔
251
        if (r <= 0)
2,335✔
252
                return r;
253

254
        journal_browse_prepare();
2,335✔
255

256
        return networkctl_main(argc, argv);
2,335✔
257
}
258

259
DEFINE_MAIN_FUNCTION(run);
4,670✔
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