From: Zbigniew Jędrzejewski-Szmek Date: Tue, 8 Jan 2019 14:07:33 +0000 (+0100) Subject: Merge pull request #11355 from yuwata/rfe-11343 X-Git-Tag: v241-rc1~103 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f0560c745349032c9a9c0934ab833c68754e2a69;hp=ff650ffe348b3a22f2fe4ef6b579526d9e55a6ee;p=thirdparty%2Fsystemd.git Merge pull request #11355 from yuwata/rfe-11343 conf-parse: accept whitespaces before comments --- diff --git a/NEWS b/NEWS index e04a797c285..9b43907fcba 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,8 @@ CHANGES WITH 240: by systemd-sysusers again. Distributors or system administrators may need to create these users and groups if they not exist (or need to re-enable DynamicUser= for those units) while upgrading systemd. + Also, the clock file for systemd-timesyncd may need to move from + /var/lib/private/systemd/timesync/clock to /var/lib/systemd/timesync/clock. * When unit files are loaded from disk, previously systemd would sometimes (depending on the unit loading order) load units from the diff --git a/hwdb/70-mouse.hwdb b/hwdb/70-mouse.hwdb index 07364c2c64d..3a15ff57ca8 100644 --- a/hwdb/70-mouse.hwdb +++ b/hwdb/70-mouse.hwdb @@ -310,6 +310,8 @@ mouse:usb:v17efp6050:name:Lenovo Precision USB Mouse: # Lenovo MOBGUL mouse:usb:v17efp601d:name:Primax Lenovo Laser Mouse: + MOUSE_DPI=1600@125 + # Lenovo MOBGULA mouse:usb:v17efp6045:name:Lenovo USB Laser Mouse: MOUSE_DPI=1600@125 @@ -331,6 +333,8 @@ mouse:usb:v17efp6044:name:ThinkPad USB Laser Mouse: # Logitech G5 Laser Mouse mouse:usb:v046dpc049:name:Logitech USB Gaming Mouse: + MOUSE_DPI=400@500 *800@500 2000@500 + # Logitech G500s Laser Gaming Mouse mouse:usb:v046dpc24e:name:Logitech G500s Laser Gaming Mouse: MOUSE_DPI=400@500 *800@500 2000@500 @@ -384,8 +388,12 @@ mouse:usb:v046dpc539:name:Logitech USB Receiver Mouse: # Logitech Wireless Mouse M185 mouse:usb:v046dp4008:name:Logitech M185: mouse:usb:v046dpc52b:name:Logitech Unifying Device. Wireless PID:4008: + MOUSE_DPI=1000@125 + # Logitech Wireless Mouse M510 mouse:usb:v046dp1025:name:Logitech M510: + MOUSE_DPI=1000@125 + # Logitech M705 (marathon mouse) mouse:usb:v046dp101b:name:Logitech M705: mouse:usb:v046dpc52b:name:Logitech Unifying Device. Wireless PID:101b: @@ -431,6 +439,8 @@ mouse:bluetooth:v046dpb003:name:Logitech MX1000 mouse: # Logitech Anywhere MX mouse:usb:v046dpc52b:name:Logitech Unifying Device. Wireless PID:1017: mouse:usb:v046dp1017:name:Logitech Anywhere MX: + MOUSE_WHEEL_CLICK_ANGLE=20 + # Logitech Anywhere MX 2S mouse:usb:v046dp406a:name:Logitech MX Anywhere 2S: MOUSE_WHEEL_CLICK_ANGLE=20 @@ -466,12 +476,20 @@ mouse:bluetooth:v046dpb019:name:MX Master 2S Mouse: # Logitech M-BJ58 Optical Mouse mouse:usb:v046dpc00e:name:Logitech USB-PS/2 Optical Mouse: + MOUSE_DPI=400@125 + # Logitech Mini Optical Mouse mouse:usb:v046dpc016:name:Logitech Optical USB Mouse: + MOUSE_DPI=400@125 + # Logitech MX310 Optical Mouse mouse:usb:v046dpc01b:name:Logitech USB-PS/2 Optical Mouse: + MOUSE_DPI=400@125 + # Logitech USB-PS/2 M-BT58 mouse:usb:v046dpc03e:name:Logitech USB-PS/2 Optical Mouse: + MOUSE_DPI=400@125 + # Logitech TrackMan Marble Wheel USB mouse:usb:v046dpc401:name:Logitech USB-PS/2 Trackball: MOUSE_DPI=400@125 @@ -486,10 +504,16 @@ mouse:usb:v046dpc045:name:Logitech USB-PS/2 Optical Mouse: # Logitech MX400 Performance Laser Mouse mouse:usb:v046dpc043:name:Logitech USB-PS/2 Optical Mouse: + MOUSE_DPI=800@125 + # Logitech MX1000 Laser Cordless Mouse mouse:usb:v046dpc50e:name:Logitech USB RECEIVER: + MOUSE_DPI=800@125 + # Logitech Cordless Click! Plus mouse:usb:v046dpc50e:name:Logitech USB Receiver: + MOUSE_DPI=800@125 + # Logitech, Inc. RX 300 Optical Mouse mouse:usb:v046dpc040:name:Logitech USB-PS/2 Optical Mouse: MOUSE_DPI=800@125 @@ -510,14 +534,24 @@ mouse:usb:v046dpc517:name:Logitech USB Receiver: # Logitech RX1000 Laser Mouse mouse:usb:v046dpc046:name:Logitech USB Optical Mouse: + MOUSE_DPI=1000@125 + # Logitech M100 Optical Mouse mouse:usb:v046dpc05a:name:Logitech USB Optical Mouse: + MOUSE_DPI=1000@125 + # Logitech USB Laser Mouse M-U0011-O rebranded as "terra Laser" mouse:usb:v046dpc065:name:Logitech USB Laser Mouse: + MOUSE_DPI=1000@125 + # Logitech USB Laser Mouse M-U0007 [M500] mouse:usb:v046dpc069:name:Logitech USB Laser Mouse: + MOUSE_DPI=1000@125 + # Logitech V500 Cordless Notebook Mouse mouse:usb:v046dpc510:name:Logitech USB Receiver: + MOUSE_DPI=1000@125 + # Logitech M560 Wireless Mouse mouse:usb:v046dp402d:name:Logitech M560: mouse:usb:v046dpc52b:name:Logitech Unifying Device. Wireless PID:402d: @@ -577,6 +611,8 @@ mouse:usb:v045ep076c:name:Microsoft Microsoft® Comfort Mouse 4500: # Microsoft Wireless Mobile Mouse 4000 mouse:usb:v045ep0745:name:Microsoft Microsoft® Nano Transceiver v2.0: + MOUSE_DPI=1000@142 + # Microsoft Sculpt Ergonomic Mouse mouse:usb:v045ep07a5:name:Microsoft Microsoft® 2.4GHz Transceiver v9.0: MOUSE_DPI=1000@142 diff --git a/man/systemd-cat.xml b/man/systemd-cat.xml index 72cd196c4e5..446fa4ba31b 100644 --- a/man/systemd-cat.xml +++ b/man/systemd-cat.xml @@ -92,6 +92,29 @@ see below. + + + + Specifies the default priority level for + messages from the process's standard error output (stderr). + Usage of this option is the same as the + option, above, and both can be + used at once. When both are used, + will specify the default priority for standard output (stdout). + + + If is not specified, + messages from stderr will still be logged, with the same + default priority level as stdout. + + Also, note that when stdout and stderr use the same + default priority, the messages will be strictly ordered, + because one channel is used for both. When the default priority + differs, two channels are used, and so stdout messages will not + be strictly ordered with respect to stderr messages - though + they will tend to be approximately ordered. + + diff --git a/src/basic/btrfs-util.h b/src/basic/btrfs-util.h index 085aca4dbcb..7d848a75d36 100644 --- a/src/basic/btrfs-util.h +++ b/src/basic/btrfs-util.h @@ -28,17 +28,17 @@ typedef struct BtrfsQuotaInfo { } BtrfsQuotaInfo; typedef enum BtrfsSnapshotFlags { - BTRFS_SNAPSHOT_FALLBACK_COPY = 1, /* If the source isn't a subvolume, reflink everything */ - BTRFS_SNAPSHOT_READ_ONLY = 2, - BTRFS_SNAPSHOT_RECURSIVE = 4, - BTRFS_SNAPSHOT_QUOTA = 8, - BTRFS_SNAPSHOT_FALLBACK_DIRECTORY = 16, /* If the destination doesn't support subvolumes, reflink/copy instead */ - BTRFS_SNAPSHOT_FALLBACK_IMMUTABLE = 32, /* When we can't create a subvolume, use the FS_IMMUTABLE attribute for indicating read-only */ + BTRFS_SNAPSHOT_FALLBACK_COPY = 1 << 0, /* If the source isn't a subvolume, reflink everything */ + BTRFS_SNAPSHOT_READ_ONLY = 1 << 1, + BTRFS_SNAPSHOT_RECURSIVE = 1 << 2, + BTRFS_SNAPSHOT_QUOTA = 1 << 3, + BTRFS_SNAPSHOT_FALLBACK_DIRECTORY = 1 << 4, /* If the destination doesn't support subvolumes, reflink/copy instead */ + BTRFS_SNAPSHOT_FALLBACK_IMMUTABLE = 1 << 5, /* When we can't create a subvolume, use the FS_IMMUTABLE attribute for indicating read-only */ } BtrfsSnapshotFlags; typedef enum BtrfsRemoveFlags { - BTRFS_REMOVE_RECURSIVE = 1, - BTRFS_REMOVE_QUOTA = 2, + BTRFS_REMOVE_RECURSIVE = 1 << 0, + BTRFS_REMOVE_QUOTA = 1 << 1, } BtrfsRemoveFlags; int btrfs_is_filesystem(int fd); diff --git a/src/basic/cgroup-util.h b/src/basic/cgroup-util.h index 220c8d381fe..119b493dc63 100644 --- a/src/basic/cgroup-util.h +++ b/src/basic/cgroup-util.h @@ -162,9 +162,9 @@ int cg_enumerate_subgroups(const char *controller, const char *path, DIR **_d); int cg_read_subgroup(DIR *d, char **fn); typedef enum CGroupFlags { - CGROUP_SIGCONT = 1, - CGROUP_IGNORE_SELF = 2, - CGROUP_REMOVE = 4, + CGROUP_SIGCONT = 1 << 0, + CGROUP_IGNORE_SELF = 1 << 1, + CGROUP_REMOVE = 1 << 2, } CGroupFlags; typedef void (*cg_kill_log_func_t)(pid_t pid, int sig, void *userdata); diff --git a/src/basic/env-util.h b/src/basic/env-util.h index 4d21ea6bef5..d54f99658bd 100644 --- a/src/basic/env-util.h +++ b/src/basic/env-util.h @@ -13,9 +13,9 @@ bool env_value_is_valid(const char *e); bool env_assignment_is_valid(const char *e); enum { - REPLACE_ENV_USE_ENVIRONMENT = 1u, - REPLACE_ENV_ALLOW_BRACELESS = 2u, - REPLACE_ENV_ALLOW_EXTENDED = 4u, + REPLACE_ENV_USE_ENVIRONMENT = 1 << 0, + REPLACE_ENV_ALLOW_BRACELESS = 1 << 1, + REPLACE_ENV_ALLOW_EXTENDED = 1 << 2, }; char *replace_env_n(const char *format, size_t n, char **env, unsigned flags); diff --git a/src/basic/extract-word.h b/src/basic/extract-word.h index 8c63b7c306b..705ebbe95bb 100644 --- a/src/basic/extract-word.h +++ b/src/basic/extract-word.h @@ -4,12 +4,12 @@ #include "macro.h" typedef enum ExtractFlags { - EXTRACT_RELAX = 1, - EXTRACT_CUNESCAPE = 2, - EXTRACT_CUNESCAPE_RELAX = 4, - EXTRACT_QUOTES = 8, - EXTRACT_DONT_COALESCE_SEPARATORS = 16, - EXTRACT_RETAIN_ESCAPE = 32, + EXTRACT_RELAX = 1 << 0, + EXTRACT_CUNESCAPE = 1 << 1, + EXTRACT_CUNESCAPE_RELAX = 1 << 2, + EXTRACT_QUOTES = 1 << 3, + EXTRACT_DONT_COALESCE_SEPARATORS = 1 << 4, + EXTRACT_RETAIN_ESCAPE = 1 << 5, } ExtractFlags; int extract_first_word(const char **p, char **ret, const char *separators, ExtractFlags flags); diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c index 57700e2388a..0af869cf652 100644 --- a/src/basic/stat-util.c +++ b/src/basic/stat-util.c @@ -338,7 +338,6 @@ int device_path_make_major_minor(mode_t mode, dev_t devno, char **ret) { return -ENOMEM; return 0; - } int device_path_make_canonical(mode_t mode, dev_t devno, char **ret) { diff --git a/src/basic/unit-name.h b/src/basic/unit-name.h index d373f03aca5..0629db3f67c 100644 --- a/src/basic/unit-name.h +++ b/src/basic/unit-name.h @@ -9,9 +9,9 @@ #define UNIT_NAME_MAX 256 typedef enum UnitNameFlags { - UNIT_NAME_PLAIN = 1, /* Allow foo.service */ - UNIT_NAME_INSTANCE = 2, /* Allow foo@bar.service */ - UNIT_NAME_TEMPLATE = 4, /* Allow foo@.service */ + UNIT_NAME_PLAIN = 1 << 0, /* Allow foo.service */ + UNIT_NAME_INSTANCE = 1 << 1, /* Allow foo@bar.service */ + UNIT_NAME_TEMPLATE = 1 << 2, /* Allow foo@.service */ UNIT_NAME_ANY = UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE, } UnitNameFlags; @@ -50,8 +50,8 @@ int unit_name_from_path_instance(const char *prefix, const char *path, const cha int unit_name_to_path(const char *name, char **ret); typedef enum UnitNameMangle { - UNIT_NAME_MANGLE_GLOB = 1, - UNIT_NAME_MANGLE_WARN = 2, + UNIT_NAME_MANGLE_GLOB = 1 << 0, + UNIT_NAME_MANGLE_WARN = 1 << 1, } UnitNameMangle; int unit_name_mangle_with_suffix(const char *name, UnitNameMangle flags, const char *suffix, char **ret); diff --git a/src/core/socket.c b/src/core/socket.c index dd126a7f21b..dd7e5d91fae 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -561,7 +561,7 @@ int socket_acquire_peer(Socket *s, int fd, SocketPeer **p) { r = getpeername(fd, &sa.peer.sa, &salen); if (r < 0) - return log_error_errno(errno, "getpeername failed: %m"); + return log_unit_error_errno(UNIT(s), errno, "getpeername failed: %m"); if (!IN_SET(sa.peer.sa.sa_family, AF_INET, AF_INET6, AF_VSOCK)) { *p = NULL; @@ -1465,6 +1465,17 @@ static int socket_address_listen_do( label); } +static int log_address_error_errno(Unit *u, const SocketAddress *address, int error, const char *fmt) { + _cleanup_free_ char *t = NULL; + + (void) socket_address_print(address, &t); + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-nonliteral" + return log_unit_error_errno(u, error, fmt, strna(t)); +#pragma GCC diagnostic pop +} + static int socket_address_listen_in_cgroup( Socket *s, const SocketAddress *address, @@ -1503,13 +1514,13 @@ static int socket_address_listen_in_cgroup( fd = socket_address_listen_do(s, address, label); if (fd < 0) { - log_unit_error_errno(UNIT(s), fd, "Failed to create listening socket: %m"); + log_address_error_errno(UNIT(s), address, fd, "Failed to create listening socket (%s): %m"); _exit(EXIT_FAILURE); } r = send_one_fd(pair[1], fd, 0); if (r < 0) { - log_unit_error_errno(UNIT(s), r, "Failed to send listening socket to parent: %m"); + log_address_error_errno(UNIT(s), address, r, "Failed to send listening socket (%s) to parent: %m"); _exit(EXIT_FAILURE); } @@ -1527,19 +1538,22 @@ static int socket_address_listen_in_cgroup( } if (fd < 0) - return log_unit_error_errno(UNIT(s), fd, "Failed to receive listening socket: %m"); + return log_address_error_errno(UNIT(s), address, fd, "Failed to receive listening socket (%s): %m"); return fd; shortcut: fd = socket_address_listen_do(s, address, label); if (fd < 0) - return log_error_errno(fd, "Failed to create listening socket: %m"); + return log_address_error_errno(UNIT(s), address, fd, "Failed to create listening socket (%s): %m"); return fd; } -static int socket_open_fds(Socket *s) { +DEFINE_TRIVIAL_CLEANUP_FUNC(Socket *, socket_close_fds); + +static int socket_open_fds(Socket *_s) { + _cleanup_(socket_close_fdsp) Socket *s = _s; _cleanup_(mac_selinux_freep) char *label = NULL; bool know_label = false; SocketPort *p; @@ -1562,7 +1576,7 @@ static int socket_open_fds(Socket *s) { r = socket_determine_selinux_label(s, &label); if (r < 0) - goto rollback; + return log_unit_error_errno(UNIT(s), r, "Failed to determine SELinux label: %m"); know_label = true; } @@ -1584,7 +1598,7 @@ static int socket_open_fds(Socket *s) { r = socket_address_listen_in_cgroup(s, &p->address, label); if (r < 0) - goto rollback; + return r; p->fd = r; socket_apply_socket_options(s, p->fd); @@ -1593,39 +1607,38 @@ static int socket_open_fds(Socket *s) { case SOCKET_SPECIAL: - p->fd = special_address_create(p->path, s->writable); - if (p->fd < 0) { - r = p->fd; - goto rollback; - } + r = special_address_create(p->path, s->writable); + if (r < 0) + return log_unit_error_errno(UNIT(s), r, "Failed to open special file %s: %m", p->path); + + p->fd = r; break; case SOCKET_FIFO: - p->fd = fifo_address_create( + r = fifo_address_create( p->path, s->directory_mode, s->socket_mode); - if (p->fd < 0) { - r = p->fd; - goto rollback; - } + if (r < 0) + return log_unit_error_errno(UNIT(s), r, "Failed to open FIFO %s: %m", p->path); + p->fd = r; socket_apply_fifo_options(s, p->fd); socket_symlink(s); break; case SOCKET_MQUEUE: - p->fd = mq_address_create( + r = mq_address_create( p->path, s->socket_mode, s->mq_maxmsg, s->mq_msgsize); - if (p->fd < 0) { - r = p->fd; - goto rollback; - } + if (r < 0) + return log_unit_error_errno(UNIT(s), r, "Failed to open message queue %s: %m", p->path); + + p->fd = r; break; case SOCKET_USB_FUNCTION: { @@ -1633,19 +1646,19 @@ static int socket_open_fds(Socket *s) { ep = path_make_absolute("ep0", p->path); - p->fd = usbffs_address_create(ep); - if (p->fd < 0) { - r = p->fd; - goto rollback; - } + r = usbffs_address_create(ep); + if (r < 0) + return r; + + p->fd = r; r = usbffs_write_descs(p->fd, SERVICE(UNIT_DEREF(s->service))); if (r < 0) - goto rollback; + return r; r = usbffs_dispatch_eps(p); if (r < 0) - goto rollback; + return r; break; } @@ -1654,11 +1667,8 @@ static int socket_open_fds(Socket *s) { } } + s = NULL; return 0; - -rollback: - socket_close_fds(s); - return r; } static void socket_unwatch_fds(Socket *s) { @@ -2521,14 +2531,14 @@ static int socket_serialize(Unit *u, FILE *f, FDSet *fds) { copy = fdset_put_dup(fds, p->fd); if (copy < 0) - return log_warning_errno(copy, "Failed to serialize socket fd: %m"); + return log_unit_warning_errno(u, copy, "Failed to serialize socket fd: %m"); if (p->type == SOCKET_SOCKET) { _cleanup_free_ char *t = NULL; r = socket_address_print(&p->address, &t); if (r < 0) - return log_error_errno(r, "Failed to format socket address: %m"); + return log_unit_error_errno(u, r, "Failed to format socket address: %m"); if (socket_address_family(&p->address) == AF_NETLINK) (void) serialize_item_format(f, "netlink", "%i %s", copy, t); diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c index ba39f596fc7..524327c4da0 100644 --- a/src/fsck/fsck.c +++ b/src/fsck/fsck.c @@ -414,7 +414,7 @@ static int run(int argc, char *argv[]) { exit_status = wait_for_terminate_and_check("fsck", pid, WAIT_LOG_ABNORMAL); if (exit_status < 0) return exit_status; - if (exit_status & ~1) { + if ((exit_status & ~FSCK_ERROR_CORRECTED) != FSCK_SUCCESS) { log_error("fsck failed with exit status %i.", exit_status); if ((exit_status & FSCK_SYSTEM_SHOULD_REBOOT) && root_directory) { diff --git a/src/journal/cat.c b/src/journal/cat.c index a84350fbc92..9900bd2e863 100644 --- a/src/journal/cat.c +++ b/src/journal/cat.c @@ -20,6 +20,7 @@ static const char *arg_identifier = NULL; static int arg_priority = LOG_INFO; +static int arg_stderr_priority = -1; static bool arg_level_prefix = true; static int help(void) { @@ -32,11 +33,12 @@ static int help(void) { printf("%s [OPTIONS...] {COMMAND} ...\n\n" "Execute process with stdout/stderr connected to the journal.\n\n" - " -h --help Show this help\n" - " --version Show package version\n" - " -t --identifier=STRING Set syslog identifier\n" - " -p --priority=PRIORITY Set priority value (0..7)\n" - " --level-prefix=BOOL Control whether level prefix shall be parsed\n" + " -h --help Show this help\n" + " --version Show package version\n" + " -t --identifier=STRING Set syslog identifier\n" + " -p --priority=PRIORITY Set priority value (0..7)\n" + " --stderr-priority=PRIORITY Set priority value (0..7) used for stderr\n" + " --level-prefix=BOOL Control whether level prefix shall be parsed\n" "\nSee the %s for details.\n" , program_invocation_short_name , link @@ -49,15 +51,17 @@ static int parse_argv(int argc, char *argv[]) { enum { ARG_VERSION = 0x100, + ARG_STDERR_PRIORITY, ARG_LEVEL_PREFIX }; static const struct option options[] = { - { "help", no_argument, NULL, 'h' }, - { "version", no_argument, NULL, ARG_VERSION }, - { "identifier", required_argument, NULL, 't' }, - { "priority", required_argument, NULL, 'p' }, - { "level-prefix", required_argument, NULL, ARG_LEVEL_PREFIX }, + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, ARG_VERSION }, + { "identifier", required_argument, NULL, 't' }, + { "priority", required_argument, NULL, 'p' }, + { "stderr-priority", required_argument, NULL, ARG_STDERR_PRIORITY }, + { "level-prefix", required_argument, NULL, ARG_LEVEL_PREFIX }, {} }; @@ -91,6 +95,13 @@ static int parse_argv(int argc, char *argv[]) { "Failed to parse priority value."); break; + case ARG_STDERR_PRIORITY: + arg_stderr_priority = log_level_from_string(optarg); + if (arg_stderr_priority < 0) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Failed to parse stderr priority value."); + break; + case ARG_LEVEL_PREFIX: { int k; @@ -113,7 +124,7 @@ static int parse_argv(int argc, char *argv[]) { } static int run(int argc, char *argv[]) { - _cleanup_close_ int fd = -1, saved_stderr = -1; + _cleanup_close_ int outfd = -1, errfd = -1, saved_stderr = -1; int r; log_parse_environment(); @@ -123,14 +134,21 @@ static int run(int argc, char *argv[]) { if (r <= 0) return r; - fd = sd_journal_stream_fd(arg_identifier, arg_priority, arg_level_prefix); - if (fd < 0) - return log_error_errno(fd, "Failed to create stream fd: %m"); + outfd = sd_journal_stream_fd(arg_identifier, arg_priority, arg_level_prefix); + if (outfd < 0) + return log_error_errno(outfd, "Failed to create stream fd: %m"); + + if (arg_stderr_priority >= 0 && arg_stderr_priority != arg_priority) { + errfd = sd_journal_stream_fd(arg_identifier, arg_stderr_priority, arg_level_prefix); + if (errfd < 0) + return log_error_errno(errfd, "Failed to create stream fd: %m"); + } saved_stderr = fcntl(STDERR_FILENO, F_DUPFD_CLOEXEC, 3); - r = rearrange_stdio(STDIN_FILENO, fd, fd); /* Invalidates fd on succcess + error! */ - TAKE_FD(fd); + r = rearrange_stdio(STDIN_FILENO, outfd, errfd < 0 ? outfd : errfd); /* Invalidates fd on succcess + error! */ + TAKE_FD(outfd); + TAKE_FD(errfd); if (r < 0) return log_error_errno(r, "Failed to rearrange stdout/stderr: %m"); diff --git a/src/libsystemd/sd-bus/bus-dump.h b/src/libsystemd/sd-bus/bus-dump.h index 373a86dd4ff..a1b67c6b14f 100644 --- a/src/libsystemd/sd-bus/bus-dump.h +++ b/src/libsystemd/sd-bus/bus-dump.h @@ -7,8 +7,8 @@ #include "sd-bus.h" enum { - BUS_MESSAGE_DUMP_WITH_HEADER = 1, - BUS_MESSAGE_DUMP_SUBTREE_ONLY = 2, + BUS_MESSAGE_DUMP_WITH_HEADER = 1 << 0, + BUS_MESSAGE_DUMP_SUBTREE_ONLY = 1 << 1, }; int bus_message_dump(sd_bus_message *m, FILE *f, unsigned flags); diff --git a/src/libsystemd/sd-bus/bus-protocol.h b/src/libsystemd/sd-bus/bus-protocol.h index a5f4724aa9b..d01fd8e6a3f 100644 --- a/src/libsystemd/sd-bus/bus-protocol.h +++ b/src/libsystemd/sd-bus/bus-protocol.h @@ -54,9 +54,9 @@ enum { /* Flags */ enum { - BUS_MESSAGE_NO_REPLY_EXPECTED = 1, - BUS_MESSAGE_NO_AUTO_START = 2, - BUS_MESSAGE_ALLOW_INTERACTIVE_AUTHORIZATION = 4, + BUS_MESSAGE_NO_REPLY_EXPECTED = 1 << 0, + BUS_MESSAGE_NO_AUTO_START = 1 << 1, + BUS_MESSAGE_ALLOW_INTERACTIVE_AUTHORIZATION = 1 << 2, }; /* Header fields */ @@ -78,9 +78,9 @@ enum { /* RequestName parameters */ enum { - BUS_NAME_ALLOW_REPLACEMENT = 1, - BUS_NAME_REPLACE_EXISTING = 2, - BUS_NAME_DO_NOT_QUEUE = 4 + BUS_NAME_ALLOW_REPLACEMENT = 1 << 0, + BUS_NAME_REPLACE_EXISTING = 1 << 1, + BUS_NAME_DO_NOT_QUEUE = 1 << 2, }; /* RequestName returns */ diff --git a/src/login/logind-inhibit.h b/src/login/logind-inhibit.h index d358a485592..650587106da 100644 --- a/src/login/logind-inhibit.h +++ b/src/login/logind-inhibit.h @@ -4,15 +4,15 @@ typedef struct Inhibitor Inhibitor; typedef enum InhibitWhat { - INHIBIT_SHUTDOWN = 1, - INHIBIT_SLEEP = 2, - INHIBIT_IDLE = 4, - INHIBIT_HANDLE_POWER_KEY = 8, - INHIBIT_HANDLE_SUSPEND_KEY = 16, - INHIBIT_HANDLE_HIBERNATE_KEY = 32, - INHIBIT_HANDLE_LID_SWITCH = 64, - _INHIBIT_WHAT_MAX = 128, - _INHIBIT_WHAT_INVALID = -1 + INHIBIT_SHUTDOWN = 1 << 0, + INHIBIT_SLEEP = 1 << 1, + INHIBIT_IDLE = 1 << 2, + INHIBIT_HANDLE_POWER_KEY = 1 << 3, + INHIBIT_HANDLE_SUSPEND_KEY = 1 << 4, + INHIBIT_HANDLE_HIBERNATE_KEY = 1 << 5, + INHIBIT_HANDLE_LID_SWITCH = 1 << 6, + _INHIBIT_WHAT_MAX = 1 << 7, + _INHIBIT_WHAT_INVALID = -1 } InhibitWhat; typedef enum InhibitMode { diff --git a/src/resolve/resolved-dns-answer.h b/src/resolve/resolved-dns-answer.h index 97514c34089..47fc80e2b02 100644 --- a/src/resolve/resolved-dns-answer.h +++ b/src/resolve/resolved-dns-answer.h @@ -15,11 +15,11 @@ typedef struct DnsAnswerItem DnsAnswerItem; * Note that we usually encode the empty DnsAnswer object as a simple NULL. */ typedef enum DnsAnswerFlags { - DNS_ANSWER_AUTHENTICATED = 1, /* Item has been authenticated */ - DNS_ANSWER_CACHEABLE = 2, /* Item is subject to caching */ - DNS_ANSWER_SHARED_OWNER = 4, /* For mDNS: RRset may be owner by multiple peers */ - DNS_ANSWER_CACHE_FLUSH = 8, /* For mDNS: sets cache-flush bit in the rrclass of response records */ - DNS_ANSWER_GOODBYE = 16, /* For mDNS: item is subject to disappear */ + DNS_ANSWER_AUTHENTICATED = 1 << 0, /* Item has been authenticated */ + DNS_ANSWER_CACHEABLE = 1 << 1, /* Item is subject to caching */ + DNS_ANSWER_SHARED_OWNER = 1 << 2, /* For mDNS: RRset may be owner by multiple peers */ + DNS_ANSWER_CACHE_FLUSH = 1 << 3, /* For mDNS: sets cache-flush bit in the rrclass of response records */ + DNS_ANSWER_GOODBYE = 1 << 4, /* For mDNS: item is subject to disappear */ } DnsAnswerFlags; struct DnsAnswerItem { diff --git a/src/shared/json.c b/src/shared/json.c index 59c4617592c..3786ff12b84 100644 --- a/src/shared/json.c +++ b/src/shared/json.c @@ -979,6 +979,8 @@ bool json_variant_has_type(JsonVariant *v, JsonVariantType type) { JsonVariantType rt; v = json_variant_dereference(v); + if (!v) + return false; rt = json_variant_type(v); if (rt == type) @@ -3140,10 +3142,7 @@ int json_log_internal( va_list ap; int r; - if (error < 0) - error = -error; - - errno = error; + errno = ERRNO_VALUE(error); va_start(ap, format); (void) vsnprintf(buffer, sizeof buffer, format, ap); diff --git a/src/shared/json.h b/src/shared/json.h index 4eba91c2720..f8e035cda19 100644 --- a/src/shared/json.h +++ b/src/shared/json.h @@ -1,5 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ - #pragma once #include @@ -154,7 +153,7 @@ typedef enum JsonFormatFlags { JSON_FORMAT_NEWLINE = 1 << 0, /* suffix with newline */ JSON_FORMAT_PRETTY = 1 << 1, /* add internal whitespace to appeal to human readers */ JSON_FORMAT_COLOR = 1 << 2, /* insert ANSI color sequences */ - JSON_FORMAT_COLOR_AUTO = 1 << 3, /* insetr ANSI color sequences if colors_enabled() says so */ + JSON_FORMAT_COLOR_AUTO = 1 << 3, /* insert ANSI color sequences if colors_enabled() says so */ JSON_FORMAT_SOURCE = 1 << 4, /* prefix with source filename/line/column */ JSON_FORMAT_SSE = 1 << 5, /* prefix/suffix with W3C server-sent events */ JSON_FORMAT_SEQ = 1 << 6, /* prefix/suffix with RFC 7464 application/json-seq */ diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c index 872c25c3dc7..bf426eb8bca 100644 --- a/src/shared/loop-util.c +++ b/src/shared/loop-util.c @@ -45,11 +45,11 @@ int loop_device_make(int fd, int open_flags, LoopDevice **ret) { *d = (LoopDevice) { .fd = copy, .nr = -1, + .relinquished = true, /* It's not allocated by us, don't destroy it when this object is freed */ }; *ret = d; - - return 0; + return d->fd; } r = stat_verify_regular(&st); @@ -88,8 +88,7 @@ int loop_device_make(int fd, int open_flags, LoopDevice **ret) { }; *ret = d; - - return (*ret)->fd; + return d->fd; } int loop_device_make_by_path(const char *path, int open_flags, LoopDevice **ret) { diff --git a/src/udev/udevadm-control.c b/src/udev/udevadm-control.c index d9320418cf8..cb9b4cc89ee 100644 --- a/src/udev/udevadm-control.c +++ b/src/udev/udevadm-control.c @@ -26,6 +26,7 @@ #include "udevadm.h" #include "udev-ctrl.h" #include "util.h" +#include "virt.h" static int help(void) { printf("%s control OPTION\n\n" @@ -70,6 +71,11 @@ int control_main(int argc, char *argv[], void *userdata) { if (r < 0) return r; + if (running_in_chroot() > 0) { + log_info("Running in chroot, ignoring request."); + return 0; + } + if (argc <= 1) log_error("Option missing"); diff --git a/src/udev/udevadm-monitor.c b/src/udev/udevadm-monitor.c index f7737d07908..f1b3e25cdda 100644 --- a/src/udev/udevadm-monitor.c +++ b/src/udev/udevadm-monitor.c @@ -17,6 +17,7 @@ #include "signal-util.h" #include "string-util.h" #include "udevadm.h" +#include "virt.h" static bool arg_show_property = false; static bool arg_print_kernel = false; @@ -210,6 +211,11 @@ int monitor_main(int argc, char *argv[], void *userdata) { if (r <= 0) goto finalize; + if (running_in_chroot() > 0) { + log_info("Running in chroot, ignoring request."); + return 0; + } + /* Callers are expecting to see events as they happen: Line buffering */ setlinebuf(stdout); diff --git a/src/udev/udevadm-settle.c b/src/udev/udevadm-settle.c index 4ae237d430b..9b05e9acf06 100644 --- a/src/udev/udevadm-settle.c +++ b/src/udev/udevadm-settle.c @@ -18,6 +18,7 @@ #include "udevadm.h" #include "udev-ctrl.h" #include "util.h" +#include "virt.h" static usec_t arg_timeout = 120 * USEC_PER_SEC; static const char *arg_exists = NULL; @@ -88,6 +89,11 @@ int settle_main(int argc, char *argv[], void *userdata) { if (r <= 0) return r; + if (running_in_chroot() > 0) { + log_info("Running in chroot, ignoring request."); + return 0; + } + deadline = now(CLOCK_MONOTONIC) + arg_timeout; /* guarantee that the udev daemon isn't pre-processing */ diff --git a/src/udev/udevadm-trigger.c b/src/udev/udevadm-trigger.c index f13a08f3f93..aa9ebd5ac57 100644 --- a/src/udev/udevadm-trigger.c +++ b/src/udev/udevadm-trigger.c @@ -15,6 +15,7 @@ #include "strv.h" #include "udevadm.h" #include "udevadm-util.h" +#include "virt.h" static bool arg_verbose = false; static bool arg_dry_run = false; @@ -158,6 +159,11 @@ int trigger_main(int argc, char *argv[], void *userdata) { bool settle = false; int c, r; + if (running_in_chroot() > 0) { + log_info("Running in chroot, ignoring request."); + return 0; + } + r = sd_device_enumerator_new(&e); if (r < 0) return r;