From 6eab5f06566dda992b416c133e07b0c66dccb9a8 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 3 Jan 2019 12:18:47 +0100 Subject: [PATCH 1/9] env-util: normalize one more flags enum --- src/basic/env-util.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/basic/env-util.h b/src/basic/env-util.h index 4d21ea6bef..d54f99658b 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); From aebfc8f0904eb3be6d71104afba2ba8d8e18089a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 28 Dec 2018 19:02:05 +0100 Subject: [PATCH 2/9] stat-util: remove spurious newline --- src/basic/stat-util.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c index 57700e2388..0af869cf65 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) { From cbf13087cc0db191e9ab0f70bef9f1f64d6bb340 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 23 Dec 2018 19:24:40 +0100 Subject: [PATCH 3/9] fsck: use symbolic names where we have them --- src/fsck/fsck.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c index ba39f596fc..524327c4da 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) { From 26c1be0fdcc2b4ce4b05d9174c0166152bdb9aa8 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 31 Dec 2018 16:56:06 +0100 Subject: [PATCH 4/9] loop-util: minor simplification --- src/shared/loop-util.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c index 872c25c3dc..e77eee6d3a 100644 --- a/src/shared/loop-util.c +++ b/src/shared/loop-util.c @@ -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) { From 16420be1fdd4a1430b4216d1ae9155914175ed42 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 31 Dec 2018 17:00:10 +0100 Subject: [PATCH 5/9] loop-util: tweak codepath when a loopback file is "created" from an existing block device Be more careful with initialized of the 'relinquished' boolean field, and let's return the fd, like we do for the regular codepath, too. --- src/shared/loop-util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c index e77eee6d3a..bf426eb8bc 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); From fc0f6fbffc6cb488768d8366f81cff5317acc14c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 3 Jan 2019 12:19:10 +0100 Subject: [PATCH 6/9] json: teach json_log() the new SYNTHETIC_ERRNO() logic --- src/shared/json.c | 5 +---- src/shared/json.h | 1 - 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/shared/json.c b/src/shared/json.c index 59c4617592..01faf4037b 100644 --- a/src/shared/json.c +++ b/src/shared/json.c @@ -3140,10 +3140,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 4eba91c272..724fb2e53f 100644 --- a/src/shared/json.h +++ b/src/shared/json.h @@ -1,5 +1,4 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ - #pragma once #include From 6af022fedd24d2605157eb683428082ac3d823c8 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 4 Jan 2019 13:24:40 +0100 Subject: [PATCH 7/9] json: fix typo --- src/shared/json.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/json.h b/src/shared/json.h index 724fb2e53f..f8e035cda1 100644 --- a/src/shared/json.h +++ b/src/shared/json.h @@ -153,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 */ From f8c186c9ece5c1c0b89abf52f058efb0ed37e0cb Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 4 Jan 2019 13:24:18 +0100 Subject: [PATCH 8/9] json: handle NULL explicitly in json_variant_has_type() --- src/shared/json.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/shared/json.c b/src/shared/json.c index 01faf4037b..3786ff12b8 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) From be0b7a1a66fd269b644124c4633088ab2224d1fb Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 7 Jan 2019 17:48:28 +0100 Subject: [PATCH 9/9] tree-wide: always declare bitflag enums the same way let's always use the 1 << x syntax. No change of behaviour or even of the compiled binary. --- src/basic/btrfs-util.h | 16 ++++++++-------- src/basic/cgroup-util.h | 6 +++--- src/basic/extract-word.h | 12 ++++++------ src/basic/unit-name.h | 10 +++++----- src/libsystemd/sd-bus/bus-dump.h | 4 ++-- src/libsystemd/sd-bus/bus-protocol.h | 12 ++++++------ src/login/logind-inhibit.h | 18 +++++++++--------- src/resolve/resolved-dns-answer.h | 10 +++++----- 8 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/basic/btrfs-util.h b/src/basic/btrfs-util.h index 085aca4dbc..7d848a75d3 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 220c8d381f..119b493dc6 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/extract-word.h b/src/basic/extract-word.h index 8c63b7c306..705ebbe95b 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/unit-name.h b/src/basic/unit-name.h index d373f03aca..0629db3f67 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/libsystemd/sd-bus/bus-dump.h b/src/libsystemd/sd-bus/bus-dump.h index 373a86dd4f..a1b67c6b14 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 a5f4724aa9..d01fd8e6a3 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 d358a48559..650587106d 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 97514c3408..47fc80e2b0 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 {