mirror of
https://github.com/Dasharo/systemd.git
synced 2026-03-06 15:02:31 -08:00
treewide: yet more log_*_errno + return simplifications
Using:
find . -name '*.[ch]' | while read f; do perl -i.mmm -e \
'local $/;
local $_=<>;
s/(if\s*\([^\n]+\))\s*{\n(\s*)(log_[a-z_]*_errno\(\s*([->a-zA-Z_]+)\s*,[^;]+);\s*return\s+\g4;\s+}/\1\n\2return \3;/msg;
print;'
$f
done
And a couple of manual whitespace fixups.
This commit is contained in:
@@ -653,10 +653,8 @@ static int setup_microhttpd_server(RemoteServer *s,
|
||||
assert(fd >= 0);
|
||||
|
||||
r = fd_nonblock(fd, true);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to make fd:%d nonblocking: %m", fd);
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to make fd:%d nonblocking: %m", fd);
|
||||
|
||||
if (key) {
|
||||
assert(cert);
|
||||
|
||||
@@ -53,10 +53,8 @@ static int object_callback(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bu
|
||||
log_info("Invoked Foobar() on %s", sd_bus_message_get_path(m));
|
||||
|
||||
r = sd_bus_reply_method_return(m, NULL);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to send reply: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to send reply: %m");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -146,10 +146,8 @@ static int client(struct context *c) {
|
||||
"/",
|
||||
"org.freedesktop.systemd.test",
|
||||
"Exit");
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to allocate method call: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to allocate method call: %m");
|
||||
|
||||
r = sd_bus_call(bus, m, 0, &error, &reply);
|
||||
if (r < 0) {
|
||||
|
||||
@@ -234,10 +234,8 @@ static int list_locales(sd_bus *bus, char **args, unsigned n) {
|
||||
assert(args);
|
||||
|
||||
r = get_locales(&l);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to read list of locales: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to read list of locales: %m");
|
||||
|
||||
pager_open_if_enabled();
|
||||
strv_print(l);
|
||||
@@ -309,10 +307,8 @@ static int nftw_cb(
|
||||
*e = 0;
|
||||
|
||||
r = set_consume(keymaps, p);
|
||||
if (r < 0 && r != -EEXIST) {
|
||||
log_error_errno(r, "Can't add keymap: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0 && r != -EEXIST)
|
||||
return log_error_errno(r, "Can't add keymap: %m");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -610,10 +610,8 @@ static int vconsole_convert_to_x11(Context *c, sd_bus *bus) {
|
||||
int r;
|
||||
|
||||
r = x11_write_data(c);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to set X11 keyboard layout: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to set X11 keyboard layout: %m");
|
||||
|
||||
log_info("Changed X11 keyboard layout to '%s' model '%s' variant '%s' options '%s'",
|
||||
strempty(c->x11_layout),
|
||||
@@ -1155,28 +1153,20 @@ static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) {
|
||||
assert(_bus);
|
||||
|
||||
r = sd_bus_default_system(&bus);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to get system bus connection: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to get system bus connection: %m");
|
||||
|
||||
r = sd_bus_add_object_vtable(bus, NULL, "/org/freedesktop/locale1", "org.freedesktop.locale1", locale_vtable, c);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to register object: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to register object: %m");
|
||||
|
||||
r = sd_bus_request_name(bus, "org.freedesktop.locale1", 0);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to register name: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to register name: %m");
|
||||
|
||||
r = sd_bus_attach_event(bus, event, 0);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to attach bus to event loop: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to attach bus to event loop: %m");
|
||||
|
||||
*_bus = bus;
|
||||
bus = NULL;
|
||||
|
||||
@@ -384,10 +384,8 @@ static int print_session_status_info(sd_bus *bus, const char *path, bool *new_li
|
||||
int r;
|
||||
|
||||
r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, &i);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Could not get properties: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not get properties: %m");
|
||||
|
||||
if (*new_line)
|
||||
printf("\n");
|
||||
@@ -699,10 +697,8 @@ static int show_user(sd_bus *bus, char **args, unsigned n) {
|
||||
uid_t uid;
|
||||
|
||||
r = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to look up user %s: %m", args[i]);
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to look up user %s: %m", args[i]);
|
||||
|
||||
r = sd_bus_call_method(
|
||||
bus,
|
||||
@@ -859,10 +855,8 @@ static int enable_linger(sd_bus *bus, char **args, unsigned n) {
|
||||
uid_t uid;
|
||||
|
||||
r = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to look up user %s: %m", args[i]);
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to look up user %s: %m", args[i]);
|
||||
|
||||
r = sd_bus_call_method (
|
||||
bus,
|
||||
@@ -892,10 +886,8 @@ static int terminate_user(sd_bus *bus, char **args, unsigned n) {
|
||||
uid_t uid;
|
||||
|
||||
r = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to look up user %s: %m", args[i]);
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to look up user %s: %m", args[i]);
|
||||
|
||||
r = sd_bus_call_method (
|
||||
bus,
|
||||
@@ -928,10 +920,8 @@ static int kill_user(sd_bus *bus, char **args, unsigned n) {
|
||||
uid_t uid;
|
||||
|
||||
r = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to look up user %s: %m", args[i]);
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to look up user %s: %m", args[i]);
|
||||
|
||||
r = sd_bus_call_method (
|
||||
bus,
|
||||
|
||||
@@ -337,10 +337,8 @@ int session_load(Session *s) {
|
||||
"CONTROLLER", &controller,
|
||||
NULL);
|
||||
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to read %s: %m", s->state_file);
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to read %s: %m", s->state_file);
|
||||
|
||||
if (!s->user) {
|
||||
uid_t u;
|
||||
|
||||
@@ -310,10 +310,8 @@ static int user_mkdir_runtime_path(User *u) {
|
||||
assert(u);
|
||||
|
||||
r = mkdir_safe_label("/run/user", 0755, 0, 0);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to create /run/user: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to create /run/user: %m");
|
||||
|
||||
if (!u->runtime_path) {
|
||||
if (asprintf(&p, "/run/user/" UID_FMT, u->uid) < 0)
|
||||
|
||||
@@ -583,52 +583,36 @@ static int manager_connect_bus(Manager *m) {
|
||||
assert(!m->bus);
|
||||
|
||||
r = sd_bus_default_system(&m->bus);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to connect to system bus: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to connect to system bus: %m");
|
||||
|
||||
r = sd_bus_add_object_vtable(m->bus, NULL, "/org/freedesktop/login1", "org.freedesktop.login1.Manager", manager_vtable, m);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to add manager object vtable: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add manager object vtable: %m");
|
||||
|
||||
r = sd_bus_add_fallback_vtable(m->bus, NULL, "/org/freedesktop/login1/seat", "org.freedesktop.login1.Seat", seat_vtable, seat_object_find, m);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to add seat object vtable: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add seat object vtable: %m");
|
||||
|
||||
r = sd_bus_add_node_enumerator(m->bus, NULL, "/org/freedesktop/login1/seat", seat_node_enumerator, m);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to add seat enumerator: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add seat enumerator: %m");
|
||||
|
||||
r = sd_bus_add_fallback_vtable(m->bus, NULL, "/org/freedesktop/login1/session", "org.freedesktop.login1.Session", session_vtable, session_object_find, m);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to add session object vtable: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add session object vtable: %m");
|
||||
|
||||
r = sd_bus_add_node_enumerator(m->bus, NULL, "/org/freedesktop/login1/session", session_node_enumerator, m);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to add session enumerator: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add session enumerator: %m");
|
||||
|
||||
r = sd_bus_add_fallback_vtable(m->bus, NULL, "/org/freedesktop/login1/user", "org.freedesktop.login1.User", user_vtable, user_object_find, m);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to add user object vtable: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add user object vtable: %m");
|
||||
|
||||
r = sd_bus_add_node_enumerator(m->bus, NULL, "/org/freedesktop/login1/user", user_node_enumerator, m);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to add user enumerator: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add user enumerator: %m");
|
||||
|
||||
r = sd_bus_add_match(m->bus,
|
||||
NULL,
|
||||
@@ -638,10 +622,8 @@ static int manager_connect_bus(Manager *m) {
|
||||
"member='NameOwnerChanged',"
|
||||
"path='/org/freedesktop/DBus'",
|
||||
match_name_owner_changed, m);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to add match for NameOwnerChanged: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add match for NameOwnerChanged: %m");
|
||||
|
||||
r = sd_bus_add_match(m->bus,
|
||||
NULL,
|
||||
@@ -651,10 +633,8 @@ static int manager_connect_bus(Manager *m) {
|
||||
"member='JobRemoved',"
|
||||
"path='/org/freedesktop/systemd1'",
|
||||
match_job_removed, m);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to add match for JobRemoved: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add match for JobRemoved: %m");
|
||||
|
||||
r = sd_bus_add_match(m->bus,
|
||||
NULL,
|
||||
@@ -664,10 +644,8 @@ static int manager_connect_bus(Manager *m) {
|
||||
"member='UnitRemoved',"
|
||||
"path='/org/freedesktop/systemd1'",
|
||||
match_unit_removed, m);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to add match for UnitRemoved: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add match for UnitRemoved: %m");
|
||||
|
||||
r = sd_bus_add_match(m->bus,
|
||||
NULL,
|
||||
@@ -676,10 +654,8 @@ static int manager_connect_bus(Manager *m) {
|
||||
"interface='org.freedesktop.DBus.Properties',"
|
||||
"member='PropertiesChanged'",
|
||||
match_properties_changed, m);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to add match for PropertiesChanged: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add match for PropertiesChanged: %m");
|
||||
|
||||
r = sd_bus_add_match(m->bus,
|
||||
NULL,
|
||||
@@ -689,10 +665,8 @@ static int manager_connect_bus(Manager *m) {
|
||||
"member='Reloading',"
|
||||
"path='/org/freedesktop/systemd1'",
|
||||
match_reloading, m);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to add match for Reloading: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add match for Reloading: %m");
|
||||
|
||||
r = sd_bus_call_method(
|
||||
m->bus,
|
||||
@@ -708,16 +682,12 @@ static int manager_connect_bus(Manager *m) {
|
||||
}
|
||||
|
||||
r = sd_bus_request_name(m->bus, "org.freedesktop.login1", 0);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to register name: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to register name: %m");
|
||||
|
||||
r = sd_bus_attach_event(m->bus, m->event, 0);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to attach bus to event loop: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to attach bus to event loop: %m");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -806,16 +776,12 @@ static int manager_connect_console(Manager *m) {
|
||||
}
|
||||
|
||||
r = ignore_signals(SIGRTMIN + 1, -1);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Cannot ignore SIGRTMIN + 1: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Cannot ignore SIGRTMIN + 1: %m");
|
||||
|
||||
r = sigprocmask_many(SIG_BLOCK, SIGRTMIN, -1);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Cannot block SIGRTMIN: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Cannot block SIGRTMIN: %m");
|
||||
|
||||
r = sd_event_add_signal(m->event, NULL, SIGRTMIN, manager_vt_switch, m);
|
||||
if (r < 0)
|
||||
@@ -1016,28 +982,20 @@ static int manager_dispatch_idle_action(sd_event_source *s, uint64_t t, void *us
|
||||
CLOCK_MONOTONIC,
|
||||
elapse, USEC_PER_SEC*30,
|
||||
manager_dispatch_idle_action, m);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to add idle event source: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add idle event source: %m");
|
||||
|
||||
r = sd_event_source_set_priority(m->idle_action_event_source, SD_EVENT_PRIORITY_IDLE+10);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to set idle event source priority: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to set idle event source priority: %m");
|
||||
} else {
|
||||
r = sd_event_source_set_time(m->idle_action_event_source, elapse);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to set idle event timer: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to set idle event timer: %m");
|
||||
|
||||
r = sd_event_source_set_enabled(m->idle_action_event_source, SD_EVENT_ONESHOT);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to enable idle event timer: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to enable idle event timer: %m");
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -1061,10 +1019,8 @@ int manager_startup(Manager *m) {
|
||||
|
||||
/* Connect to udev */
|
||||
r = manager_connect_udev(m);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to create udev watchers: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to create udev watchers: %m");
|
||||
|
||||
/* Connect to the bus */
|
||||
r = manager_connect_bus(m);
|
||||
@@ -1073,10 +1029,8 @@ int manager_startup(Manager *m) {
|
||||
|
||||
/* Instantiate magic seat 0 */
|
||||
r = manager_add_seat(m, "seat0", &m->seat0);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to add seat0: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add seat0: %m");
|
||||
|
||||
r = manager_set_lid_switch_ignore(m, 0 + IGNORE_LID_SWITCH_STARTUP_USEC);
|
||||
if (r < 0)
|
||||
|
||||
@@ -414,10 +414,8 @@ static int show_info(const char *verb, sd_bus *bus, const char *path, bool *new_
|
||||
path,
|
||||
map,
|
||||
&info);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Could not get properties: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not get properties: %m");
|
||||
|
||||
if (*new_line)
|
||||
printf("\n");
|
||||
@@ -681,16 +679,12 @@ static int login_machine(sd_bus *bus, char **args, unsigned n) {
|
||||
}
|
||||
|
||||
r = sd_event_default(&event);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to get event loop: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to get event loop: %m");
|
||||
|
||||
r = sd_bus_attach_event(bus, event, 0);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to attach bus to event loop: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to attach bus to event loop: %m");
|
||||
|
||||
r = sd_bus_call_method(
|
||||
bus,
|
||||
@@ -719,20 +713,16 @@ static int login_machine(sd_bus *bus, char **args, unsigned n) {
|
||||
&error,
|
||||
&reply2,
|
||||
"u");
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to retrieve PID of leader: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to retrieve PID of leader: %m");
|
||||
|
||||
r = sd_bus_message_read(reply2, "u", &leader);
|
||||
if (r < 0)
|
||||
return bus_log_parse_error(r);
|
||||
|
||||
master = openpt_in_namespace(leader, O_RDWR|O_NOCTTY|O_CLOEXEC|O_NDELAY);
|
||||
if (master < 0) {
|
||||
log_error_errno(master, "Failed to acquire pseudo tty: %m");
|
||||
return master;
|
||||
}
|
||||
if (master < 0)
|
||||
return log_error_errno(master, "Failed to acquire pseudo tty: %m");
|
||||
|
||||
pty = ptsname(master);
|
||||
if (!pty) {
|
||||
@@ -747,10 +737,8 @@ static int login_machine(sd_bus *bus, char **args, unsigned n) {
|
||||
}
|
||||
|
||||
r = sd_bus_open_system_container(&container_bus, args[1]);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to get container bus: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to get container bus: %m");
|
||||
|
||||
getty = strjoin("container-getty@", p, ".service", NULL);
|
||||
if (!getty)
|
||||
@@ -785,16 +773,12 @@ static int login_machine(sd_bus *bus, char **args, unsigned n) {
|
||||
sd_event_add_signal(event, NULL, SIGTERM, NULL, NULL);
|
||||
|
||||
r = pty_forward_new(event, master, &forward);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to create PTY forwarder: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to create PTY forwarder: %m");
|
||||
|
||||
r = sd_event_loop(event);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to run event loop: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to run event loop: %m");
|
||||
|
||||
forward = pty_forward_free(forward);
|
||||
|
||||
|
||||
@@ -137,28 +137,20 @@ static int manager_connect_bus(Manager *m) {
|
||||
assert(!m->bus);
|
||||
|
||||
r = sd_bus_default_system(&m->bus);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to connect to system bus: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to connect to system bus: %m");
|
||||
|
||||
r = sd_bus_add_object_vtable(m->bus, NULL, "/org/freedesktop/machine1", "org.freedesktop.machine1.Manager", manager_vtable, m);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to add manager object vtable: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add manager object vtable: %m");
|
||||
|
||||
r = sd_bus_add_fallback_vtable(m->bus, NULL, "/org/freedesktop/machine1/machine", "org.freedesktop.machine1.Machine", machine_vtable, machine_object_find, m);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to add machine object vtable: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add machine object vtable: %m");
|
||||
|
||||
r = sd_bus_add_node_enumerator(m->bus, NULL, "/org/freedesktop/machine1/machine", machine_node_enumerator, m);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to add machine enumerator: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add machine enumerator: %m");
|
||||
|
||||
r = sd_bus_add_match(m->bus,
|
||||
NULL,
|
||||
@@ -169,10 +161,8 @@ static int manager_connect_bus(Manager *m) {
|
||||
"path='/org/freedesktop/systemd1'",
|
||||
match_job_removed,
|
||||
m);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to add match for JobRemoved: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add match for JobRemoved: %m");
|
||||
|
||||
r = sd_bus_add_match(m->bus,
|
||||
NULL,
|
||||
@@ -183,10 +173,8 @@ static int manager_connect_bus(Manager *m) {
|
||||
"path='/org/freedesktop/systemd1'",
|
||||
match_unit_removed,
|
||||
m);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to add match for UnitRemoved: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add match for UnitRemoved: %m");
|
||||
|
||||
r = sd_bus_add_match(m->bus,
|
||||
NULL,
|
||||
@@ -196,10 +184,8 @@ static int manager_connect_bus(Manager *m) {
|
||||
"member='PropertiesChanged'",
|
||||
match_properties_changed,
|
||||
m);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to add match for PropertiesChanged: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add match for PropertiesChanged: %m");
|
||||
|
||||
r = sd_bus_add_match(m->bus,
|
||||
NULL,
|
||||
@@ -210,10 +196,8 @@ static int manager_connect_bus(Manager *m) {
|
||||
"path='/org/freedesktop/systemd1'",
|
||||
match_reloading,
|
||||
m);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to add match for Reloading: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add match for Reloading: %m");
|
||||
|
||||
r = sd_bus_call_method(
|
||||
m->bus,
|
||||
@@ -229,16 +213,12 @@ static int manager_connect_bus(Manager *m) {
|
||||
}
|
||||
|
||||
r = sd_bus_request_name(m->bus, "org.freedesktop.machine1", 0);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to register name: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to register name: %m");
|
||||
|
||||
r = sd_bus_attach_event(m->bus, m->event, 0);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to attach bus to event loop: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to attach bus to event loop: %m");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -81,10 +81,8 @@ static int load_module(struct kmod_ctx *ctx, const char *m) {
|
||||
log_debug("load: %s", m);
|
||||
|
||||
r = kmod_module_new_from_lookup(ctx, m, &modlist);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to lookup alias '%s': %m", m);
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to lookup alias '%s': %m", m);
|
||||
|
||||
if (!modlist) {
|
||||
log_error("Failed to find module '%s'", m);
|
||||
|
||||
@@ -190,10 +190,8 @@ static int list_links(char **args, unsigned n) {
|
||||
pager_open_if_enabled();
|
||||
|
||||
r = sd_rtnl_open(&rtnl, 0);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to connect to netlink: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to connect to netlink: %m");
|
||||
|
||||
udev = udev_new();
|
||||
if (!udev) {
|
||||
@@ -210,10 +208,8 @@ static int list_links(char **args, unsigned n) {
|
||||
return rtnl_log_create_error(r);
|
||||
|
||||
r = sd_rtnl_call(rtnl, req, 0, &reply);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to enumerate links: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to enumerate links: %m");
|
||||
|
||||
if (arg_legend)
|
||||
printf("%3s %-16s %-18s %-11s %-10s\n", "IDX", "LINK", "TYPE", "OPERATIONAL", "SETUP");
|
||||
@@ -322,10 +318,8 @@ static int link_status_one(sd_rtnl *rtnl, struct udev *udev, const char *name) {
|
||||
return rtnl_log_create_error(r);
|
||||
|
||||
r = sd_rtnl_call(rtnl, req, 0, &reply);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to query link: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to query link: %m");
|
||||
|
||||
r = sd_rtnl_message_link_get_ifindex(reply, &ifindex);
|
||||
if (r < 0)
|
||||
@@ -447,10 +441,8 @@ static int link_status(char **args, unsigned n) {
|
||||
int r;
|
||||
|
||||
r = sd_rtnl_open(&rtnl, 0);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to connect to netlink: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to connect to netlink: %m");
|
||||
|
||||
udev = udev_new();
|
||||
if (!udev) {
|
||||
@@ -513,10 +505,8 @@ static int link_status(char **args, unsigned n) {
|
||||
return rtnl_log_create_error(r);
|
||||
|
||||
r = sd_rtnl_call(rtnl, req, 0, &reply);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to enumerate links: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to enumerate links: %m");
|
||||
|
||||
c = decode_and_sort_links(reply, &links);
|
||||
if (c < 0)
|
||||
|
||||
@@ -355,10 +355,8 @@ int manager_udev_listen(Manager *m) {
|
||||
assert(m->udev_monitor);
|
||||
|
||||
r = udev_monitor_filter_add_match_subsystem_devtype(m->udev_monitor, "net", NULL);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Could not add udev monitor filter: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not add udev monitor filter: %m");
|
||||
|
||||
r = udev_monitor_enable_receiving(m->udev_monitor);
|
||||
if (r < 0) {
|
||||
|
||||
@@ -46,10 +46,8 @@ static int netdev_veth_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_m
|
||||
|
||||
if (v->ifname_peer) {
|
||||
r = sd_rtnl_message_append_string(m, IFLA_IFNAME, v->ifname_peer);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to add netlink interface name: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to add netlink interface name: %m");
|
||||
}
|
||||
|
||||
if (v->mac_peer) {
|
||||
|
||||
@@ -743,10 +743,8 @@ int netdev_load(Manager *manager) {
|
||||
netdev_unref(netdev);
|
||||
|
||||
r = conf_files_list_strv(&files, ".netdev", NULL, network_dirs);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to enumerate netdev files: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to enumerate netdev files: %m");
|
||||
|
||||
STRV_FOREACH_BACKWARDS(f, files) {
|
||||
r = netdev_load_one(manager, *f);
|
||||
|
||||
@@ -131,10 +131,8 @@ int network_load(Manager *manager) {
|
||||
network_free(network);
|
||||
|
||||
r = conf_files_list_strv(&files, ".network", NULL, network_dirs);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to enumerate network files: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to enumerate network files: %m");
|
||||
|
||||
STRV_FOREACH_BACKWARDS(f, files) {
|
||||
r = network_load_one(manager, *f);
|
||||
|
||||
@@ -113,20 +113,16 @@ int route_drop(Route *route, Link *link,
|
||||
r = sd_rtnl_message_new_route(link->manager->rtnl, &req,
|
||||
RTM_DELROUTE, route->family,
|
||||
route->protocol);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Could not create RTM_DELROUTE message: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not create RTM_DELROUTE message: %m");
|
||||
|
||||
if (!in_addr_is_null(route->family, &route->in_addr)) {
|
||||
if (route->family == AF_INET)
|
||||
r = sd_rtnl_message_append_in_addr(req, RTA_GATEWAY, &route->in_addr.in);
|
||||
else if (route->family == AF_INET6)
|
||||
r = sd_rtnl_message_append_in6_addr(req, RTA_GATEWAY, &route->in_addr.in6);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Could not append RTA_GATEWAY attribute: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append RTA_GATEWAY attribute: %m");
|
||||
}
|
||||
|
||||
if (route->dst_prefixlen) {
|
||||
@@ -134,16 +130,12 @@ int route_drop(Route *route, Link *link,
|
||||
r = sd_rtnl_message_append_in_addr(req, RTA_DST, &route->dst_addr.in);
|
||||
else if (route->family == AF_INET6)
|
||||
r = sd_rtnl_message_append_in6_addr(req, RTA_DST, &route->dst_addr.in6);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Could not append RTA_DST attribute: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append RTA_DST attribute: %m");
|
||||
|
||||
r = sd_rtnl_message_route_set_dst_prefixlen(req, route->dst_prefixlen);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Could not set destination prefix length: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not set destination prefix length: %m");
|
||||
}
|
||||
|
||||
if (!in_addr_is_null(route->family, &route->prefsrc_addr)) {
|
||||
@@ -151,35 +143,25 @@ int route_drop(Route *route, Link *link,
|
||||
r = sd_rtnl_message_append_in_addr(req, RTA_PREFSRC, &route->prefsrc_addr.in);
|
||||
else if (route->family == AF_INET6)
|
||||
r = sd_rtnl_message_append_in6_addr(req, RTA_PREFSRC, &route->prefsrc_addr.in6);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Could not append RTA_PREFSRC attribute: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append RTA_PREFSRC attribute: %m");
|
||||
}
|
||||
|
||||
r = sd_rtnl_message_route_set_scope(req, route->scope);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Could not set scope: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not set scope: %m");
|
||||
|
||||
r = sd_rtnl_message_append_u32(req, RTA_PRIORITY, route->metrics);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Could not append RTA_PRIORITY attribute: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append RTA_PRIORITY attribute: %m");
|
||||
|
||||
r = sd_rtnl_message_append_u32(req, RTA_OIF, link->ifindex);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Could not append RTA_OIF attribute: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append RTA_OIF attribute: %m");
|
||||
|
||||
r = sd_rtnl_call_async(link->manager->rtnl, req, callback, link, 0, NULL);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Could not send rtnetlink message: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not send rtnetlink message: %m");
|
||||
|
||||
link_ref(link);
|
||||
|
||||
@@ -200,20 +182,16 @@ int route_configure(Route *route, Link *link,
|
||||
r = sd_rtnl_message_new_route(link->manager->rtnl, &req,
|
||||
RTM_NEWROUTE, route->family,
|
||||
route->protocol);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Could not create RTM_NEWROUTE message: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not create RTM_NEWROUTE message: %m");
|
||||
|
||||
if (!in_addr_is_null(route->family, &route->in_addr)) {
|
||||
if (route->family == AF_INET)
|
||||
r = sd_rtnl_message_append_in_addr(req, RTA_GATEWAY, &route->in_addr.in);
|
||||
else if (route->family == AF_INET6)
|
||||
r = sd_rtnl_message_append_in6_addr(req, RTA_GATEWAY, &route->in_addr.in6);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Could not append RTA_GATEWAY attribute: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append RTA_GATEWAY attribute: %m");
|
||||
}
|
||||
|
||||
if (route->dst_prefixlen) {
|
||||
@@ -221,16 +199,12 @@ int route_configure(Route *route, Link *link,
|
||||
r = sd_rtnl_message_append_in_addr(req, RTA_DST, &route->dst_addr.in);
|
||||
else if (route->family == AF_INET6)
|
||||
r = sd_rtnl_message_append_in6_addr(req, RTA_DST, &route->dst_addr.in6);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Could not append RTA_DST attribute: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append RTA_DST attribute: %m");
|
||||
|
||||
r = sd_rtnl_message_route_set_dst_prefixlen(req, route->dst_prefixlen);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Could not set destination prefix length: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not set destination prefix length: %m");
|
||||
}
|
||||
|
||||
if (!in_addr_is_null(route->family, &route->prefsrc_addr)) {
|
||||
@@ -238,35 +212,25 @@ int route_configure(Route *route, Link *link,
|
||||
r = sd_rtnl_message_append_in_addr(req, RTA_PREFSRC, &route->prefsrc_addr.in);
|
||||
else if (route->family == AF_INET6)
|
||||
r = sd_rtnl_message_append_in6_addr(req, RTA_PREFSRC, &route->prefsrc_addr.in6);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Could not append RTA_PREFSRC attribute: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append RTA_PREFSRC attribute: %m");
|
||||
}
|
||||
|
||||
r = sd_rtnl_message_route_set_scope(req, route->scope);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Could not set scope: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not set scope: %m");
|
||||
|
||||
r = sd_rtnl_message_append_u32(req, RTA_PRIORITY, route->metrics);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Could not append RTA_PRIORITY attribute: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append RTA_PRIORITY attribute: %m");
|
||||
|
||||
r = sd_rtnl_message_append_u32(req, RTA_OIF, link->ifindex);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Could not append RTA_OIF attribute: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append RTA_OIF attribute: %m");
|
||||
|
||||
r = sd_rtnl_call_async(link->manager->rtnl, req, callback, link, 0, NULL);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Could not send rtnetlink message: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not send rtnetlink message: %m");
|
||||
|
||||
link_ref(link);
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -108,10 +108,8 @@ static int print_home(const char *n) {
|
||||
_cleanup_free_ char *p = NULL;
|
||||
|
||||
r = sd_path_home(i, arg_suffix, &p);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to query %s: %m", n);
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to query %s: %m", n);
|
||||
|
||||
printf("%s\n", p);
|
||||
return 0;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user