1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-02 10:51:20 +03:00

treewide: simplify log_*_errno(r,...) immediately followed by "return r"

This commit is contained in:
Michal Schmidt 2014-11-28 17:34:26 +01:00
parent c33b329709
commit eb56eb9b40
10 changed files with 137 additions and 252 deletions

View File

@ -65,10 +65,8 @@ static int open_sockets(int *epoll_fd, bool accept) {
int count = 0; int count = 0;
n = sd_listen_fds(true); n = sd_listen_fds(true);
if (n < 0) { if (n < 0)
log_error_errno(n, "Failed to read listening file descriptors from environment: %m"); return log_error_errno(n, "Failed to read listening file descriptors from environment: %m");
return n;
}
if (n > 0) { if (n > 0) {
log_info("Received %i descriptors via the environment.", n); log_info("Received %i descriptors via the environment.", n);

View File

@ -141,11 +141,9 @@ static int manager_sysview_session_add(Manager *m, sysview_event *event) {
int r; int r;
r = sysview_session_take_control(session); r = sysview_session_take_control(session);
if (r < 0) { if (r < 0)
log_error_errno(r, "Cannot request session control on '%s': %m", return log_error_errno(r, "Cannot request session control on '%s': %m",
sysview_session_get_name(session)); sysview_session_get_name(session));
return r;
}
r = session_new(&s, m, session); r = session_new(&s, m, session);
if (r < 0) { if (r < 0) {

View File

@ -729,10 +729,8 @@ static int manager_setup_kdbus(Manager *m) {
m->running_as == SYSTEMD_SYSTEM ? "system" : "user", m->running_as == SYSTEMD_SYSTEM ? "system" : "user",
m->running_as == SYSTEMD_SYSTEM, &p); m->running_as == SYSTEMD_SYSTEM, &p);
if (m->kdbus_fd < 0) { if (m->kdbus_fd < 0)
log_debug_errno(m->kdbus_fd, "Failed to set up kdbus: %m"); return log_debug_errno(m->kdbus_fd, "Failed to set up kdbus: %m");
return m->kdbus_fd;
}
log_debug("Successfully set up kdbus on %s", p); log_debug("Successfully set up kdbus on %s", p);
#endif #endif

View File

@ -320,11 +320,9 @@ static int get_source_for_fd(RemoteServer *s,
return log_oom(); return log_oom();
r = get_writer(s, name, &writer); r = get_writer(s, name, &writer);
if (r < 0) { if (r < 0)
log_warning_errno(r, "Failed to get writer for source %s: %m", return log_warning_errno(r, "Failed to get writer for source %s: %m",
name); name);
return r;
}
if (s->sources[fd] == NULL) { if (s->sources[fd] == NULL) {
s->sources[fd] = source_new(fd, false, name, writer); s->sources[fd] = source_new(fd, false, name, writer);
@ -459,11 +457,9 @@ static int request_meta(void **connection_cls, int fd, char *hostname) {
return 0; return 0;
r = get_writer(server, hostname, &writer); r = get_writer(server, hostname, &writer);
if (r < 0) { if (r < 0)
log_warning_errno(r, "Failed to get writer for source %s: %m", return log_warning_errno(r, "Failed to get writer for source %s: %m",
hostname); hostname);
return r;
}
source = source_new(fd, true, hostname, writer); source = source_new(fd, true, hostname, writer);
if (!source) { if (!source) {
@ -855,10 +851,9 @@ static int remoteserver_init(RemoteServer *s,
return r; return r;
n = sd_listen_fds(true); n = sd_listen_fds(true);
if (n < 0) { if (n < 0)
log_error_errno(n, "Failed to read listening file descriptors from environment: %m"); return log_error_errno(n, "Failed to read listening file descriptors from environment: %m");
return n; else
} else
log_info("Received %d descriptors", n); log_info("Received %d descriptors", n);
if (MAX(http_socket, https_socket) >= SD_LISTEN_FDS_START + n) { if (MAX(http_socket, https_socket) >= SD_LISTEN_FDS_START + n) {
@ -1460,28 +1455,22 @@ static int load_certificates(char **key, char **cert, char **trust) {
int r; int r;
r = read_full_file(arg_key ?: PRIV_KEY_FILE, key, NULL); r = read_full_file(arg_key ?: PRIV_KEY_FILE, key, NULL);
if (r < 0) { if (r < 0)
log_error_errno(r, "Failed to read key from file '%s': %m", return log_error_errno(r, "Failed to read key from file '%s': %m",
arg_key ?: PRIV_KEY_FILE); arg_key ?: PRIV_KEY_FILE);
return r;
}
r = read_full_file(arg_cert ?: CERT_FILE, cert, NULL); r = read_full_file(arg_cert ?: CERT_FILE, cert, NULL);
if (r < 0) { if (r < 0)
log_error_errno(r, "Failed to read certificate from file '%s': %m", return log_error_errno(r, "Failed to read certificate from file '%s': %m",
arg_cert ?: CERT_FILE); arg_cert ?: CERT_FILE);
return r;
}
if (arg_trust_all) if (arg_trust_all)
log_info("Certificate checking disabled."); log_info("Certificate checking disabled.");
else { else {
r = read_full_file(arg_trust ?: TRUST_FILE, trust, NULL); r = read_full_file(arg_trust ?: TRUST_FILE, trust, NULL);
if (r < 0) { if (r < 0)
log_error_errno(r, "Failed to read CA certificate file '%s': %m", return log_error_errno(r, "Failed to read CA certificate file '%s': %m",
arg_trust ?: TRUST_FILE); arg_trust ?: TRUST_FILE);
return r;
}
} }
return 0; return 0;

View File

@ -25,10 +25,8 @@ static ssize_t write_entry(char *buf, size_t size, Uploader *u) {
u->current_cursor = NULL; u->current_cursor = NULL;
r = sd_journal_get_cursor(u->journal, &u->current_cursor); r = sd_journal_get_cursor(u->journal, &u->current_cursor);
if (r < 0) { if (r < 0)
log_error_errno(r, "Failed to get cursor: %m"); return log_error_errno(r, "Failed to get cursor: %m");
return r;
}
r = snprintf(buf + pos, size - pos, r = snprintf(buf + pos, size - pos,
"__CURSOR=%s\n", u->current_cursor); "__CURSOR=%s\n", u->current_cursor);
@ -51,10 +49,8 @@ static ssize_t write_entry(char *buf, size_t size, Uploader *u) {
usec_t realtime; usec_t realtime;
r = sd_journal_get_realtime_usec(u->journal, &realtime); r = sd_journal_get_realtime_usec(u->journal, &realtime);
if (r < 0) { if (r < 0)
log_error_errno(r, "Failed to get realtime timestamp: %m"); return log_error_errno(r, "Failed to get realtime timestamp: %m");
return r;
}
r = snprintf(buf + pos, size - pos, r = snprintf(buf + pos, size - pos,
"__REALTIME_TIMESTAMP="USEC_FMT"\n", realtime); "__REALTIME_TIMESTAMP="USEC_FMT"\n", realtime);
@ -78,10 +74,8 @@ static ssize_t write_entry(char *buf, size_t size, Uploader *u) {
sd_id128_t boot_id; sd_id128_t boot_id;
r = sd_journal_get_monotonic_usec(u->journal, &monotonic, &boot_id); r = sd_journal_get_monotonic_usec(u->journal, &monotonic, &boot_id);
if (r < 0) { if (r < 0)
log_error_errno(r, "Failed to get monotonic timestamp: %m"); return log_error_errno(r, "Failed to get monotonic timestamp: %m");
return r;
}
r = snprintf(buf + pos, size - pos, r = snprintf(buf + pos, size - pos,
"__MONOTONIC_TIMESTAMP="USEC_FMT"\n", monotonic); "__MONOTONIC_TIMESTAMP="USEC_FMT"\n", monotonic);
@ -105,10 +99,8 @@ static ssize_t write_entry(char *buf, size_t size, Uploader *u) {
char sid[33]; char sid[33];
r = sd_journal_get_monotonic_usec(u->journal, NULL, &boot_id); r = sd_journal_get_monotonic_usec(u->journal, NULL, &boot_id);
if (r < 0) { if (r < 0)
log_error_errno(r, "Failed to get monotonic timestamp: %m"); return log_error_errno(r, "Failed to get monotonic timestamp: %m");
return r;
}
r = snprintf(buf + pos, size - pos, r = snprintf(buf + pos, size - pos,
"_BOOT_ID=%s\n", sd_id128_to_string(boot_id, sid)); "_BOOT_ID=%s\n", sd_id128_to_string(boot_id, sid));
@ -133,10 +125,9 @@ static ssize_t write_entry(char *buf, size_t size, Uploader *u) {
r = sd_journal_enumerate_data(u->journal, r = sd_journal_enumerate_data(u->journal,
&u->field_data, &u->field_data,
&u->field_length); &u->field_length);
if (r < 0) { if (r < 0)
log_error_errno(r, "Failed to move to next field in entry: %m"); return log_error_errno(r, "Failed to move to next field in entry: %m");
return r; else if (r == 0) {
} else if (r == 0) {
u->entry_state = ENTRY_OUTRO; u->entry_state = ENTRY_OUTRO;
continue; continue;
} }
@ -302,10 +293,9 @@ static int process_journal_input(Uploader *u, int skip) {
int r; int r;
r = sd_journal_next_skip(u->journal, skip); r = sd_journal_next_skip(u->journal, skip);
if (r < 0) { if (r < 0)
log_error_errno(r, "Failed to skip to next entry: %m"); return log_error_errno(r, "Failed to skip to next entry: %m");
return r; else if (r < skip)
} else if (r < skip)
return 0; return 0;
/* have data */ /* have data */
@ -361,10 +351,8 @@ int open_journal_for_upload(Uploader *u,
if (follow) { if (follow) {
fd = sd_journal_get_fd(j); fd = sd_journal_get_fd(j);
if (fd < 0) { if (fd < 0)
log_error_errno(fd, "sd_journal_get_fd failed: %m"); return log_error_errno(fd, "sd_journal_get_fd failed: %m");
return fd;
}
events = sd_journal_get_events(j); events = sd_journal_get_events(j);
@ -377,10 +365,8 @@ int open_journal_for_upload(Uploader *u,
r = sd_event_add_io(u->events, &u->input_event, r = sd_event_add_io(u->events, &u->input_event,
fd, events, dispatch_journal_input, u); fd, events, dispatch_journal_input, u);
if (r < 0) { if (r < 0)
log_error_errno(r, "Failed to register input event: %m"); return log_error_errno(r, "Failed to register input event: %m");
return r;
}
log_debug("Listening for journal events on fd:%d, timeout %d", log_debug("Listening for journal events on fd:%d, timeout %d",
fd, u->timeout == (uint64_t) -1 ? -1 : (int) u->timeout); fd, u->timeout == (uint64_t) -1 ? -1 : (int) u->timeout);
@ -390,9 +376,8 @@ int open_journal_for_upload(Uploader *u,
if (cursor) { if (cursor) {
r = sd_journal_seek_cursor(j, cursor); r = sd_journal_seek_cursor(j, cursor);
if (r < 0) { if (r < 0) {
log_error_errno(r, "Failed to seek to cursor %s: %m", return log_error_errno(r, "Failed to seek to cursor %s: %m",
cursor); cursor);
return r;
} }
} }

View File

@ -103,18 +103,14 @@ static int check_cursor_updating(Uploader *u) {
return 0; return 0;
r = mkdir_parents(u->state_file, 0755); r = mkdir_parents(u->state_file, 0755);
if (r < 0) { if (r < 0)
log_error_errno(r, "Cannot create parent directory of state file %s: %m", return log_error_errno(r, "Cannot create parent directory of state file %s: %m",
u->state_file); u->state_file);
return r;
}
r = fopen_temporary(u->state_file, &f, &temp_path); r = fopen_temporary(u->state_file, &f, &temp_path);
if (r < 0) { if (r < 0)
log_error_errno(r, "Cannot save state to %s: %m", return log_error_errno(r, "Cannot save state to %s: %m",
u->state_file); u->state_file);
return r;
}
unlink(temp_path); unlink(temp_path);
return 0; return 0;
@ -164,11 +160,10 @@ static int load_cursor_state(Uploader *u) {
if (r == -ENOENT) if (r == -ENOENT)
log_debug("State file %s is not present.", u->state_file); log_debug("State file %s is not present.", u->state_file);
else if (r < 0) { else if (r < 0)
log_error_errno(r, "Failed to read state file %s: %m", return log_error_errno(r, "Failed to read state file %s: %m",
u->state_file); u->state_file);
return r; else
} else
log_debug("Last cursor was %s", u->last_cursor); log_debug("Last cursor was %s", u->last_cursor);
return 0; return 0;
@ -374,10 +369,8 @@ static int open_file_for_upload(Uploader *u, const char *filename) {
r = sd_event_add_io(u->events, &u->input_event, r = sd_event_add_io(u->events, &u->input_event,
fd, EPOLLIN, dispatch_fd_input, u); fd, EPOLLIN, dispatch_fd_input, u);
if (r < 0) { if (r < 0) {
if (r != -EPERM || arg_follow > 0) { if (r != -EPERM || arg_follow > 0)
log_error_errno(r, "Failed to register input event: %m"); return log_error_errno(r, "Failed to register input event: %m");
return r;
}
/* Normal files should just be consumed without polling. */ /* Normal files should just be consumed without polling. */
r = start_upload(u, fd_input_callback, u); r = start_upload(u, fd_input_callback, u);
@ -458,16 +451,12 @@ static int setup_uploader(Uploader *u, const char *url, const char *state_file)
u->state_file = state_file; u->state_file = state_file;
r = sd_event_default(&u->events); r = sd_event_default(&u->events);
if (r < 0) { if (r < 0)
log_error_errno(r, "sd_event_default failed: %m"); return log_error_errno(r, "sd_event_default failed: %m");
return r;
}
r = setup_signals(u); r = setup_signals(u);
if (r < 0) { if (r < 0)
log_error_errno(r, "Failed to set up signals: %m"); return log_error_errno(r, "Failed to set up signals: %m");
return r;
}
return load_cursor_state(u); return load_cursor_state(u);
} }
@ -701,10 +690,8 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_FILE: case ARG_FILE:
r = glob_extend(&arg_file, optarg); r = glob_extend(&arg_file, optarg);
if (r < 0) { if (r < 0)
log_error_errno(r, "Failed to add paths: %m"); return log_error_errno(r, "Failed to add paths: %m");
return r;
};
break; break;
case ARG_CURSOR: case ARG_CURSOR:

View File

@ -341,17 +341,13 @@ static long write_catalog(const char *database, Hashmap *h, struct strbuf *sb,
return log_oom(); return log_oom();
r = mkdir_p(d, 0775); r = mkdir_p(d, 0775);
if (r < 0) { if (r < 0)
log_error_errno(r, "Recursive mkdir %s: %m", d); return log_error_errno(r, "Recursive mkdir %s: %m", d);
return r;
}
r = fopen_temporary(database, &w, &p); r = fopen_temporary(database, &w, &p);
if (r < 0) { if (r < 0)
log_error_errno(r, "Failed to open database for writing: %s: %m", return log_error_errno(r, "Failed to open database for writing: %s: %m",
database); database);
return r;
}
zero(header); zero(header);
memcpy(header.signature, CATALOG_SIGNATURE, sizeof(header.signature)); memcpy(header.signature, CATALOG_SIGNATURE, sizeof(header.signature));

View File

@ -332,10 +332,8 @@ static int kbdctx_refresh_keymap(kbdctx *kc) {
/* TODO: add a fallback keymap that's compiled-in */ /* TODO: add a fallback keymap that's compiled-in */
r = kbdmap_new_from_names(&km, kc, kc->last_x11_model, kc->last_x11_layout, r = kbdmap_new_from_names(&km, kc, kc->last_x11_model, kc->last_x11_layout,
kc->last_x11_variant, kc->last_x11_options); kc->last_x11_variant, kc->last_x11_options);
if (r < 0) { if (r < 0)
log_debug_errno(r, "idev-keyboard: cannot create keymap from locale1: %m"); return log_debug_errno(r, "idev-keyboard: cannot create keymap from locale1: %m");
return r;
}
kbdmap_unref(kc->kbdmap); kbdmap_unref(kc->kbdmap);
kc->kbdmap = km; kc->kbdmap = km;
@ -1161,9 +1159,8 @@ static int keyboard_update_kbdtbl(idev_keyboard *k) {
return 0; return 0;
error: error:
log_debug_errno(r, "idev-keyboard: %s/%s: cannot adopt new compose table: %m", return log_debug_errno(r, "idev-keyboard: %s/%s: cannot adopt new compose table: %m",
d->session->name, d->name); d->session->name, d->name);
return r;
} }
static const idev_device_vtable keyboard_vtable = { static const idev_device_vtable keyboard_vtable = {

View File

@ -975,11 +975,9 @@ static int context_ud_hotplug(sysview_context *c, struct udev_device *d) {
return 0; return 0;
r = device_new_ud(&device, seat, type, d); r = device_new_ud(&device, seat, type, d);
if (r < 0) { if (r < 0)
log_debug_errno(r, "sysview: cannot create device for udev-device '%s': %m", return log_debug_errno(r, "sysview: cannot create device for udev-device '%s': %m",
syspath); syspath);
return r;
}
context_add_device(c, device); context_add_device(c, device);
} }
@ -1102,10 +1100,8 @@ static int context_ld_seat_new(sysview_context *c, sd_bus_message *signal) {
int r; int r;
r = sd_bus_message_read(signal, "so", &id, &path); r = sd_bus_message_read(signal, "so", &id, &path);
if (r < 0) { if (r < 0)
log_debug_errno(r, "sysview: cannot parse SeatNew from logind: %m"); return log_debug_errno(r, "sysview: cannot parse SeatNew from logind: %m");
return r;
}
context_add_seat(c, id); context_add_seat(c, id);
return 0; return 0;
@ -1117,10 +1113,8 @@ static int context_ld_seat_removed(sysview_context *c, sd_bus_message *signal) {
int r; int r;
r = sd_bus_message_read(signal, "so", &id, &path); r = sd_bus_message_read(signal, "so", &id, &path);
if (r < 0) { if (r < 0)
log_debug_errno(r, "sysview: cannot parse SeatRemoved from logind: %m"); return log_debug_errno(r, "sysview: cannot parse SeatRemoved from logind: %m");
return r;
}
seat = sysview_find_seat(c, id); seat = sysview_find_seat(c, id);
if (!seat) if (!seat)
@ -1138,10 +1132,8 @@ static int context_ld_session_new(sysview_context *c, sd_bus_message *signal) {
int r; int r;
r = sd_bus_message_read(signal, "so", &id, &path); r = sd_bus_message_read(signal, "so", &id, &path);
if (r < 0) { if (r < 0)
log_debug_errno(r, "sysview: cannot parse SessionNew from logind: %m"); return log_debug_errno(r, "sysview: cannot parse SessionNew from logind: %m");
return r;
}
/* /*
* As the dbus message didn't contain enough information, we * As the dbus message didn't contain enough information, we
@ -1182,9 +1174,8 @@ static int context_ld_session_new(sysview_context *c, sd_bus_message *signal) {
return 0; return 0;
error: error:
log_debug_errno(r, "sysview: failed retrieving information for new session '%s': %m", return log_debug_errno(r, "sysview: failed retrieving information for new session '%s': %m",
id); id);
return r;
} }
static int context_ld_session_removed(sysview_context *c, sd_bus_message *signal) { static int context_ld_session_removed(sysview_context *c, sd_bus_message *signal) {
@ -1193,10 +1184,8 @@ static int context_ld_session_removed(sysview_context *c, sd_bus_message *signal
int r; int r;
r = sd_bus_message_read(signal, "so", &id, &path); r = sd_bus_message_read(signal, "so", &id, &path);
if (r < 0) { if (r < 0)
log_debug_errno(r, "sysview: cannot parse SessionRemoved from logind: %m"); return log_debug_errno(r, "sysview: cannot parse SessionRemoved from logind: %m");
return r;
}
session = sysview_find_session(c, id); session = sysview_find_session(c, id);
if (!session) if (!session)
@ -1295,8 +1284,7 @@ static int context_ld_list_seats_fn(sd_bus *bus,
return 0; return 0;
error: error:
log_debug_errno(r, "sysview: erroneous ListSeats response from logind: %m"); return log_debug_errno(r, "sysview: erroneous ListSeats response from logind: %m");
return r;
} }
static int context_ld_list_sessions_fn(sd_bus *bus, static int context_ld_list_sessions_fn(sd_bus *bus,
@ -1360,8 +1348,7 @@ static int context_ld_list_sessions_fn(sd_bus *bus,
return 0; return 0;
error: error:
log_debug_errno(r, "sysview: erroneous ListSessions response from logind: %m"); return log_debug_errno(r, "sysview: erroneous ListSessions response from logind: %m");
return r;
} }
static int context_ld_scan(sysview_context *c) { static int context_ld_scan(sysview_context *c) {
@ -1491,19 +1478,15 @@ static int context_scan_fn(sd_event_source *s, void *userdata) {
if (!c->scanned) { if (!c->scanned) {
r = context_ld_scan(c); r = context_ld_scan(c);
if (r < 0) { if (r < 0)
log_debug_errno(r, "sysview: logind scan failed: %m"); return log_debug_errno(r, "sysview: logind scan failed: %m");
return r;
}
} }
/* skip device scans if no sessions are available */ /* skip device scans if no sessions are available */
if (hashmap_size(c->session_map) > 0) { if (hashmap_size(c->session_map) > 0) {
r = context_ud_scan(c); r = context_ud_scan(c);
if (r < 0) { if (r < 0)
log_debug_errno(r, "sysview: udev scan failed: %m"); return log_debug_errno(r, "sysview: udev scan failed: %m");
return r;
}
HASHMAP_FOREACH(seat, c->seat_map, i) HASHMAP_FOREACH(seat, c->seat_map, i)
seat->scanned = true; seat->scanned = true;

View File

@ -117,31 +117,23 @@ int address_drop(Address *address, Link *link,
r = sd_rtnl_message_new_addr(link->manager->rtnl, &req, RTM_DELADDR, r = sd_rtnl_message_new_addr(link->manager->rtnl, &req, RTM_DELADDR,
link->ifindex, address->family); link->ifindex, address->family);
if (r < 0) { if (r < 0)
log_error_errno(r, "Could not allocate RTM_DELADDR message: %m"); return log_error_errno(r, "Could not allocate RTM_DELADDR message: %m");
return r;
}
r = sd_rtnl_message_addr_set_prefixlen(req, address->prefixlen); r = sd_rtnl_message_addr_set_prefixlen(req, address->prefixlen);
if (r < 0) { if (r < 0)
log_error_errno(r, "Could not set prefixlen: %m"); return log_error_errno(r, "Could not set prefixlen: %m");
return r;
}
if (address->family == AF_INET) if (address->family == AF_INET)
r = sd_rtnl_message_append_in_addr(req, IFA_LOCAL, &address->in_addr.in); r = sd_rtnl_message_append_in_addr(req, IFA_LOCAL, &address->in_addr.in);
else if (address->family == AF_INET6) else if (address->family == AF_INET6)
r = sd_rtnl_message_append_in6_addr(req, IFA_LOCAL, &address->in_addr.in6); r = sd_rtnl_message_append_in6_addr(req, IFA_LOCAL, &address->in_addr.in6);
if (r < 0) { if (r < 0)
log_error_errno(r, "Could not append IFA_LOCAL attribute: %m"); return log_error_errno(r, "Could not append IFA_LOCAL attribute: %m");
return r;
}
r = sd_rtnl_call_async(link->manager->rtnl, req, callback, link, 0, NULL); r = sd_rtnl_call_async(link->manager->rtnl, req, callback, link, 0, NULL);
if (r < 0) { if (r < 0)
log_error_errno(r, "Could not send rtnetlink message: %m"); return log_error_errno(r, "Could not send rtnetlink message: %m");
return r;
}
link_ref(link); link_ref(link);
@ -161,65 +153,47 @@ int address_update(Address *address, Link *link,
r = sd_rtnl_message_new_addr_update(link->manager->rtnl, &req, r = sd_rtnl_message_new_addr_update(link->manager->rtnl, &req,
link->ifindex, address->family); link->ifindex, address->family);
if (r < 0) { if (r < 0)
log_error_errno(r, "Could not allocate RTM_NEWADDR message: %m"); return log_error_errno(r, "Could not allocate RTM_NEWADDR message: %m");
return r;
}
r = sd_rtnl_message_addr_set_prefixlen(req, address->prefixlen); r = sd_rtnl_message_addr_set_prefixlen(req, address->prefixlen);
if (r < 0) { if (r < 0)
log_error_errno(r, "Could not set prefixlen: %m"); return log_error_errno(r, "Could not set prefixlen: %m");
return r;
}
r = sd_rtnl_message_addr_set_flags(req, IFA_F_PERMANENT); r = sd_rtnl_message_addr_set_flags(req, IFA_F_PERMANENT);
if (r < 0) { if (r < 0)
log_error_errno(r, "Could not set flags: %m"); return log_error_errno(r, "Could not set flags: %m");
return r;
}
r = sd_rtnl_message_addr_set_scope(req, address->scope); r = sd_rtnl_message_addr_set_scope(req, address->scope);
if (r < 0) { if (r < 0)
log_error_errno(r, "Could not set scope: %m"); return log_error_errno(r, "Could not set scope: %m");
return r;
}
if (address->family == AF_INET) if (address->family == AF_INET)
r = sd_rtnl_message_append_in_addr(req, IFA_LOCAL, &address->in_addr.in); r = sd_rtnl_message_append_in_addr(req, IFA_LOCAL, &address->in_addr.in);
else if (address->family == AF_INET6) else if (address->family == AF_INET6)
r = sd_rtnl_message_append_in6_addr(req, IFA_LOCAL, &address->in_addr.in6); r = sd_rtnl_message_append_in6_addr(req, IFA_LOCAL, &address->in_addr.in6);
if (r < 0) { if (r < 0)
log_error_errno(r, "Could not append IFA_LOCAL attribute: %m"); return log_error_errno(r, "Could not append IFA_LOCAL attribute: %m");
return r;
}
if (address->family == AF_INET) { if (address->family == AF_INET) {
r = sd_rtnl_message_append_in_addr(req, IFA_BROADCAST, &address->broadcast); r = sd_rtnl_message_append_in_addr(req, IFA_BROADCAST, &address->broadcast);
if (r < 0) { if (r < 0)
log_error_errno(r, "Could not append IFA_BROADCAST attribute: %m"); return log_error_errno(r, "Could not append IFA_BROADCAST attribute: %m");
return r;
}
} }
if (address->label) { if (address->label) {
r = sd_rtnl_message_append_string(req, IFA_LABEL, address->label); r = sd_rtnl_message_append_string(req, IFA_LABEL, address->label);
if (r < 0) { if (r < 0)
log_error_errno(r, "Could not append IFA_LABEL attribute: %m"); return log_error_errno(r, "Could not append IFA_LABEL attribute: %m");
return r;
}
} }
r = sd_rtnl_message_append_cache_info(req, IFA_CACHEINFO, &address->cinfo); r = sd_rtnl_message_append_cache_info(req, IFA_CACHEINFO, &address->cinfo);
if (r < 0) { if (r < 0)
log_error_errno(r, "Could not append IFA_CACHEINFO attribute: %m"); return log_error_errno(r, "Could not append IFA_CACHEINFO attribute: %m");
return r;
}
r = sd_rtnl_call_async(link->manager->rtnl, req, callback, link, 0, NULL); r = sd_rtnl_call_async(link->manager->rtnl, req, callback, link, 0, NULL);
if (r < 0) { if (r < 0)
log_error_errno(r, "Could not send rtnetlink message: %m"); return log_error_errno(r, "Could not send rtnetlink message: %m");
return r;
}
link_ref(link); link_ref(link);
@ -305,77 +279,57 @@ int address_configure(Address *address, Link *link,
r = sd_rtnl_message_new_addr(link->manager->rtnl, &req, RTM_NEWADDR, r = sd_rtnl_message_new_addr(link->manager->rtnl, &req, RTM_NEWADDR,
link->ifindex, address->family); link->ifindex, address->family);
if (r < 0) { if (r < 0)
log_error_errno(r, "Could not allocate RTM_NEWADDR message: %m"); return log_error_errno(r, "Could not allocate RTM_NEWADDR message: %m");
return r;
}
r = sd_rtnl_message_addr_set_prefixlen(req, address->prefixlen); r = sd_rtnl_message_addr_set_prefixlen(req, address->prefixlen);
if (r < 0) { if (r < 0)
log_error_errno(r, "Could not set prefixlen: %m"); return log_error_errno(r, "Could not set prefixlen: %m");
return r;
}
r = sd_rtnl_message_addr_set_flags(req, IFA_F_PERMANENT); r = sd_rtnl_message_addr_set_flags(req, IFA_F_PERMANENT);
if (r < 0) { if (r < 0)
log_error_errno(r, "Could not set flags: %m"); return log_error_errno(r, "Could not set flags: %m");
return r;
}
r = sd_rtnl_message_addr_set_scope(req, address->scope); r = sd_rtnl_message_addr_set_scope(req, address->scope);
if (r < 0) { if (r < 0)
log_error_errno(r, "Could not set scope: %m"); return log_error_errno(r, "Could not set scope: %m");
return r;
}
if (address->family == AF_INET) if (address->family == AF_INET)
r = sd_rtnl_message_append_in_addr(req, IFA_LOCAL, &address->in_addr.in); r = sd_rtnl_message_append_in_addr(req, IFA_LOCAL, &address->in_addr.in);
else if (address->family == AF_INET6) else if (address->family == AF_INET6)
r = sd_rtnl_message_append_in6_addr(req, IFA_LOCAL, &address->in_addr.in6); r = sd_rtnl_message_append_in6_addr(req, IFA_LOCAL, &address->in_addr.in6);
if (r < 0) { if (r < 0)
log_error_errno(r, "Could not append IFA_LOCAL attribute: %m"); return log_error_errno(r, "Could not append IFA_LOCAL attribute: %m");
return r;
}
if (!in_addr_is_null(address->family, &address->in_addr_peer)) { if (!in_addr_is_null(address->family, &address->in_addr_peer)) {
if (address->family == AF_INET) if (address->family == AF_INET)
r = sd_rtnl_message_append_in_addr(req, IFA_ADDRESS, &address->in_addr_peer.in); r = sd_rtnl_message_append_in_addr(req, IFA_ADDRESS, &address->in_addr_peer.in);
else if (address->family == AF_INET6) else if (address->family == AF_INET6)
r = sd_rtnl_message_append_in6_addr(req, IFA_ADDRESS, &address->in_addr_peer.in6); r = sd_rtnl_message_append_in6_addr(req, IFA_ADDRESS, &address->in_addr_peer.in6);
if (r < 0) { if (r < 0)
log_error_errno(r, "Could not append IFA_ADDRESS attribute: %m"); return log_error_errno(r, "Could not append IFA_ADDRESS attribute: %m");
return r;
}
} else { } else {
if (address->family == AF_INET) { if (address->family == AF_INET) {
r = sd_rtnl_message_append_in_addr(req, IFA_BROADCAST, &address->broadcast); r = sd_rtnl_message_append_in_addr(req, IFA_BROADCAST, &address->broadcast);
if (r < 0) { if (r < 0)
log_error_errno(r, "Could not append IFA_BROADCAST attribute: %m"); return log_error_errno(r, "Could not append IFA_BROADCAST attribute: %m");
return r;
}
} }
} }
if (address->label) { if (address->label) {
r = sd_rtnl_message_append_string(req, IFA_LABEL, address->label); r = sd_rtnl_message_append_string(req, IFA_LABEL, address->label);
if (r < 0) { if (r < 0)
log_error_errno(r, "Could not append IFA_LABEL attribute: %m"); return log_error_errno(r, "Could not append IFA_LABEL attribute: %m");
return r;
}
} }
r = sd_rtnl_message_append_cache_info(req, IFA_CACHEINFO, r = sd_rtnl_message_append_cache_info(req, IFA_CACHEINFO,
&address->cinfo); &address->cinfo);
if (r < 0) { if (r < 0)
log_error_errno(r, "Could not append IFA_CACHEINFO attribute: %m"); return log_error_errno(r, "Could not append IFA_CACHEINFO attribute: %m");
return r;
}
r = sd_rtnl_call_async(link->manager->rtnl, req, callback, link, 0, NULL); r = sd_rtnl_call_async(link->manager->rtnl, req, callback, link, 0, NULL);
if (r < 0) { if (r < 0)
log_error_errno(r, "Could not send rtnetlink message: %m"); return log_error_errno(r, "Could not send rtnetlink message: %m");
return r;
}
link_ref(link); link_ref(link);