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

systemd / systemd / 19200508431

08 Nov 2025 07:53PM UTC coverage: 72.411% (+0.3%) from 72.098%
19200508431

push

github

yuwata
README: align features after 'for'

307177 of 424213 relevant lines covered (72.41%)

1185389.63 hits per line

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

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

3
#include "sd-varlink.h"
4

5
#include "alloc-util.h"
6
#include "glob-util.h"
7
#include "json-util.h"
8
#include "log.h"
9
#include "networkctl.h"
10
#include "networkctl-description.h"
11
#include "networkctl-util.h"
12
#include "stdio-util.h"
13
#include "strv.h"
14
#include "varlink-util.h"
15

16
static int dump_manager_description(sd_varlink *vl) {
72✔
17
        sd_json_variant *v;
72✔
18
        int r;
72✔
19

20
        assert(vl);
72✔
21

22
        r = varlink_call_and_log(vl, "io.systemd.Network.Describe", /* parameters = */ NULL, &v);
72✔
23
        if (r < 0)
72✔
24
                return r;
72✔
25

26
        r = sd_json_variant_dump(v, arg_json_format_flags, /* f = */ NULL, /* prefix = */ NULL);
72✔
27
        if (r < 0)
72✔
28
                return log_error_errno(r, "Failed to dump json object: %m");
×
29
        return 0;
30
}
31

32
static int dump_link_description(sd_varlink *vl, char * const *patterns) {
6✔
33
        _cleanup_free_ bool *matched_patterns = NULL;
6✔
34
        sd_json_variant *i, *v;
6✔
35
        size_t c = 0;
6✔
36
        int r;
6✔
37

38
        assert(vl);
6✔
39
        assert(patterns);
6✔
40

41
        r = varlink_call_and_log(vl, "io.systemd.Network.Describe", /* parameters = */ NULL, &v);
6✔
42
        if (r < 0)
6✔
43
                return r;
44

45
        matched_patterns = new0(bool, strv_length(patterns));
6✔
46
        if (!matched_patterns)
6✔
47
                return log_oom();
×
48

49
        JSON_VARIANT_ARRAY_FOREACH(i, sd_json_variant_by_key(v, "Interfaces")) {
51✔
50
                char ifindex_str[DECIMAL_STR_MAX(int64_t)];
45✔
51
                const char *name;
45✔
52
                int64_t index;
45✔
53
                size_t pos;
45✔
54

55
                name = sd_json_variant_string(sd_json_variant_by_key(i, "Name"));
45✔
56
                index = sd_json_variant_integer(sd_json_variant_by_key(i, "Index"));
45✔
57
                xsprintf(ifindex_str, "%" PRIi64, index);
45✔
58

59
                if (!strv_fnmatch_full(patterns, ifindex_str, 0, &pos) &&
90✔
60
                    !strv_fnmatch_full(patterns, name, 0, &pos)) {
45✔
61
                        bool match = false;
39✔
62
                        sd_json_variant *a;
39✔
63

64
                        JSON_VARIANT_ARRAY_FOREACH(a, sd_json_variant_by_key(i, "AlternativeNames"))
39✔
65
                                if (strv_fnmatch_full(patterns, sd_json_variant_string(a), 0, &pos)) {
×
66
                                        match = true;
67
                                        break;
68
                                }
69

70
                        if (!match)
39✔
71
                                continue;
39✔
72
                }
73

74
                matched_patterns[pos] = true;
6✔
75
                sd_json_variant_dump(i, arg_json_format_flags, NULL, NULL);
6✔
76
                c++;
6✔
77
        }
78

79
        /* Look if we matched all our arguments that are not globs. It is OK for a glob to match
80
         * nothing, but not for an exact argument. */
81
        for (size_t pos = 0; pos < strv_length(patterns); pos++) {
12✔
82
                if (matched_patterns[pos])
6✔
83
                        continue;
6✔
84

85
                if (string_is_glob(patterns[pos]))
×
86
                        log_debug("Pattern \"%s\" doesn't match any interface, ignoring.",
×
87
                                  patterns[pos]);
88
                else
89
                        return log_error_errno(SYNTHETIC_ERRNO(ENODEV),
×
90
                                               "Interface \"%s\" not found.", patterns[pos]);
91
        }
92

93
        if (c == 0)
6✔
94
                log_warning("No interfaces matched.");
×
95

96
        return 0;
97
}
98

99
int dump_description(int argc, char *argv[]) {
1,514✔
100
        _cleanup_(sd_varlink_flush_close_unrefp) sd_varlink *vl = NULL;
1,514✔
101
        int r;
1,514✔
102

103
        if (!sd_json_format_enabled(arg_json_format_flags))
1,514✔
104
                return 0;
105

106
        r = varlink_connect_networkd(&vl);
78✔
107
        if (r < 0)
78✔
108
                return r;
109

110
        if (arg_all || argc <= 1)
78✔
111
                r = dump_manager_description(vl);
72✔
112
        else
113
                r = dump_link_description(vl, strv_skip(argv, 1));
6✔
114
        if (r < 0)
78✔
115
                return r;
×
116

117
        return 1; /* done */
118
}
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