diff options
47 files changed, 429 insertions, 362 deletions
diff --git a/configure.ac b/configure.ac index 5719075934..878b23b061 100644 --- a/configure.ac +++ b/configure.ac @@ -159,10 +159,13 @@ CC_CHECK_FLAGS_APPEND([with_cflags], [CFLAGS], [\ -Wdeclaration-after-statement \ -Wfloat-equal \ -Wsuggest-attribute=noreturn \ - -Wmissing-prototypes \ + -Werror=missing-prototypes \ + -Werror=implicit-function-declaration \ + -Werror=missing-declarations \ + -Werror=return-type \ + -Werror=shadow \ -Wstrict-prototypes \ -Wredundant-decls \ - -Wmissing-declarations \ -Wmissing-noreturn \ -Wshadow \ -Wendif-labels \ diff --git a/hwdb/60-keyboard.hwdb b/hwdb/60-keyboard.hwdb index 9c7e553a41..007c6a809e 100644 --- a/hwdb/60-keyboard.hwdb +++ b/hwdb/60-keyboard.hwdb @@ -980,6 +980,8 @@ evdev:atkbd:dmi:bvn*:bvr*:bd*:svn[sS][aA][mM][sS][uU][nN][gG]*:pn*550P*:pvr* KEYBOARD_KEY_a9=! # Fn Lock - Function lock off # Series 7 / 9 +evdev:atkbd:dmi:bvn*:bvr*:bd*:svn[sS][aA][mM][sS][uU][nN][gG]*:pn*350V*:pvr* +evdev:atkbd:dmi:bvn*:bvr*:bd*:svn[sS][aA][mM][sS][uU][nN][gG]*:pn*670Z*:pvr* evdev:atkbd:dmi:bvn*:bvr*:bd*:svn[sS][aA][mM][sS][uU][nN][gG]*:pn*700Z*:pvr* evdev:atkbd:dmi:bvn*:bvr*:bd*:svn[sS][aA][mM][sS][uU][nN][gG]*:pn*700G*:pvr* evdev:atkbd:dmi:bvn*:bvr*:bd*:svn[sS][aA][mM][sS][uU][nN][gG]*:pn*900X[34]*:pvr* diff --git a/hwdb/70-mouse.hwdb b/hwdb/70-mouse.hwdb index 2784b941a1..6c77b74e53 100644 --- a/hwdb/70-mouse.hwdb +++ b/hwdb/70-mouse.hwdb @@ -169,6 +169,8 @@ mouse:usb:v046dpc00e:name:Logitech USB-PS/2 Optical Mouse: mouse:usb:v046dpc01b:name:Logitech USB-PS/2 Optical Mouse: # Logitech USB-PS/2 M-BT58 mouse:usb:v046dpc03e:name:Logitech USB-PS/2 Optical Mouse: +# Logitech TrackMan Marble Wheel USB +mouse:usb:v046dpc401:name:Logitech USB-PS/2 Trackball: MOUSE_DPI=400@125 # Lenovo USB mouse model MO28UOL @@ -180,6 +182,7 @@ mouse:usb:v046dpc045:name:Logitech USB-PS/2 Optical Mouse: MOUSE_DPI=600@125 # Logitech Wireless Mouse M325 +mouse:usb:v046dp400a:name:Logitech M325: mouse:usb:v046dpc52b:name:Logitech Unifying Device. Wireless PID:400a: MOUSE_DPI=600@166 MOUSE_WHEEL_CLICK_ANGLE=20 @@ -213,8 +216,10 @@ mouse:usb:v046dp1028:name:Logitech M570: MOUSE_DPI=540@167 # Logitech Wireless Mouse M185 +mouse:usb:v046dp4008:name:Logitech M185: mouse:usb:v046dpc52b:name:Logitech Unifying Device. Wireless PID:4008: # Logitech M705 (marathon mouse) +mouse:usb:v046dp101b:name:Logitech M705: mouse:usb:v046dpc52b:name:Logitech Unifying Device. Wireless PID:101b: MOUSE_DPI=800@166 @@ -225,6 +230,8 @@ mouse:usb:v046dpc24e:name:Logitech G500s Laser Gaming Mouse: MOUSE_DPI=400@500 *800@500 2000@500 # Logitech B605 Wireless Mouse (also M505) +mouse:usb:v046dp101d:name:Logitech B605: +mouse:usb:v046dp101d:name:Logitech M505: mouse:usb:v046dpc52b:name:Logitech Unifying Device. Wireless PID:101d: MOUSE_DPI=900@166 @@ -253,10 +260,12 @@ mouse:usb:v046dpc069:name:Logitech USB Laser Mouse: MOUSE_DPI=1200@125 # Logitech T620 (or, the soap) +mouse:usb:v046dp4027:name:Logitech T620: mouse:usb:v046dpc52b:name:Logitech Unifying Device. Wireless PID:4027: MOUSE_DPI=1200@250 # Logitech ZoneTouch Mouse T400 +mouse:usb:v046dp4026:name:Logitech T400: mouse:usb:v046dpc52b:name:Logitech Unifying Device. Wireless PID:4026: MOUSE_DPI=1300@166 diff --git a/src/activate/activate.c b/src/activate/activate.c index d345e28567..5318829442 100644 --- a/src/activate/activate.c +++ b/src/activate/activate.c @@ -33,6 +33,7 @@ #include "log.h" #include "strv.h" #include "macro.h" +#include "signal-util.h" static char** arg_listen = NULL; static bool arg_accept = false; @@ -192,6 +193,10 @@ static int launch1(const char* child, char** argv, char **env, int fd) { /* In the child */ if (child_pid == 0) { + + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); + r = dup2(fd, STDIN_FILENO); if (r < 0) { log_error_errno(errno, "Failed to dup connection to stdin: %m"); diff --git a/src/core/busname.c b/src/core/busname.c index 3f5abbcb24..2085721546 100644 --- a/src/core/busname.c +++ b/src/core/busname.c @@ -408,8 +408,8 @@ static int busname_make_starter(BusName *n, pid_t *_pid) { if (pid == 0) { int ret; - default_signals(SIGNALS_CRASH_HANDLER, SIGNALS_IGNORE, -1); - ignore_signals(SIGPIPE, -1); + (void) default_signals(SIGNALS_CRASH_HANDLER, SIGNALS_IGNORE, -1); + (void) ignore_signals(SIGPIPE, -1); log_forget_fds(); r = bus_kernel_make_starter(n->starter_fd, n->name, n->activating, n->accept_fd, n->policy, n->policy_world); diff --git a/src/core/execute.c b/src/core/execute.c index 4120493bda..f13c6936e0 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -823,6 +823,7 @@ static int setup_pam( /* Block SIGTERM, so that we know that it won't get lost in * the child */ + if (sigemptyset(&ss) < 0 || sigaddset(&ss, SIGTERM) < 0 || sigprocmask(SIG_BLOCK, &ss, &old_ss) < 0) @@ -857,6 +858,8 @@ static int setup_pam( if (setresuid(uid, uid, uid) < 0) log_error_errno(r, "Error: Failed to setresuid() in sd-pam: %m"); + (void) ignore_signals(SIGPIPE, -1); + /* Wait until our parent died. This will only work if * the above setresuid() succeeds, otherwise the kernel * will not allow unprivileged parents kill their privileged @@ -1324,11 +1327,11 @@ static int exec_child( * others we leave untouched because we set them to * SIG_DFL or a valid handler initially, both of which * will be demoted to SIG_DFL. */ - default_signals(SIGNALS_CRASH_HANDLER, - SIGNALS_IGNORE, -1); + (void) default_signals(SIGNALS_CRASH_HANDLER, + SIGNALS_IGNORE, -1); if (context->ignore_sigpipe) - ignore_signals(SIGPIPE, -1); + (void) ignore_signals(SIGPIPE, -1); r = reset_signal_mask(); if (r < 0) { diff --git a/src/core/killall.c b/src/core/killall.c index 6e85923581..2a9d72c901 100644 --- a/src/core/killall.c +++ b/src/core/killall.c @@ -158,6 +158,7 @@ static int killall(int sig, Set *pids, bool send_sighup) { while ((d = readdir(dir))) { pid_t pid; + int r; if (d->d_type != DT_DIR && d->d_type != DT_UNKNOWN) @@ -177,8 +178,11 @@ static int killall(int sig, Set *pids, bool send_sighup) { } if (kill(pid, sig) >= 0) { - if (pids) - set_put(pids, ULONG_TO_PTR(pid)); + if (pids) { + r = set_put(pids, ULONG_TO_PTR(pid)); + if (r < 0) + log_oom(); + } } else if (errno != ENOENT) log_warning_errno(errno, "Could not kill %d: %m", pid); diff --git a/src/core/main.c b/src/core/main.c index 29ccff7b63..332453a0ea 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1405,9 +1405,8 @@ int main(int argc, char *argv[]) { } /* Reset all signal handlers. */ - assert_se(reset_all_signal_handlers() == 0); - - ignore_signals(SIGNALS_IGNORE, -1); + (void) reset_all_signal_handlers(); + (void) ignore_signals(SIGNALS_IGNORE, -1); if (parse_config_file() < 0) { error_message = "Failed to parse config file"; @@ -1931,8 +1930,8 @@ finish: /* Reenable any blocked signals, especially important * if we switch from initial ramdisk to init=... */ - reset_all_signal_handlers(); - reset_signal_mask(); + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); if (switch_root_init) { args[0] = switch_root_init; diff --git a/src/core/socket.c b/src/core/socket.c index 0239962055..d3178e642b 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -1473,8 +1473,8 @@ static int socket_chown(Socket *s, pid_t *_pid) { gid_t gid = GID_INVALID; int ret; - default_signals(SIGNALS_CRASH_HANDLER, SIGNALS_IGNORE, -1); - ignore_signals(SIGPIPE, -1); + (void) default_signals(SIGNALS_CRASH_HANDLER, SIGNALS_IGNORE, -1); + (void) ignore_signals(SIGPIPE, -1); log_forget_fds(); if (!isempty(s->user)) { diff --git a/src/delta/delta.c b/src/delta/delta.c index c764bb4b46..b60aaef734 100644 --- a/src/delta/delta.c +++ b/src/delta/delta.c @@ -24,6 +24,7 @@ #include <string.h> #include <unistd.h> #include <getopt.h> +#include <sys/prctl.h> #include "hashmap.h" #include "util.h" @@ -34,6 +35,7 @@ #include "strv.h" #include "process-util.h" #include "terminal-util.h" +#include "signal-util.h" static const char prefixes[] = "/etc\0" @@ -189,9 +191,14 @@ static int found_override(const char *top, const char *bottom) { if (pid < 0) return log_error_errno(errno, "Failed to fork off diff: %m"); else if (pid == 0) { + + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); + assert_se(prctl(PR_SET_PDEATHSIG, SIGTERM) == 0); + execlp("diff", "diff", "-us", "--", bottom, top, NULL); log_error_errno(errno, "Failed to execute diff: %m"); - _exit(1); + _exit(EXIT_FAILURE); } wait_for_terminate_and_warn("diff", pid, false); diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c index f0e5c5f239..30254b6680 100644 --- a/src/fsck/fsck.c +++ b/src/fsck/fsck.c @@ -394,8 +394,8 @@ int main(int argc, char *argv[]) { /* Child */ - reset_all_signal_handlers(); - reset_signal_mask(); + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); assert_se(prctl(PR_SET_PDEATHSIG, SIGTERM) == 0); /* Close the reading side of the progress pipe */ diff --git a/src/import/export.c b/src/import/export.c index d4bc88e010..e563bee96e 100644 --- a/src/import/export.c +++ b/src/import/export.c @@ -311,7 +311,7 @@ int main(int argc, char *argv[]) { if (r <= 0) goto finish; - ignore_signals(SIGPIPE, -1); + (void) ignore_signals(SIGPIPE, -1); r = export_main(argc, argv); diff --git a/src/import/import-common.c b/src/import/import-common.c index 9711614000..950c7b4acd 100644 --- a/src/import/import-common.c +++ b/src/import/import-common.c @@ -97,8 +97,8 @@ int import_fork_tar_x(const char *path, pid_t *ret) { /* Child */ - reset_all_signal_handlers(); - reset_signal_mask(); + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); assert_se(prctl(PR_SET_PDEATHSIG, SIGTERM) == 0); pipefd[1] = safe_close(pipefd[1]); @@ -171,8 +171,8 @@ int import_fork_tar_c(const char *path, pid_t *ret) { /* Child */ - reset_all_signal_handlers(); - reset_signal_mask(); + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); assert_se(prctl(PR_SET_PDEATHSIG, SIGTERM) == 0); pipefd[0] = safe_close(pipefd[0]); diff --git a/src/import/import.c b/src/import/import.c index fff5a104b1..3091ed1c45 100644 --- a/src/import/import.c +++ b/src/import/import.c @@ -328,7 +328,7 @@ int main(int argc, char *argv[]) { if (r <= 0) goto finish; - ignore_signals(SIGPIPE, -1); + (void) ignore_signals(SIGPIPE, -1); r = import_main(argc, argv); diff --git a/src/import/importd.c b/src/import/importd.c index 50566a6e5c..e2df44ad26 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -390,8 +390,8 @@ static int transfer_start(Transfer *t) { /* Child */ - reset_all_signal_handlers(); - reset_signal_mask(); + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); assert_se(prctl(PR_SET_PDEATHSIG, SIGTERM) == 0); pipefd[0] = safe_close(pipefd[0]); diff --git a/src/import/pull-common.c b/src/import/pull-common.c index d2588d4fa0..652277e4be 100644 --- a/src/import/pull-common.c +++ b/src/import/pull-common.c @@ -339,8 +339,8 @@ int pull_verify( /* Child */ - reset_all_signal_handlers(); - reset_signal_mask(); + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); assert_se(prctl(PR_SET_PDEATHSIG, SIGTERM) == 0); gpg_pipe[1] = safe_close(gpg_pipe[1]); diff --git a/src/import/pull.c b/src/import/pull.c index eec4583868..03fe3dcaf4 100644 --- a/src/import/pull.c +++ b/src/import/pull.c @@ -440,7 +440,7 @@ int main(int argc, char *argv[]) { if (r <= 0) goto finish; - ignore_signals(SIGPIPE, -1); + (void) ignore_signals(SIGPIPE, -1); r = pull_main(argc, argv); diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c index 911e2a178b..ae332d826f 100644 --- a/src/journal-remote/journal-remote.c +++ b/src/journal-remote/journal-remote.c @@ -96,6 +96,10 @@ static int spawn_child(const char* child, char** argv) { /* In the child */ if (child_pid == 0) { + + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); + r = dup2(fd[1], STDOUT_FILENO); if (r < 0) { log_error_errno(errno, "Failed to dup pipe to stdout: %m"); diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c index 381bf72776..fc49b2e174 100644 --- a/src/journal/coredumpctl.c +++ b/src/journal/coredumpctl.c @@ -757,6 +757,9 @@ static int run_gdb(sd_journal *j) { goto finish; } if (pid == 0) { + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); + execlp("gdb", "gdb", exe, path, NULL); log_error_errno(errno, "Failed to invoke gdb: %m"); diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c index 572a9c6e64..3aaaabf4ed 100644 --- a/src/libsystemd/sd-bus/bus-kernel.c +++ b/src/libsystemd/sd-bus/bus-kernel.c @@ -498,7 +498,6 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) { footer, footer_size, n_bytes, fds, n_fds, - NULL, seclabel, 0, &m); if (r < 0) return r; diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c index 6ee209dd1b..c38b2a5fa5 100644 --- a/src/libsystemd/sd-bus/bus-message.c +++ b/src/libsystemd/sd-bus/bus-message.c @@ -435,7 +435,6 @@ int bus_message_from_header( size_t message_size, int *fds, unsigned n_fds, - const struct ucred *ucred, const char *label, size_t extra, sd_bus_message **ret) { @@ -528,23 +527,6 @@ int bus_message_from_header( m->fds = fds; m->n_fds = n_fds; - if (ucred) { - m->creds.pid = ucred->pid; - m->creds.euid = ucred->uid; - m->creds.egid = ucred->gid; - - /* Due to namespace translations some data might be - * missing from this ucred record. */ - if (m->creds.pid > 0) - m->creds.mask |= SD_BUS_CREDS_PID; - - if (m->creds.euid != UID_INVALID) - m->creds.mask |= SD_BUS_CREDS_EUID; - - if (m->creds.egid != GID_INVALID) - m->creds.mask |= SD_BUS_CREDS_EGID; - } - if (label) { m->creds.label = (char*) m + ALIGN(sizeof(sd_bus_message)) + ALIGN(extra); memcpy(m->creds.label, label, label_sz + 1); @@ -565,7 +547,6 @@ int bus_message_from_malloc( size_t length, int *fds, unsigned n_fds, - const struct ucred *ucred, const char *label, sd_bus_message **ret) { @@ -579,7 +560,7 @@ int bus_message_from_malloc( buffer, length, length, fds, n_fds, - ucred, label, + label, 0, &m); if (r < 0) return r; diff --git a/src/libsystemd/sd-bus/bus-message.h b/src/libsystemd/sd-bus/bus-message.h index d784e603dd..088d5b1109 100644 --- a/src/libsystemd/sd-bus/bus-message.h +++ b/src/libsystemd/sd-bus/bus-message.h @@ -205,7 +205,6 @@ int bus_message_from_header( size_t message_size, int *fds, unsigned n_fds, - const struct ucred *ucred, const char *label, size_t extra, sd_bus_message **ret); @@ -216,7 +215,6 @@ int bus_message_from_malloc( size_t length, int *fds, unsigned n_fds, - const struct ucred *ucred, const char *label, sd_bus_message **ret); diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c index bcd49efb20..9f3756f0c2 100644 --- a/src/libsystemd/sd-bus/bus-socket.c +++ b/src/libsystemd/sd-bus/bus-socket.c @@ -711,7 +711,8 @@ int bus_socket_exec(sd_bus *b) { if (pid == 0) { /* Child */ - reset_all_signal_handlers(); + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); close_all_fds(s+1, 1); @@ -887,7 +888,6 @@ static int bus_socket_make_message(sd_bus *bus, size_t size) { bus->rbuffer, size, bus->fds, bus->n_fds, NULL, - NULL, &t); if (r < 0) { free(b); diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index 0cd5cad223..2805b29839 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -49,6 +49,21 @@ #include "bus-track.h" #include "bus-slot.h" +#define log_debug_bus_message(m) \ + do { \ + sd_bus_message *_mm = (m); \ + log_debug("Got message type=%s sender=%s destination=%s object=%s interface=%s member=%s cookie=%" PRIu64 " reply_cookie=%" PRIu64 " error=%s", \ + bus_message_type_to_string(_mm->header->type), \ + strna(sd_bus_message_get_sender(_mm)), \ + strna(sd_bus_message_get_destination(_mm)), \ + strna(sd_bus_message_get_path(_mm)), \ + strna(sd_bus_message_get_interface(_mm)), \ + strna(sd_bus_message_get_member(_mm)), \ + BUS_MESSAGE_COOKIE(_mm), \ + _mm->reply_cookie, \ + strna(_mm->error.message)); \ + } while (false) + static int bus_poll(sd_bus *bus, bool need_more, uint64_t timeout_usec); static int attach_io_events(sd_bus *b); static void detach_io_events(sd_bus *b); @@ -1993,6 +2008,7 @@ _public_ int sd_bus_call( memmove(bus->rqueue + i, bus->rqueue + i + 1, sizeof(sd_bus_message*) * (bus->rqueue_size - i - 1)); bus->rqueue_size--; + log_debug_bus_message(incoming); if (incoming->header->type == SD_BUS_MESSAGE_METHOD_RETURN) { @@ -2481,16 +2497,7 @@ static int process_message(sd_bus *bus, sd_bus_message *m) { bus->current_message = m; bus->iteration_counter++; - log_debug("Got message type=%s sender=%s destination=%s object=%s interface=%s member=%s cookie=%" PRIu64 " reply_cookie=%" PRIu64 " error=%s", - bus_message_type_to_string(m->header->type), - strna(sd_bus_message_get_sender(m)), - strna(sd_bus_message_get_destination(m)), - strna(sd_bus_message_get_path(m)), - strna(sd_bus_message_get_interface(m)), - strna(sd_bus_message_get_member(m)), - BUS_MESSAGE_COOKIE(m), - m->reply_cookie, - strna(m->error.message)); + log_debug_bus_message(m); r = process_hello(bus, m); if (r != 0) diff --git a/src/libsystemd/sd-bus/test-bus-gvariant.c b/src/libsystemd/sd-bus/test-bus-gvariant.c index 992edacb28..22ea00c2fb 100644 --- a/src/libsystemd/sd-bus/test-bus-gvariant.c +++ b/src/libsystemd/sd-bus/test-bus-gvariant.c @@ -198,7 +198,7 @@ static void test_marshal(void) { } #endif - assert_se(bus_message_from_malloc(bus, blob, sz, NULL, 0, NULL, NULL, &n) >= 0); + assert_se(bus_message_from_malloc(bus, blob, sz, NULL, 0, NULL, &n) >= 0); blob = NULL; assert_se(bus_message_dump(n, NULL, BUS_MESSAGE_DUMP_WITH_HEADER) >= 0); diff --git a/src/libsystemd/sd-bus/test-bus-marshal.c b/src/libsystemd/sd-bus/test-bus-marshal.c index f8ecadf499..a866a56179 100644 --- a/src/libsystemd/sd-bus/test-bus-marshal.c +++ b/src/libsystemd/sd-bus/test-bus-marshal.c @@ -212,7 +212,7 @@ int main(int argc, char *argv[]) { m = sd_bus_message_unref(m); - r = bus_message_from_malloc(bus, buffer, sz, NULL, 0, NULL, NULL, &m); + r = bus_message_from_malloc(bus, buffer, sz, NULL, 0, NULL, &m); assert_se(r >= 0); bus_message_dump(m, stdout, BUS_MESSAGE_DUMP_WITH_HEADER); diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index 2b8d1b87ed..00880c983b 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -2384,7 +2384,6 @@ _public_ int sd_event_wait(sd_event *e, uint64_t timeout) { } r = -errno; - goto finish; } diff --git a/src/login/inhibit.c b/src/login/inhibit.c index 57cfb5d0b5..0e5dce5925 100644 --- a/src/login/inhibit.c +++ b/src/login/inhibit.c @@ -33,6 +33,7 @@ #include "strv.h" #include "formats-util.h" #include "process-util.h" +#include "signal-util.h" static const char* arg_what = "idle:sleep:shutdown"; static const char* arg_who = NULL; @@ -274,6 +275,9 @@ int main(int argc, char *argv[]) { if (pid == 0) { /* Child */ + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); + close_all_fds(NULL, 0); execvp(argv[optind], argv + optind); diff --git a/src/login/logind-user.c b/src/login/logind-user.c index 373c9938e7..c0b473930d 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -738,8 +738,7 @@ int user_kill(User *u, int signo) { return manager_kill_unit(u->manager, u->slice, KILL_ALL, signo, NULL); } -static bool -elect_display_filter(Session *s) { +static bool elect_display_filter(Session *s) { /* Return true if the session is a candidate for the user’s ‘primary * session’ or ‘display’. */ assert(s); @@ -747,8 +746,7 @@ elect_display_filter(Session *s) { return (s->class == SESSION_USER && !s->stopping); } -static int -elect_display_compare(Session *s1, Session *s2) { +static int elect_display_compare(Session *s1, Session *s2) { /* Indexed by SessionType. Lower numbers mean more preferred. */ const int type_ranks[_SESSION_TYPE_MAX] = { [SESSION_UNSPECIFIED] = 0, diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 127bc1249a..7841f69dab 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -749,7 +749,6 @@ static int set_hostname_handler(sd_bus_message *m, void *userdata, sd_bus_error } int link_set_hostname(Link *link, const char *hostname) { - _cleanup_bus_message_unref_ sd_bus_message *m = NULL; int r = 0; assert(link); @@ -764,22 +763,19 @@ int link_set_hostname(Link *link, const char *hostname) { return 0; } - r = sd_bus_message_new_method_call( + r = sd_bus_call_method_async( link->manager->bus, - &m, + NULL, "org.freedesktop.hostname1", "/org/freedesktop/hostname1", "org.freedesktop.hostname1", - "SetHostname"); - if (r < 0) - return r; - - r = sd_bus_message_append(m, "sb", hostname, false); - if (r < 0) - return r; + "SetHostname", + set_hostname_handler, + link, + "sb", + hostname, + false); - r = sd_bus_call_async(link->manager->bus, NULL, m, set_hostname_handler, - link, 0); if (r < 0) return log_link_error_errno(link, r, "Could not set transient hostname: %m"); diff --git a/src/network/networkd-netdev-bond.c b/src/network/networkd-netdev-bond.c index 70df08a5e1..9919955f51 100644 --- a/src/network/networkd-netdev-bond.c +++ b/src/network/networkd-netdev-bond.c @@ -191,215 +191,132 @@ static int netdev_bond_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_m if (b->mode != _NETDEV_BOND_MODE_INVALID) { r = sd_rtnl_message_append_u8(m, IFLA_BOND_MODE, bond_mode_to_kernel(b->mode)); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_BOND_MODE attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_MODE attribute: %m"); } if (b->xmit_hash_policy != _NETDEV_BOND_XMIT_HASH_POLICY_INVALID) { r = sd_rtnl_message_append_u8(m, IFLA_BOND_XMIT_HASH_POLICY, bond_xmit_hash_policy_to_kernel(b->xmit_hash_policy)); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_BOND_XMIT_HASH_POLICY attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_XMIT_HASH_POLICY attribute: %m"); } if (b->lacp_rate != _NETDEV_BOND_LACP_RATE_INVALID && b->mode == NETDEV_BOND_MODE_802_3AD) { r = sd_rtnl_message_append_u8(m, IFLA_BOND_AD_LACP_RATE, b->lacp_rate ); if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_BOND_AD_LACP_RATE attribute: %s", - strerror(-r)); - return r; + return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_AD_LACP_RATE attribute: %m"); } } if (b->miimon != 0) { r = sd_rtnl_message_append_u32(m, IFLA_BOND_MIIMON, b->miimon / USEC_PER_MSEC); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_BOND_BOND_MIIMON attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_BOND_MIIMON attribute: %m"); } if (b->downdelay != 0) { r = sd_rtnl_message_append_u32(m, IFLA_BOND_DOWNDELAY, b->downdelay / USEC_PER_MSEC); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_BOND_DOWNDELAY attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_DOWNDELAY attribute: %m"); } if (b->updelay != 0) { r = sd_rtnl_message_append_u32(m, IFLA_BOND_UPDELAY, b->updelay / USEC_PER_MSEC); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_BOND_UPDELAY attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_UPDELAY attribute: %m"); } if (b->arp_interval != 0) { r = sd_rtnl_message_append_u32(m, IFLA_BOND_ARP_INTERVAL, b->arp_interval / USEC_PER_MSEC); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_BOND_ARP_INTERVAL attribute: %s", - strerror(-r)); - return r; - } - } - - if ((b->lp_interval >= LEARNING_PACKETS_INTERVAL_MIN_SEC) && - (b->lp_interval <= LEARNING_PACKETS_INTERVAL_MAX_SEC)) { - r = sd_rtnl_message_append_u32(m, IFLA_BOND_LP_INTERVAL, b->lp_interval / USEC_PER_SEC); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_BOND_LP_INTERVAL attribute: %s", - strerror(-r)); - return r; + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ARP_INTERVAL attribute: %m"); + + if ((b->lp_interval >= LEARNING_PACKETS_INTERVAL_MIN_SEC) && + (b->lp_interval <= LEARNING_PACKETS_INTERVAL_MAX_SEC)) { + r = sd_rtnl_message_append_u32(m, IFLA_BOND_LP_INTERVAL, b->lp_interval / USEC_PER_SEC); + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_LP_INTERVAL attribute: %m"); } } if (b->ad_select != _NETDEV_BOND_AD_SELECT_INVALID && b->mode == BOND_MODE_8023AD) { r = sd_rtnl_message_append_u8(m, IFLA_BOND_AD_SELECT, b->ad_select); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_BOND_AD_SELECT attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_AD_SELECT attribute: %m"); } if (b->fail_over_mac != _NETDEV_BOND_FAIL_OVER_MAC_INVALID && b->mode == NETDEV_BOND_MODE_ACTIVE_BACKUP) { r = sd_rtnl_message_append_u8(m, IFLA_BOND_FAIL_OVER_MAC, b->fail_over_mac); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_BOND_FAIL_OVER_MAC attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_FAIL_OVER_MAC attribute: %m"); } if (b->arp_validate != _NETDEV_BOND_ARP_VALIDATE_INVALID) { r = sd_rtnl_message_append_u32(m, IFLA_BOND_ARP_VALIDATE, b->arp_validate); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_BOND_ARP_VALIDATE attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ARP_VALIDATE attribute: %m"); } if (b->arp_all_targets != _NETDEV_BOND_ARP_ALL_TARGETS_INVALID) { r = sd_rtnl_message_append_u32(m, IFLA_BOND_ARP_ALL_TARGETS, b->arp_all_targets); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_BOND_ARP_VALIDATE attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ARP_VALIDATE attribute: %m"); } if (b->primary_reselect != _NETDEV_BOND_PRIMARY_RESELECT_INVALID) { r = sd_rtnl_message_append_u32(m, IFLA_BOND_ARP_ALL_TARGETS, b->primary_reselect); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_BOND_ARP_ALL_TARGETS attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ARP_ALL_TARGETS attribute: %m"); } if (b->resend_igmp <= RESEND_IGMP_MAX) { r = sd_rtnl_message_append_u32(m, IFLA_BOND_RESEND_IGMP, b->resend_igmp); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_BOND_RESEND_IGMP attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_RESEND_IGMP attribute: %m"); } if (b->packets_per_slave <= PACKETS_PER_SLAVE_MAX) { r = sd_rtnl_message_append_u32(m, IFLA_BOND_PACKETS_PER_SLAVE, b->packets_per_slave); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_BOND_PACKETS_PER_SLAVE attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_PACKETS_PER_SLAVE attribute: %m"); } if (b->num_grat_arp <= GRATUITOUS_ARP_MAX) { r = sd_rtnl_message_append_u8(m, IFLA_BOND_NUM_PEER_NOTIF, b->num_grat_arp); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_BOND_NUM_PEER_NOTIF attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_NUM_PEER_NOTIF attribute: %m"); } if (b->min_links != 0) { r = sd_rtnl_message_append_u32(m, IFLA_BOND_MIN_LINKS, b->min_links); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_BOND_MIN_LINKS attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_MIN_LINKS attribute: %m"); } r = sd_rtnl_message_append_u8(m, IFLA_BOND_ALL_SLAVES_ACTIVE, b->all_slaves_active); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_BOND_ALL_SLAVES_ACTIVE attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ALL_SLAVES_ACTIVE attribute: %m"); if (b->arp_interval > 0) { if (b->n_arp_ip_targets > 0) { r = sd_rtnl_message_open_container(m, IFLA_BOND_ARP_IP_TARGET); - if (r < 0) { - log_netdev_error(netdev, - "Could not open contaniner IFLA_BOND_ARP_IP_TARGET : %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not open contaniner IFLA_BOND_ARP_IP_TARGET : %m"); LIST_FOREACH(arp_ip_target, target, b->arp_ip_targets) { r = sd_rtnl_message_append_u32(m, i++, target->ip.in.s_addr); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_BOND_ARP_ALL_TARGETS attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ARP_ALL_TARGETS attribute: %m"); } r = sd_rtnl_message_close_container(m); - if (r < 0) { - log_netdev_error(netdev, - "Could not close contaniner IFLA_BOND_ARP_IP_TARGET : %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not close contaniner IFLA_BOND_ARP_IP_TARGET : %m"); } } diff --git a/src/network/networkd-netdev-veth.c b/src/network/networkd-netdev-veth.c index 9e9e1225e7..7bb02d1ae1 100644 --- a/src/network/networkd-netdev-veth.c +++ b/src/network/networkd-netdev-veth.c @@ -35,12 +35,8 @@ static int netdev_veth_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_m assert(m); r = sd_rtnl_message_open_container(m, VETH_INFO_PEER); - if (r < 0) { - log_netdev_error(netdev, - "Could not append VETH_INFO_PEER attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append VETH_INFO_PEER attribute: %m"); if (v->ifname_peer) { r = sd_rtnl_message_append_string(m, IFLA_IFNAME, v->ifname_peer); @@ -50,21 +46,13 @@ static int netdev_veth_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_m if (v->mac_peer) { r = sd_rtnl_message_append_ether_addr(m, IFLA_ADDRESS, v->mac_peer); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_ADDRESS attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_ADDRESS attribute: %m"); } r = sd_rtnl_message_close_container(m); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_INFO_DATA attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_INFO_DATA attribute: %m"); return r; } diff --git a/src/network/networkd-netdev-vxlan.c b/src/network/networkd-netdev-vxlan.c index e2c2b108b9..01a1e5089c 100644 --- a/src/network/networkd-netdev-vxlan.c +++ b/src/network/networkd-netdev-vxlan.c @@ -39,123 +39,67 @@ static int netdev_vxlan_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_ if (v->id <= VXLAN_VID_MAX) { r = sd_rtnl_message_append_u32(m, IFLA_VXLAN_ID, v->id); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_VXLAN_ID attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_ID attribute: %m"); } r = sd_rtnl_message_append_in_addr(m, IFLA_VXLAN_GROUP, &v->group.in); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_VXLAN_GROUP attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_GROUP attribute: %m"); r = sd_rtnl_message_append_u32(m, IFLA_VXLAN_LINK, link->ifindex); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_VXLAN_LINK attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_LINK attribute: %m"); if(v->ttl) { r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_TTL, v->ttl); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_VXLAN_TTL attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_TTL attribute: %m"); } if(v->tos) { r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_TOS, v->tos); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_VXLAN_TOS attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_TOS attribute: %m"); } r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_LEARNING, v->learning); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_VXLAN_LEARNING attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_LEARNING attribute: %m"); r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_RSC, v->route_short_circuit); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_VXLAN_RSC attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_RSC attribute: %m"); r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_PROXY, v->arp_proxy); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_VXLAN_PROXY attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_PROXY attribute: %m"); r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_L2MISS, v->l2miss); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_VXLAN_L2MISS attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_L2MISS attribute: %m"); r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_L3MISS, v->l3miss); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_VXLAN_L3MISS attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_L3MISS attribute: %m"); if(v->fdb_ageing) { r = sd_rtnl_message_append_u32(m, IFLA_VXLAN_AGEING, v->fdb_ageing / USEC_PER_SEC); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_VXLAN_AGEING attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_AGEING attribute: %m"); } r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_UDP_CSUM, v->udpcsum); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_VXLAN_UDP_CSUM attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_UDP_CSUM attribute: %m"); r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_UDP_ZERO_CSUM6_TX, v->udp6zerocsumtx); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_VXLAN_UDP_ZERO_CSUM6_TX attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_UDP_ZERO_CSUM6_TX attribute: %m"); r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_UDP_ZERO_CSUM6_RX, v->udp6zerocsumrx); - if (r < 0) { - log_netdev_error(netdev, - "Could not append IFLA_VXLAN_UDP_ZERO_CSUM6_RX attribute: %s", - strerror(-r)); - return r; - } + if (r < 0) + return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_UDP_ZERO_CSUM6_RX attribute: %m"); return r; } diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 4211a3d779..251af4a67c 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -3656,7 +3656,8 @@ static int spawn_getent(const char *database, const char *key, pid_t *rpid) { if (nullfd > 2) safe_close(nullfd); - reset_all_signal_handlers(); + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); close_all_fds(NULL, 0); execle("/usr/bin/getent", "getent", database, key, NULL, &empty_env); @@ -4739,8 +4740,8 @@ int main(int argc, char *argv[]) { rtnl_socket_pair[0] = safe_close(rtnl_socket_pair[0]); pid_socket_pair[0] = safe_close(pid_socket_pair[0]); - reset_all_signal_handlers(); - reset_signal_mask(); + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); r = outer_child(&barrier, arg_directory, diff --git a/src/quotacheck/quotacheck.c b/src/quotacheck/quotacheck.c index a729f592cf..cf6a239402 100644 --- a/src/quotacheck/quotacheck.c +++ b/src/quotacheck/quotacheck.c @@ -23,9 +23,11 @@ #include <stdbool.h> #include <errno.h> #include <unistd.h> +#include <sys/prctl.h> #include "util.h" #include "process-util.h" +#include "signal-util.h" static bool arg_skip = false; static bool arg_force = false; @@ -105,7 +107,13 @@ int main(int argc, char *argv[]) { log_error_errno(errno, "fork(): %m"); return EXIT_FAILURE; } else if (pid == 0) { + /* Child */ + + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); + assert_se(prctl(PR_SET_PDEATHSIG, SIGTERM) == 0); + execv(cmdline[0], (char**) cmdline); _exit(1); /* Operational error */ } diff --git a/src/remount-fs/remount-fs.c b/src/remount-fs/remount-fs.c index e701fc9fae..f904e48e75 100644 --- a/src/remount-fs/remount-fs.c +++ b/src/remount-fs/remount-fs.c @@ -95,6 +95,9 @@ int main(int argc, char *argv[]) { const char *arguments[5]; /* Child */ + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); + arguments[0] = MOUNT_PATH; arguments[1] = me->mnt_dir; arguments[2] = "-o"; diff --git a/src/shared/machine-pool.c b/src/shared/machine-pool.c index d27931cb4a..8c64908b1a 100644 --- a/src/shared/machine-pool.c +++ b/src/shared/machine-pool.c @@ -109,8 +109,8 @@ static int setup_machine_raw(uint64_t size, sd_bus_error *error) { /* Child */ - reset_all_signal_handlers(); - reset_signal_mask(); + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); assert_se(prctl(PR_SET_PDEATHSIG, SIGTERM) == 0); fd = safe_close(fd); diff --git a/src/shared/pager.c b/src/shared/pager.c index 58b62fdccf..13f03e798b 100644 --- a/src/shared/pager.c +++ b/src/shared/pager.c @@ -30,6 +30,7 @@ #include "process-util.h" #include "macro.h" #include "terminal-util.h" +#include "signal-util.h" static pid_t pager_pid = 0; @@ -85,6 +86,9 @@ int pager_open(bool jump_to_end) { if (pager_pid == 0) { const char* less_opts; + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); + dup2(fd[0], STDIN_FILENO); safe_close_pair(fd); @@ -178,6 +182,10 @@ int show_man_page(const char *desc, bool null_stdio) { if (pid == 0) { /* Child */ + + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); + if (null_stdio) { r = make_null_stdio(); if (r < 0) { diff --git a/src/shared/path-util.c b/src/shared/path-util.c index be50a1865d..537705446a 100644 --- a/src/shared/path-util.c +++ b/src/shared/path-util.c @@ -640,7 +640,7 @@ fallback_fstat: /* flags can be AT_SYMLINK_FOLLOW or 0 */ int path_is_mount_point(const char *t, int flags) { _cleanup_close_ int fd = -1; - _cleanup_free_ char *parent = NULL; + _cleanup_free_ char *canonical = NULL, *parent = NULL; int r; assert(t); @@ -648,7 +648,17 @@ int path_is_mount_point(const char *t, int flags) { if (path_equal(t, "/")) return 1; - r = path_get_parent(t, &parent); + /* we need to resolve symlinks manually, we can't just rely on + * fd_is_mount_point() to do that for us; if we have a structure like + * /bin -> /usr/bin/ and /usr is a mount point, then the parent that we + * look at needs to be /usr, not /. */ + if (flags & AT_SYMLINK_FOLLOW) { + canonical = canonicalize_file_name(t); + if (!canonical) + return -errno; + } + + r = path_get_parent(canonical ?: t, &parent); if (r < 0) return r; @@ -656,7 +666,7 @@ int path_is_mount_point(const char *t, int flags) { if (fd < 0) return -errno; - return fd_is_mount_point(fd, basename(t), flags); + return fd_is_mount_point(fd, basename(canonical ?: t), flags); } int path_is_read_only_fs(const char *path) { diff --git a/src/shared/pty.c b/src/shared/pty.c index 119d66e9a2..a87b3ce6f0 100644 --- a/src/shared/pty.c +++ b/src/shared/pty.c @@ -239,7 +239,7 @@ int pty_setup_child(Pty *pty) { assert_return(pty_is_child(pty), -EINVAL); assert_return(pty_is_open(pty), -EALREADY); - r = sigprocmask_many(SIG_SETMASK, -1); + r = reset_signal_mask(); if (r < 0) return r; diff --git a/src/shared/signal-util.c b/src/shared/signal-util.c index 9a2973b6fd..84cf42b285 100644 --- a/src/shared/signal-util.c +++ b/src/shared/signal-util.c @@ -23,13 +23,13 @@ #include "signal-util.h" int reset_all_signal_handlers(void) { + static const struct sigaction sa = { + .sa_handler = SIG_DFL, + .sa_flags = SA_RESTART, + }; int sig, r = 0; for (sig = 1; sig < _NSIG; sig++) { - static const struct sigaction sa = { - .sa_handler = SIG_DFL, - .sa_flags = SA_RESTART, - }; /* These two cannot be caught... */ if (sig == SIGKILL || sig == SIGSTOP) @@ -38,7 +38,7 @@ int reset_all_signal_handlers(void) { /* On Linux the first two RT signals are reserved by * glibc, and sigaction() will return EINVAL for them. */ if ((sigaction(sig, &sa, NULL) < 0)) - if (errno != EINVAL && r == 0) + if (errno != EINVAL && r >= 0) r = -errno; } @@ -57,83 +57,123 @@ int reset_signal_mask(void) { return 0; } +static int sigaction_many_ap(const struct sigaction *sa, int sig, va_list ap) { + int r = 0; + + /* negative signal ends the list. 0 signal is skipped. */ + + if (sig < 0) + return 0; + + if (sig > 0) { + if (sigaction(sig, sa, NULL) < 0) + r = -errno; + } + + while ((sig = va_arg(ap, int)) >= 0) { + + if (sig == 0) + continue; + + if (sigaction(sig, sa, NULL) < 0) { + if (r >= 0) + r = -errno; + } + } + + return r; +} + int sigaction_many(const struct sigaction *sa, ...) { va_list ap; - int r = 0, sig; + int r; va_start(ap, sa); - while ((sig = va_arg(ap, int)) > 0) - if (sigaction(sig, sa, NULL) < 0) - r = -errno; + r = sigaction_many_ap(sa, 0, ap); va_end(ap); return r; } int ignore_signals(int sig, ...) { + static const struct sigaction sa = { .sa_handler = SIG_IGN, .sa_flags = SA_RESTART, }; - va_list ap; - int r = 0; - if (sigaction(sig, &sa, NULL) < 0) - r = -errno; + va_list ap; + int r; va_start(ap, sig); - while ((sig = va_arg(ap, int)) > 0) - if (sigaction(sig, &sa, NULL) < 0) - r = -errno; + r = sigaction_many_ap(&sa, sig, ap); va_end(ap); return r; } int default_signals(int sig, ...) { + static const struct sigaction sa = { .sa_handler = SIG_DFL, .sa_flags = SA_RESTART, }; - va_list ap; - int r = 0; - if (sigaction(sig, &sa, NULL) < 0) - r = -errno; + va_list ap; + int r; va_start(ap, sig); - while ((sig = va_arg(ap, int)) > 0) - if (sigaction(sig, &sa, NULL) < 0) - r = -errno; + r = sigaction_many_ap(&sa, sig, ap); va_end(ap); return r; } -void sigset_add_many(sigset_t *ss, ...) { - va_list ap; - int sig; +static int sigset_add_many_ap(sigset_t *ss, va_list ap) { + int sig, r = 0; assert(ss); + while ((sig = va_arg(ap, int)) >= 0) { + + if (sig == 0) + continue; + + if (sigaddset(ss, sig) < 0) { + if (r >= 0) + r = -errno; + } + } + + return r; +} + +int sigset_add_many(sigset_t *ss, ...) { + va_list ap; + int r; + va_start(ap, ss); - while ((sig = va_arg(ap, int)) > 0) - assert_se(sigaddset(ss, sig) == 0); + r = sigset_add_many_ap(ss, ap); va_end(ap); + + return r; } int sigprocmask_many(int how, ...) { va_list ap; sigset_t ss; - int sig; + int r; - assert_se(sigemptyset(&ss) == 0); + if (sigemptyset(&ss) < 0) + return -errno; va_start(ap, how); - while ((sig = va_arg(ap, int)) > 0) - assert_se(sigaddset(&ss, sig) == 0); + r = sigset_add_many_ap(&ss, ap); va_end(ap); + if (r < 0) + return r; + if (sigprocmask(how, &ss, NULL) < 0) return -errno; diff --git a/src/shared/signal-util.h b/src/shared/signal-util.h index ddf64cda76..9dc8a28726 100644 --- a/src/shared/signal-util.h +++ b/src/shared/signal-util.h @@ -32,7 +32,7 @@ int ignore_signals(int sig, ...); int default_signals(int sig, ...); int sigaction_many(const struct sigaction *sa, ...); -void sigset_add_many(sigset_t *ss, ...); +int sigset_add_many(sigset_t *ss, ...); int sigprocmask_many(int how, ...); const char *signal_to_string(int i) _const_; diff --git a/src/shared/util.c b/src/shared/util.c index dc5e938796..a20e7bb2ef 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -2301,8 +2301,8 @@ static int do_execute(char **directories, usec_t timeout, char *argv[]) { /* We fork this all off from a child process so that we can * somewhat cleanly make use of SIGALRM to set a time limit */ - reset_all_signal_handlers(); - reset_signal_mask(); + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); assert_se(prctl(PR_SET_PDEATHSIG, SIGTERM) == 0); @@ -3344,8 +3344,8 @@ int fork_agent(pid_t *pid, const int except[], unsigned n_except, const char *pa /* Make sure we actually can kill the agent, if we need to, in * case somebody invoked us from a shell script that trapped * SIGTERM or so... */ - reset_all_signal_handlers(); - reset_signal_mask(); + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); /* Check whether our parent died before we were able * to set the death signal and unblock the signals */ diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index b3d90d2c33..5075e4e176 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -5189,6 +5189,9 @@ static int enable_sysv_units(const char *verb, char **args) { else if (pid == 0) { /* Child */ + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); + execv(argv[0], (char**) argv); log_error("Failed to execute %s: %m", argv[0]); _exit(EXIT_FAILURE); @@ -5854,6 +5857,9 @@ static int run_editor(char **paths) { unsigned i = 1; size_t argc; + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); + argc = strv_length(paths)/2 + 1; args = newa(const char*, argc + 1); diff --git a/src/test/test-copy.c b/src/test/test-copy.c index 403d85bff0..e55ffaa16a 100644 --- a/src/test/test-copy.c +++ b/src/test/test-copy.c @@ -133,10 +133,45 @@ static void test_copy_tree(void) { (void) rm_rf(original_dir, REMOVE_ROOT|REMOVE_PHYSICAL); } +static void test_copy_bytes(void) { + _cleanup_close_pair_ int pipefd[2] = {-1, -1}; + _cleanup_close_ int infd = -1; + int r, r2; + char buf[1024], buf2[1024]; + + infd = open("/etc/os-release", O_RDONLY|O_CLOEXEC); + assert_se(infd >= 0); + + assert_se(pipe2(pipefd, O_CLOEXEC) == 0); + + r = copy_bytes(infd, pipefd[1], (off_t) -1, false); + assert_se(r == 0); + + r = read(pipefd[0], buf, sizeof(buf)); + assert_se(r >= 0); + + assert_se(lseek(infd, 0, SEEK_SET) == 0); + r2 = read(infd, buf2, sizeof(buf2)); + assert_se(r == r2); + + assert_se(strneq(buf, buf2, r)); + + /* test copy_bytes with invalid descriptors */ + r = copy_bytes(pipefd[0], pipefd[0], 1, false); + assert_se(r == -EBADF); + + r = copy_bytes(pipefd[1], pipefd[1], 1, false); + assert_se(r == -EBADF); + + r = copy_bytes(pipefd[1], infd, 1, false); + assert_se(r == -EBADF); +} + int main(int argc, char *argv[]) { test_copy_file(); test_copy_file_fd(); test_copy_tree(); + test_copy_bytes(); return 0; } diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c index 0045ae6824..fce4e81a09 100644 --- a/src/test/test-path-util.c +++ b/src/test/test-path-util.c @@ -312,9 +312,11 @@ static void test_prefix_root(void) { } static void test_path_is_mount_point(void) { - int fd, rt, rf, rlt, rlf; + int fd; char tmp_dir[] = "/tmp/test-path-is-mount-point-XXXXXX"; _cleanup_free_ char *file1 = NULL, *file2 = NULL, *link1 = NULL, *link2 = NULL; + _cleanup_free_ char *dir1 = NULL, *dir1file = NULL, *dirlink1 = NULL, *dirlink1file = NULL; + _cleanup_free_ char *dir2 = NULL, *dir2file = NULL; assert_se(path_is_mount_point("/", AT_SYMLINK_FOLLOW) > 0); assert_se(path_is_mount_point("/", 0) > 0); @@ -328,6 +330,19 @@ static void test_path_is_mount_point(void) { assert_se(path_is_mount_point("/sys", AT_SYMLINK_FOLLOW) > 0); assert_se(path_is_mount_point("/sys", 0) > 0); + /* we'll create a hierarchy of different kinds of dir/file/link + * layouts: + * + * <tmp>/file1, <tmp>/file2 + * <tmp>/link1 -> file1, <tmp>/link2 -> file2 + * <tmp>/dir1/ + * <tmp>/dir1/file + * <tmp>/dirlink1 -> dir1 + * <tmp>/dirlink1file -> dirlink1/file + * <tmp>/dir2/ + * <tmp>/dir2/file + */ + /* file mountpoints */ assert_se(mkdtemp(tmp_dir) != NULL); file1 = path_join(NULL, tmp_dir, "file1"); @@ -352,8 +367,43 @@ static void test_path_is_mount_point(void) { assert_se(path_is_mount_point(link1, AT_SYMLINK_FOLLOW) == 0); assert_se(path_is_mount_point(link1, 0) == 0); - /* this test will only work as root */ + /* directory mountpoints */ + dir1 = path_join(NULL, tmp_dir, "dir1"); + assert_se(dir1); + assert_se(mkdir(dir1, 0755) == 0); + dirlink1 = path_join(NULL, tmp_dir, "dirlink1"); + assert_se(dirlink1); + assert_se(symlink("dir1", dirlink1) == 0); + dirlink1file = path_join(NULL, tmp_dir, "dirlink1file"); + assert_se(dirlink1file); + assert_se(symlink("dirlink1/file", dirlink1file) == 0); + dir2 = path_join(NULL, tmp_dir, "dir2"); + assert_se(dir2); + assert_se(mkdir(dir2, 0755) == 0); + + assert_se(path_is_mount_point(dir1, AT_SYMLINK_FOLLOW) == 0); + assert_se(path_is_mount_point(dir1, 0) == 0); + assert_se(path_is_mount_point(dirlink1, AT_SYMLINK_FOLLOW) == 0); + assert_se(path_is_mount_point(dirlink1, 0) == 0); + + /* file in subdirectory mountpoints */ + dir1file = path_join(NULL, dir1, "file"); + assert_se(dir1file); + fd = open(dir1file, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0664); + assert_se(fd > 0); + close(fd); + + assert_se(path_is_mount_point(dir1file, AT_SYMLINK_FOLLOW) == 0); + assert_se(path_is_mount_point(dir1file, 0) == 0); + assert_se(path_is_mount_point(dirlink1file, AT_SYMLINK_FOLLOW) == 0); + assert_se(path_is_mount_point(dirlink1file, 0) == 0); + + /* these tests will only work as root */ if (mount(file1, file2, NULL, MS_BIND, NULL) >= 0) { + int rt, rf, rlt, rlf, rl1t, rl1f; + + /* files */ + /* capture results in vars, to avoid dangling mounts on failure */ rf = path_is_mount_point(file2, 0); rt = path_is_mount_point(file2, AT_SYMLINK_FOLLOW); rlf = path_is_mount_point(link2, 0); @@ -365,6 +415,33 @@ static void test_path_is_mount_point(void) { assert_se(rt == 1); assert_se(rlf == 0); assert_se(rlt == 1); + + /* dirs */ + dir2file = path_join(NULL, dir2, "file"); + assert_se(dir2file); + fd = open(dir2file, O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0664); + assert_se(fd > 0); + close(fd); + + assert_se(mount(dir2, dir1, NULL, MS_BIND, NULL) >= 0); + + rf = path_is_mount_point(dir1, 0); + rt = path_is_mount_point(dir1, AT_SYMLINK_FOLLOW); + rlf = path_is_mount_point(dirlink1, 0); + rlt = path_is_mount_point(dirlink1, AT_SYMLINK_FOLLOW); + /* its parent is a mount point, but not /file itself */ + rl1f = path_is_mount_point(dirlink1file, 0); + rl1t = path_is_mount_point(dirlink1file, AT_SYMLINK_FOLLOW); + + assert_se(umount(dir1) == 0); + + assert_se(rf == 1); + assert_se(rt == 1); + assert_se(rlf == 0); + assert_se(rlt == 1); + assert_se(rl1f == 0); + assert_se(rl1t == 0); + } else printf("Skipping bind mount file test: %m\n"); diff --git a/src/vconsole/vconsole-setup.c b/src/vconsole/vconsole-setup.c index 6c782b3130..f7728dcfff 100644 --- a/src/vconsole/vconsole-setup.c +++ b/src/vconsole/vconsole-setup.c @@ -37,6 +37,7 @@ #include "fileio.h" #include "process-util.h" #include "terminal-util.h" +#include "signal-util.h" static bool is_vconsole(int fd) { unsigned char data[1]; @@ -122,6 +123,10 @@ static int keyboard_load_and_wait(const char *vc, const char *map, const char *m if (pid < 0) return log_error_errno(errno, "Failed to fork: %m"); else if (pid == 0) { + + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); + execv(args[0], (char **) args); _exit(EXIT_FAILURE); } @@ -160,6 +165,10 @@ static int font_load_and_wait(const char *vc, const char *font, const char *map, if (pid < 0) return log_error_errno(errno, "Failed to fork: %m"); else if (pid == 0) { + + (void) reset_all_signal_handlers(); + (void) reset_signal_mask(); + execv(args[0], (char **) args); _exit(EXIT_FAILURE); } |