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

systemd / systemd / 14766779411

30 Apr 2025 04:55PM UTC coverage: 72.225% (-0.06%) from 72.282%
14766779411

push

github

web-flow
wait-online: handle varlink connection errors while waiting for DNS (#37283)

Currently, if systemd-networkd-wait-online is started with --dns, and
systemd-resolved is not running, it will exit with an error right away.
Similarly, if systemd-resolved is restarted while waiting for DNS
configuration, systemd-networkd-wait-online will not attempt to
re-connect, and will potentially never see subsequent DNS
configurations.

Improve this by adding socket units for the systemd-resolved varlink
servers, and re-establish the connection in systemd-networkd-wait-online
when we receive `SD_VARLINK_ERROR_DISCONNECTED`.

8 of 16 new or added lines in 2 files covered. (50.0%)

5825 existing lines in 217 files now uncovered.

297168 of 411450 relevant lines covered (72.22%)

695892.62 hits per line

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

84.09
/src/systemctl/systemctl-set-default.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include "bus-error.h"
4
#include "bus-locator.h"
5
#include "proc-cmdline.h"
6
#include "systemctl.h"
7
#include "systemctl-daemon-reload.h"
8
#include "systemctl-set-default.h"
9
#include "systemctl-util.h"
10

11
static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
115✔
12
        char **ret = data;
115✔
13

14
        if (streq(key, "systemd.unit")) {
115✔
15
                if (proc_cmdline_value_missing(key, value))
5✔
16
                        return 0;
17
                if (!unit_name_is_valid(value, UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE)) {
5✔
18
                        log_warning("Unit name specified on %s= is not valid, ignoring: %s", key, value);
×
19
                        return 0;
×
20
                }
21

22
                return free_and_strdup_warn(ret, key);
5✔
23

24
        } else if (!value) {
110✔
25
                if (runlevel_to_target(key))
15✔
26
                        return free_and_strdup_warn(ret, key);
×
27
        }
28

29
        return 0;
30
}
31

32
static void emit_cmdline_warning(void) {
10✔
33
        if (arg_quiet || arg_root)
10✔
34
                /* don't bother checking the command line if we're operating on a container */
35
                return;
5✔
36

37
        _cleanup_free_ char *override = NULL;
5✔
38
        int r;
5✔
39

40
        r = proc_cmdline_parse(parse_proc_cmdline_item, &override, 0);
5✔
41
        if (r < 0)
5✔
42
                log_debug_errno(r, "Failed to parse kernel command line, ignoring: %m");
×
43
        if (override)
5✔
44
                log_notice("Note: found \"%s\" on the kernel command line, which overrides the default unit.",
5✔
45
                           override);
46
}
47

48
static int determine_default(char **ret_name) {
10✔
49
        int r;
10✔
50

51
        if (install_client_side()) {
10✔
52
                r = unit_file_get_default(arg_runtime_scope, arg_root, ret_name);
5✔
53
                if (r == -ERFKILL)
5✔
54
                        return log_error_errno(r, "Failed to get default target: Unit file is masked.");
×
55
                if (r < 0)
5✔
56
                        return log_error_errno(r, "Failed to get default target: %m");
×
57
                return 0;
58

59
        } else {
60
                sd_bus *bus;
5✔
61
                _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
5✔
62
                _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
5✔
63
                const char *name;
5✔
64

65
                r = acquire_bus(BUS_MANAGER, &bus);
5✔
66
                if (r < 0)
5✔
67
                        return r;
68

69
                r = bus_call_method(bus, bus_systemd_mgr, "GetDefaultTarget", &error, &reply, NULL);
5✔
70
                if (r < 0)
5✔
71
                        return log_error_errno(r, "Failed to get default target: %s", bus_error_message(&error, r));
×
72

73
                r = sd_bus_message_read(reply, "s", &name);
5✔
74
                if (r < 0)
5✔
75
                        return bus_log_parse_error(r);
×
76

77
                return free_and_strdup_warn(ret_name, name);
5✔
78
        }
79
}
80

81
int verb_get_default(int argc, char *argv[], void *userdata) {
6✔
82
        _cleanup_free_ char *name = NULL;
6✔
83
        int r;
6✔
84

85
        r = determine_default(&name);
6✔
86
        if (r < 0)
6✔
87
                return r;
88

89
        printf("%s\n", name);
6✔
90

91
        emit_cmdline_warning();
6✔
92

93
        return 0;
94
}
95

96
int verb_set_default(int argc, char *argv[], void *userdata) {
4✔
97
        _cleanup_free_ char *unit = NULL;
4✔
98
        int r;
4✔
99

100
        assert(argc >= 2);
4✔
101
        assert(argv);
4✔
102

103
        r = unit_name_mangle_with_suffix(argv[1], "set-default",
4✔
104
                                         arg_quiet ? 0 : UNIT_NAME_MANGLE_WARN,
4✔
105
                                         ".target", &unit);
106
        if (r < 0)
4✔
107
                return log_error_errno(r, "Failed to mangle unit name: %m");
×
108

109
        if (install_client_side()) {
4✔
110
                InstallChange *changes = NULL;
2✔
111
                size_t n_changes = 0;
2✔
112

113
                CLEANUP_ARRAY(changes, n_changes, install_changes_free);
2✔
114

115
                r = unit_file_set_default(arg_runtime_scope, UNIT_FILE_FORCE, arg_root, unit, &changes, &n_changes);
2✔
116
                install_changes_dump(r, "set default", changes, n_changes, arg_quiet);
2✔
117
                if (r < 0)
2✔
118
                        return r;
×
119
        } else {
120
                _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
×
121
                _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
2✔
122
                sd_bus *bus;
2✔
123

124
                polkit_agent_open_maybe();
2✔
125

126
                r = acquire_bus(BUS_MANAGER, &bus);
2✔
127
                if (r < 0)
2✔
128
                        return r;
129

130
                r = bus_call_method(bus, bus_systemd_mgr, "SetDefaultTarget", &error, &reply, "sb", unit, 1);
2✔
131
                if (r < 0)
2✔
132
                        return log_error_errno(r, "Failed to set default target: %s", bus_error_message(&error, r));
×
133

134
                r = bus_deserialize_and_dump_unit_file_changes(reply, arg_quiet);
2✔
135
                if (r < 0)
2✔
136
                        return r;
137

138
                /* Try to reload if enabled */
139
                if (!arg_no_reload) {
2✔
140
                        r = daemon_reload(ACTION_RELOAD, /* graceful= */ false);
2✔
141
                        if (r < 0)
2✔
142
                                return r;
143
                }
144
        }
145

146
        emit_cmdline_warning();
4✔
147

148
        if (!arg_quiet) {
4✔
149
                _cleanup_free_ char *final = NULL;
4✔
150

151
                r = determine_default(&final);
4✔
152
                if (r < 0)
4✔
153
                        return r;
×
154

155
                if (!streq(final, unit))
4✔
UNCOV
156
                        log_notice("Note: \"%s\" is the default unit (possibly a runtime override).", final);
×
157
        }
158

159
        return 0;
160
}
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