diff options
Diffstat (limited to 'src')
37 files changed, 219 insertions, 103 deletions
diff --git a/src/basic/fdset.c b/src/basic/fdset.c index 6101b628ec..a4823e6659 100644 --- a/src/basic/fdset.c +++ b/src/basic/fdset.c @@ -267,8 +267,7 @@ bool fdset_isempty(FDSet *fds) { int fdset_iterate(FDSet *s, Iterator *i) { void *p; - p = set_iterate(MAKE_SET(s), i); - if (!p) + if (!set_iterate(MAKE_SET(s), i, &p)) return -ENOENT; return PTR_TO_FD(p); diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c index 20d599d04b..0ee2f3bd31 100644 --- a/src/basic/hashmap.c +++ b/src/basic/hashmap.c @@ -733,29 +733,33 @@ static unsigned hashmap_iterate_entry(HashmapBase *h, Iterator *i) { : hashmap_iterate_in_internal_order(h, i); } -void *internal_hashmap_iterate(HashmapBase *h, Iterator *i, const void **key) { +bool internal_hashmap_iterate(HashmapBase *h, Iterator *i, void **value, const void **key) { struct hashmap_base_entry *e; void *data; unsigned idx; idx = hashmap_iterate_entry(h, i); if (idx == IDX_NIL) { + if (value) + *value = NULL; if (key) *key = NULL; - return NULL; + return false; } e = bucket_at(h, idx); data = entry_value(h, e); + if (value) + *value = data; if (key) *key = e->key; - return data; + return true; } -void *set_iterate(Set *s, Iterator *i) { - return internal_hashmap_iterate(HASHMAP_BASE(s), i, NULL); +bool set_iterate(Set *s, Iterator *i, void **value) { + return internal_hashmap_iterate(HASHMAP_BASE(s), i, value, NULL); } #define HASHMAP_FOREACH_IDX(idx, h, i) \ diff --git a/src/basic/hashmap.h b/src/basic/hashmap.h index a03ee5812a..5723f09ca9 100644 --- a/src/basic/hashmap.h +++ b/src/basic/hashmap.h @@ -65,6 +65,7 @@ typedef struct { } Iterator; #define _IDX_ITERATOR_FIRST (UINT_MAX - 1) +#define _IDX_ITERATOR_NIL (UINT_MAX) #define ITERATOR_FIRST ((Iterator) { .idx = _IDX_ITERATOR_FIRST, .next_key = NULL }) typedef unsigned long (*hash_func_t)(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]); @@ -296,12 +297,12 @@ static inline unsigned ordered_hashmap_buckets(OrderedHashmap *h) { return internal_hashmap_buckets(HASHMAP_BASE(h)); } -void *internal_hashmap_iterate(HashmapBase *h, Iterator *i, const void **key); -static inline void *hashmap_iterate(Hashmap *h, Iterator *i, const void **key) { - return internal_hashmap_iterate(HASHMAP_BASE(h), i, key); +bool internal_hashmap_iterate(HashmapBase *h, Iterator *i, void **value, const void **key); +static inline bool hashmap_iterate(Hashmap *h, Iterator *i, void **value, const void **key) { + return internal_hashmap_iterate(HASHMAP_BASE(h), i, value, key); } -static inline void *ordered_hashmap_iterate(OrderedHashmap *h, Iterator *i, const void **key) { - return internal_hashmap_iterate(HASHMAP_BASE(h), i, key); +static inline bool ordered_hashmap_iterate(OrderedHashmap *h, Iterator *i, void **value, const void **key) { + return internal_hashmap_iterate(HASHMAP_BASE(h), i, value, key); } void internal_hashmap_clear(HashmapBase *h); @@ -386,24 +387,16 @@ static inline char **ordered_hashmap_get_strv(OrderedHashmap *h) { * It is safe to remove the current entry. */ #define HASHMAP_FOREACH(e, h, i) \ - for ((i) = ITERATOR_FIRST, (e) = hashmap_iterate((h), &(i), NULL); \ - (e); \ - (e) = hashmap_iterate((h), &(i), NULL)) + for ((i) = ITERATOR_FIRST; hashmap_iterate((h), &(i), (void**)&(e), NULL); ) #define ORDERED_HASHMAP_FOREACH(e, h, i) \ - for ((i) = ITERATOR_FIRST, (e) = ordered_hashmap_iterate((h), &(i), NULL); \ - (e); \ - (e) = ordered_hashmap_iterate((h), &(i), NULL)) + for ((i) = ITERATOR_FIRST; ordered_hashmap_iterate((h), &(i), (void**)&(e), NULL); ) #define HASHMAP_FOREACH_KEY(e, k, h, i) \ - for ((i) = ITERATOR_FIRST, (e) = hashmap_iterate((h), &(i), (const void**) &(k)); \ - (e); \ - (e) = hashmap_iterate((h), &(i), (const void**) &(k))) + for ((i) = ITERATOR_FIRST; hashmap_iterate((h), &(i), (void**)&(e), (const void**) &(k)); ) #define ORDERED_HASHMAP_FOREACH_KEY(e, k, h, i) \ - for ((i) = ITERATOR_FIRST, (e) = ordered_hashmap_iterate((h), &(i), (const void**) &(k)); \ - (e); \ - (e) = ordered_hashmap_iterate((h), &(i), (const void**) &(k))) + for ((i) = ITERATOR_FIRST; ordered_hashmap_iterate((h), &(i), (void**)&(e), (const void**) &(k)); ) DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, hashmap_free); DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, hashmap_free_free); diff --git a/src/basic/macro.h b/src/basic/macro.h index cc1c9e73c0..5fa17ed208 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -248,18 +248,19 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) { REENABLE_WARNING #endif +#define assert_log(expr) ((_likely_(expr)) \ + ? (true) \ + : (log_assert_failed_return(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__), false)) + #define assert_return(expr, r) \ do { \ - if (_unlikely_(!(expr))) { \ - log_assert_failed_return(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__); \ + if (!assert_log(expr)) \ return (r); \ - } \ } while (false) #define assert_return_errno(expr, r, err) \ do { \ - if (_unlikely_(!(expr))) { \ - log_assert_failed_return(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__); \ + if (!assert_log(expr)) { \ errno = err; \ return (r); \ } \ diff --git a/src/basic/ordered-set.h b/src/basic/ordered-set.h index 766a1f2e83..6c617ab305 100644 --- a/src/basic/ordered-set.h +++ b/src/basic/ordered-set.h @@ -47,12 +47,12 @@ static inline bool ordered_set_isempty(OrderedSet *s) { return ordered_hashmap_isempty((OrderedHashmap*) s); } -static inline void *ordered_set_iterate(OrderedSet *s, Iterator *i) { - return ordered_hashmap_iterate((OrderedHashmap*) s, i, NULL); +static inline bool ordered_set_iterate(OrderedSet *s, Iterator *i, void **value) { + return ordered_hashmap_iterate((OrderedHashmap*) s, i, value, NULL); } #define ORDERED_SET_FOREACH(e, s, i) \ - for ((i) = ITERATOR_FIRST, (e) = ordered_set_iterate((s), &(i)); (e); (e) = ordered_set_iterate((s), &(i))) + for ((i) = ITERATOR_FIRST; ordered_set_iterate((s), &(i), (void**)&(e)); ) DEFINE_TRIVIAL_CLEANUP_FUNC(OrderedSet*, ordered_set_free); diff --git a/src/basic/rm-rf.c b/src/basic/rm-rf.c index bafd483be2..dbbe817684 100644 --- a/src/basic/rm-rf.c +++ b/src/basic/rm-rf.c @@ -182,7 +182,7 @@ int rm_rf(const char *path, RemoveFlags flags) { if (r >= 0) return r; - if (r != -ENOTTY && r != -EINVAL) + if (r != -ENOTTY && r != -EINVAL && r != -ENOTDIR) return r; /* Not btrfs or not a subvolume */ diff --git a/src/basic/set.h b/src/basic/set.h index 4dffecd39d..51e40d3a6c 100644 --- a/src/basic/set.h +++ b/src/basic/set.h @@ -91,7 +91,7 @@ static inline unsigned set_buckets(Set *s) { return internal_hashmap_buckets(HASHMAP_BASE(s)); } -void *set_iterate(Set *s, Iterator *i); +bool set_iterate(Set *s, Iterator *i, void **value); static inline void set_clear(Set *s) { internal_hashmap_clear(HASHMAP_BASE(s)); @@ -125,7 +125,7 @@ int set_put_strdup(Set *s, const char *p); int set_put_strdupv(Set *s, char **l); #define SET_FOREACH(e, s, i) \ - for ((i) = ITERATOR_FIRST, (e) = set_iterate((s), &(i)); (e); (e) = set_iterate((s), &(i))) + for ((i) = ITERATOR_FIRST; set_iterate((s), &(i), (void**)&(e)); ) DEFINE_TRIVIAL_CLEANUP_FUNC(Set*, set_free); DEFINE_TRIVIAL_CLEANUP_FUNC(Set*, set_free_free); diff --git a/src/basic/signal-util.c b/src/basic/signal-util.c index d24730d439..90abe8af81 100644 --- a/src/basic/signal-util.c +++ b/src/basic/signal-util.c @@ -167,7 +167,7 @@ int sigprocmask_many(int how, sigset_t *old, ...) { if (sigemptyset(&ss) < 0) return -errno; - va_start(ap, how); + va_start(ap, old); r = sigset_add_many_ap(&ss, ap); va_end(ap); diff --git a/src/basic/util.c b/src/basic/util.c index b7c70af541..e0c5069ff8 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -60,8 +60,8 @@ #include <linux/fs.h> /* When we include libgen.h because we need dirname() we immediately - * undefine basename() since libgen.h defines it as a macro to the XDG - * version which is really broken. */ + * undefine basename() since libgen.h defines it as a macro to the POSIX + * version which is really broken. We prefer GNU basename(). */ #include <libgen.h> #undef basename diff --git a/src/core/execute.c b/src/core/execute.c index 444865da86..a6ff5ac56e 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -771,7 +771,7 @@ static int setup_pam( }; pam_handle_t *handle = NULL; - sigset_t ss, old_ss; + sigset_t old_ss; int pam_code = PAM_SUCCESS; int err; char **e = NULL; @@ -868,6 +868,11 @@ static int setup_pam( /* Check if our parent process might already have * died? */ if (getppid() == parent_pid) { + sigset_t ss; + + assert_se(sigemptyset(&ss) >= 0); + assert_se(sigaddset(&ss, SIGTERM) >= 0); + for (;;) { if (sigwait(&ss, &sig) < 0) { if (errno == EINTR) diff --git a/src/libsystemd/sd-bus/bus-error.c b/src/libsystemd/sd-bus/bus-error.c index dac157be16..64a5a972ae 100644 --- a/src/libsystemd/sd-bus/bus-error.c +++ b/src/libsystemd/sd-bus/bus-error.c @@ -70,9 +70,11 @@ BUS_ERROR_MAP_ELF_REGISTER const sd_bus_error_map bus_standard_errors[] = { SD_BUS_ERROR_MAP_END }; -/* GCC maps this magically to the beginning and end of the BUS_ERROR_MAP section */ -extern const sd_bus_error_map __start_BUS_ERROR_MAP[]; -extern const sd_bus_error_map __stop_BUS_ERROR_MAP[]; +/* GCC maps this magically to the beginning and end of the BUS_ERROR_MAP section. + * Hide them; for currently unknown reasons they get exported to the shared libries + * even without being listed in the sym file. */ +extern const sd_bus_error_map __start_BUS_ERROR_MAP[] _hidden_; +extern const sd_bus_error_map __stop_BUS_ERROR_MAP[] _hidden_; /* Additional maps registered with sd_bus_error_add_map() are in this * NULL terminated array */ diff --git a/src/libsystemd/sd-bus/bus-internal.h b/src/libsystemd/sd-bus/bus-internal.h index 88c058889a..c3e20ee1bf 100644 --- a/src/libsystemd/sd-bus/bus-internal.h +++ b/src/libsystemd/sd-bus/bus-internal.h @@ -141,6 +141,7 @@ struct sd_bus_slot { void *userdata; BusSlotType type:5; bool floating:1; + bool match_added:1; char *description; LIST_FIELDS(sd_bus_slot, slots); diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c index 3aaaabf4ed..f08db2da89 100644 --- a/src/libsystemd/sd-bus/bus-kernel.c +++ b/src/libsystemd/sd-bus/bus-kernel.c @@ -29,8 +29,8 @@ #include <sys/prctl.h> /* When we include libgen.h because we need dirname() we immediately - * undefine basename() since libgen.h defines it as a macro to the XDG - * version which is really broken. */ + * undefine basename() since libgen.h defines it as a macro to the POSIX + * version which is really broken. We prefer GNU basename(). */ #include <libgen.h> #undef basename diff --git a/src/libsystemd/sd-bus/bus-match.c b/src/libsystemd/sd-bus/bus-match.c index 7c5264fad4..132b37526e 100644 --- a/src/libsystemd/sd-bus/bus-match.c +++ b/src/libsystemd/sd-bus/bus-match.c @@ -1149,3 +1149,40 @@ void bus_match_dump(struct bus_match_node *node, unsigned level) { for (c = node->child; c; c = c->next) bus_match_dump(c, level + 1); } + +enum bus_match_scope bus_match_get_scope(const struct bus_match_component *components, unsigned n_components) { + bool found_driver = false; + unsigned i; + + if (n_components <= 0) + return BUS_MATCH_GENERIC; + + assert(components); + + /* Checks whether the specified match can only match the + * pseudo-service for local messages, which we detect by + * sender, interface or path. If a match is not restricted to + * local messages, then we check if it only matches on the + * driver. */ + + for (i = 0; i < n_components; i++) { + const struct bus_match_component *c = components + i; + + if (c->type == BUS_MATCH_SENDER) { + if (streq_ptr(c->value_str, "org.freedesktop.DBus.Local")) + return BUS_MATCH_LOCAL; + + if (streq_ptr(c->value_str, "org.freedesktop.DBus")) + found_driver = true; + } + + if (c->type == BUS_MATCH_INTERFACE && streq_ptr(c->value_str, "org.freedesktop.DBus.Local")) + return BUS_MATCH_LOCAL; + + if (c->type == BUS_MATCH_PATH && streq_ptr(c->value_str, "/org/freedesktop/DBus/Local")) + return BUS_MATCH_LOCAL; + } + + return found_driver ? BUS_MATCH_DRIVER : BUS_MATCH_GENERIC; + +} diff --git a/src/libsystemd/sd-bus/bus-match.h b/src/libsystemd/sd-bus/bus-match.h index af5f65d073..56516be9fa 100644 --- a/src/libsystemd/sd-bus/bus-match.h +++ b/src/libsystemd/sd-bus/bus-match.h @@ -73,6 +73,12 @@ struct bus_match_component { char *value_str; }; +enum bus_match_scope { + BUS_MATCH_GENERIC, + BUS_MATCH_LOCAL, + BUS_MATCH_DRIVER, +}; + int bus_match_run(sd_bus *bus, struct bus_match_node *root, sd_bus_message *m); int bus_match_add(struct bus_match_node *root, struct bus_match_component *components, unsigned n_components, struct match_callback *callback); @@ -90,3 +96,5 @@ enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n int bus_match_parse(const char *match, struct bus_match_component **_components, unsigned *_n_components); void bus_match_parse_free(struct bus_match_component *components, unsigned n_components); char *bus_match_to_string(struct bus_match_component *components, unsigned n_components); + +enum bus_match_scope bus_match_get_scope(const struct bus_match_component *components, unsigned n_components); diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c index c38b2a5fa5..983e2f62cd 100644 --- a/src/libsystemd/sd-bus/bus-message.c +++ b/src/libsystemd/sd-bus/bus-message.c @@ -803,7 +803,7 @@ _public_ int sd_bus_message_new_method_errorf( const char *format, ...) { - _cleanup_free_ sd_bus_error error = SD_BUS_ERROR_NULL; + _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; va_list ap; assert_return(name, -EINVAL); @@ -822,7 +822,7 @@ _public_ int sd_bus_message_new_method_errno( int error, const sd_bus_error *p) { - _cleanup_free_ sd_bus_error berror = SD_BUS_ERROR_NULL; + _cleanup_bus_error_free_ sd_bus_error berror = SD_BUS_ERROR_NULL; if (sd_bus_error_is_set(p)) return sd_bus_message_new_method_error(call, m, p); @@ -839,7 +839,7 @@ _public_ int sd_bus_message_new_method_errnof( const char *format, ...) { - _cleanup_free_ sd_bus_error berror = SD_BUS_ERROR_NULL; + _cleanup_bus_error_free_ sd_bus_error berror = SD_BUS_ERROR_NULL; va_list ap; va_start(ap, format); diff --git a/src/libsystemd/sd-bus/bus-slot.c b/src/libsystemd/sd-bus/bus-slot.c index 8060e9882c..c452477566 100644 --- a/src/libsystemd/sd-bus/bus-slot.c +++ b/src/libsystemd/sd-bus/bus-slot.c @@ -89,7 +89,7 @@ void bus_slot_disconnect(sd_bus_slot *slot) { case BUS_MATCH_CALLBACK: - if (slot->bus->bus_client) + if (slot->match_added) bus_remove_match_internal(slot->bus, slot->match_callback.match_string, slot->match_callback.cookie); slot->bus->match_callbacks_modified = true; diff --git a/src/libsystemd/sd-bus/bus-track.c b/src/libsystemd/sd-bus/bus-track.c index ec9340f8e1..e43891be25 100644 --- a/src/libsystemd/sd-bus/bus-track.c +++ b/src/libsystemd/sd-bus/bus-track.c @@ -248,7 +248,7 @@ _public_ const char* sd_bus_track_first(sd_bus_track *track) { track->modified = false; track->iterator = ITERATOR_FIRST; - hashmap_iterate(track->names, &track->iterator, (const void**) &n); + hashmap_iterate(track->names, &track->iterator, NULL, (const void**) &n); return n; } @@ -261,7 +261,7 @@ _public_ const char* sd_bus_track_next(sd_bus_track *track) { if (track->modified) return NULL; - hashmap_iterate(track->names, &track->iterator, (const void**) &n); + hashmap_iterate(track->names, &track->iterator, NULL, (const void**) &n); return n; } diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index 2805b29839..0881b4779a 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -2952,22 +2952,35 @@ _public_ int sd_bus_add_match( s->match_callback.cookie = ++bus->match_cookie; if (bus->bus_client) { + enum bus_match_scope scope; - if (!bus->is_kernel) { - /* When this is not a kernel transport, we - * store the original match string, so that we - * can use it to remove the match again */ + scope = bus_match_get_scope(components, n_components); - s->match_callback.match_string = strdup(match); - if (!s->match_callback.match_string) { - r = -ENOMEM; - goto finish; + /* Do not install server-side matches for matches + * against the local service, interface or bus + * path. Also, when on kdbus don't install driver + * matches server side. */ + if (scope == BUS_MATCH_GENERIC || + (!bus->is_kernel && scope == BUS_MATCH_DRIVER)) { + + if (!bus->is_kernel) { + /* When this is not a kernel transport, we + * store the original match string, so that we + * can use it to remove the match again */ + + s->match_callback.match_string = strdup(match); + if (!s->match_callback.match_string) { + r = -ENOMEM; + goto finish; + } } - } - r = bus_add_match_internal(bus, s->match_callback.match_string, components, n_components, s->match_callback.cookie); - if (r < 0) - goto finish; + r = bus_add_match_internal(bus, s->match_callback.match_string, components, n_components, s->match_callback.cookie); + if (r < 0) + goto finish; + + s->match_added = true; + } } bus->match_callbacks_modified = true; diff --git a/src/libsystemd/sd-bus/test-bus-match.c b/src/libsystemd/sd-bus/test-bus-match.c index 40c67046da..a1687b1c7b 100644 --- a/src/libsystemd/sd-bus/test-bus-match.c +++ b/src/libsystemd/sd-bus/test-bus-match.c @@ -77,6 +77,15 @@ static int match_add(sd_bus_slot *slots, struct bus_match_node *root, const char return r; } +static void test_match_scope(const char *match, enum bus_match_scope scope) { + struct bus_match_component *components = NULL; + unsigned n_components = 0; + + assert_se(bus_match_parse(match, &components, &n_components) >= 0); + assert_se(bus_match_get_scope(components, n_components) == scope); + bus_match_parse_free(components, n_components); +} + int main(int argc, char *argv[]) { struct bus_match_node root = { .type = BUS_MATCH_ROOT, @@ -142,5 +151,12 @@ int main(int argc, char *argv[]) { bus_match_free(&root); + test_match_scope("interface='foobar'", BUS_MATCH_GENERIC); + test_match_scope("", BUS_MATCH_GENERIC); + test_match_scope("interface='org.freedesktop.DBus.Local'", BUS_MATCH_LOCAL); + test_match_scope("sender='org.freedesktop.DBus.Local'", BUS_MATCH_LOCAL); + test_match_scope("member='gurke',path='/org/freedesktop/DBus/Local'", BUS_MATCH_LOCAL); + test_match_scope("arg2='piep',sender='org.freedesktop.DBus',member='waldo'", BUS_MATCH_DRIVER); + return 0; } diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index 8e63b9ef56..b274f71093 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -1371,6 +1371,8 @@ _public_ int sd_device_get_usec_since_initialized(sd_device *device, uint64_t *u } _public_ const char *sd_device_get_tag_first(sd_device *device) { + void *v; + assert_return(device, NULL); (void) device_read_db(device); @@ -1378,10 +1380,13 @@ _public_ const char *sd_device_get_tag_first(sd_device *device) { device->tags_iterator_generation = device->tags_generation; device->tags_iterator = ITERATOR_FIRST; - return set_iterate(device->tags, &device->tags_iterator); + set_iterate(device->tags, &device->tags_iterator, &v); + return v; } _public_ const char *sd_device_get_tag_next(sd_device *device) { + void *v; + assert_return(device, NULL); (void) device_read_db(device); @@ -1389,10 +1394,13 @@ _public_ const char *sd_device_get_tag_next(sd_device *device) { if (device->tags_iterator_generation != device->tags_generation) return NULL; - return set_iterate(device->tags, &device->tags_iterator); + set_iterate(device->tags, &device->tags_iterator, &v); + return v; } _public_ const char *sd_device_get_devlink_first(sd_device *device) { + void *v; + assert_return(device, NULL); (void) device_read_db(device); @@ -1400,10 +1408,13 @@ _public_ const char *sd_device_get_devlink_first(sd_device *device) { device->devlinks_iterator_generation = device->devlinks_generation; device->devlinks_iterator = ITERATOR_FIRST; - return set_iterate(device->devlinks, &device->devlinks_iterator); + set_iterate(device->devlinks, &device->devlinks_iterator, &v); + return v; } _public_ const char *sd_device_get_devlink_next(sd_device *device) { + void *v; + assert_return(device, NULL); (void) device_read_db(device); @@ -1411,7 +1422,8 @@ _public_ const char *sd_device_get_devlink_next(sd_device *device) { if (device->devlinks_iterator_generation != device->devlinks_generation) return NULL; - return set_iterate(device->devlinks, &device->devlinks_iterator); + set_iterate(device->devlinks, &device->devlinks_iterator, &v); + return v; } static int device_properties_prepare(sd_device *device) { @@ -1482,7 +1494,7 @@ _public_ const char *sd_device_get_property_first(sd_device *device, const char device->properties_iterator_generation = device->properties_generation; device->properties_iterator = ITERATOR_FIRST; - value = ordered_hashmap_iterate(device->properties, &device->properties_iterator, (const void**)&key); + ordered_hashmap_iterate(device->properties, &device->properties_iterator, (void**)&value, (const void**)&key); if (_value) *_value = value; @@ -1504,7 +1516,7 @@ _public_ const char *sd_device_get_property_next(sd_device *device, const char * if (device->properties_iterator_generation != device->properties_generation) return NULL; - value = ordered_hashmap_iterate(device->properties, &device->properties_iterator, (const void**)&key); + ordered_hashmap_iterate(device->properties, &device->properties_iterator, (void**)&value, (const void**)&key); if (_value) *_value = value; @@ -1562,6 +1574,7 @@ static int device_sysattrs_read_all(sd_device *device) { } _public_ const char *sd_device_get_sysattr_first(sd_device *device) { + void *v; int r; assert_return(device, NULL); @@ -1576,16 +1589,20 @@ _public_ const char *sd_device_get_sysattr_first(sd_device *device) { device->sysattrs_iterator = ITERATOR_FIRST; - return set_iterate(device->sysattrs, &device->sysattrs_iterator); + set_iterate(device->sysattrs, &device->sysattrs_iterator, &v); + return v; } _public_ const char *sd_device_get_sysattr_next(sd_device *device) { + void *v; + assert_return(device, NULL); if (!device->sysattrs_read) return NULL; - return set_iterate(device->sysattrs, &device->sysattrs_iterator); + set_iterate(device->sysattrs, &device->sysattrs_iterator, &v); + return v; } _public_ int sd_device_has_tag(sd_device *device, const char *tag) { diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index 00880c983b..76964aa0cc 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -468,24 +468,22 @@ static bool event_pid_changed(sd_event *e) { return e->original_pid != getpid(); } -static int source_io_unregister(sd_event_source *s) { +static void source_io_unregister(sd_event_source *s) { int r; assert(s); assert(s->type == SOURCE_IO); if (event_pid_changed(s->event)) - return 0; + return; if (!s->io.registered) - return 0; + return; r = epoll_ctl(s->event->epoll_fd, EPOLL_CTL_DEL, s->io.fd, NULL); - if (r < 0) - return -errno; + assert_log(r >= 0); s->io.registered = false; - return 0; } static int source_io_register( @@ -1457,10 +1455,7 @@ _public_ int sd_event_source_set_enabled(sd_event_source *s, int m) { switch (s->type) { case SOURCE_IO: - r = source_io_unregister(s); - if (r < 0) - return r; - + source_io_unregister(s); s->enabled = m; break; diff --git a/src/libsystemd/sd-hwdb/sd-hwdb.c b/src/libsystemd/sd-hwdb/sd-hwdb.c index 2a0e00f7d2..40aa77ee5c 100644 --- a/src/libsystemd/sd-hwdb/sd-hwdb.c +++ b/src/libsystemd/sd-hwdb/sd-hwdb.c @@ -449,7 +449,8 @@ _public_ int sd_hwdb_seek(sd_hwdb *hwdb, const char *modalias) { } _public_ int sd_hwdb_enumerate(sd_hwdb *hwdb, const char **key, const char **value) { - const void *k, *v; + const void *k; + void *v; assert_return(hwdb, -EINVAL); assert_return(key, -EINVAL); @@ -458,7 +459,7 @@ _public_ int sd_hwdb_enumerate(sd_hwdb *hwdb, const char **key, const char **val if (hwdb->properties_modified) return -EAGAIN; - v = ordered_hashmap_iterate(hwdb->properties, &hwdb->properties_iterator, &k); + ordered_hashmap_iterate(hwdb->properties, &hwdb->properties_iterator, &v, &k); if (!k) return 0; diff --git a/src/login/logind-core.c b/src/login/logind-core.c index 440c32aa2c..f9e6ddfb3f 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -360,7 +360,7 @@ int manager_get_user_by_pid(Manager *m, pid_t pid, User **user) { int manager_get_idle_hint(Manager *m, dual_timestamp *t) { Session *s; bool idle_hint; - dual_timestamp ts = { 0, 0 }; + dual_timestamp ts = DUAL_TIMESTAMP_NULL; Iterator i; assert(m); diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index b272401e5b..e6f9ec7845 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -158,7 +158,7 @@ static int property_get_idle_since_hint( sd_bus_error *error) { Manager *m = userdata; - dual_timestamp t; + dual_timestamp t = DUAL_TIMESTAMP_NULL; assert(bus); assert(reply); @@ -243,6 +243,24 @@ static int property_get_scheduled_shutdown( static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_handle_action, handle_action, HandleAction); +static int property_get_docked( + sd_bus *bus, + const char *path, + const char *interface, + const char *property, + sd_bus_message *reply, + void *userdata, + sd_bus_error *error) { + + Manager *m = userdata; + + assert(bus); + assert(reply); + assert(m); + + return sd_bus_message_append(reply, "b", manager_is_docked_or_multiple_displays(m)); +} + static int method_get_session(sd_bus_message *message, void *userdata, sd_bus_error *error) { _cleanup_free_ char *p = NULL; Manager *m = userdata; @@ -2406,6 +2424,7 @@ const sd_bus_vtable manager_vtable[] = { SD_BUS_PROPERTY("PreparingForShutdown", "b", property_get_preparing, 0, 0), SD_BUS_PROPERTY("PreparingForSleep", "b", property_get_preparing, 0, 0), SD_BUS_PROPERTY("ScheduledShutdown", "(st)", property_get_scheduled_shutdown, 0, 0), + SD_BUS_PROPERTY("Docked", "b", property_get_docked, 0, 0), SD_BUS_METHOD("GetSession", "s", "o", method_get_session, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("GetSessionByPID", "u", "o", method_get_session_by_pid, SD_BUS_VTABLE_UNPRIVILEGED), diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index 68304a1610..855c85402c 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -371,7 +371,7 @@ bool manager_is_inhibited( Inhibitor *i; Iterator j; - struct dual_timestamp ts = { 0, 0 }; + struct dual_timestamp ts = DUAL_TIMESTAMP_NULL; bool inhibited = false; assert(m); diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index 11d24ce5b4..3c30eeaa95 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -599,7 +599,7 @@ bool seat_can_graphical(Seat *s) { int seat_get_idle_hint(Seat *s, dual_timestamp *t) { Session *session; bool idle_hint = true; - dual_timestamp ts = { 0, 0 }; + dual_timestamp ts = DUAL_TIMESTAMP_NULL; assert(s); diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c index debaa31a29..563153e2d9 100644 --- a/src/login/logind-session-dbus.c +++ b/src/login/logind-session-dbus.c @@ -163,7 +163,7 @@ static int property_get_idle_since_hint( sd_bus_error *error) { Session *s = userdata; - dual_timestamp t; + dual_timestamp t = DUAL_TIMESTAMP_NULL; uint64_t u; int r; diff --git a/src/login/logind-user-dbus.c b/src/login/logind-user-dbus.c index 8a710cef13..0f72d70b10 100644 --- a/src/login/logind-user-dbus.c +++ b/src/login/logind-user-dbus.c @@ -138,7 +138,7 @@ static int property_get_idle_since_hint( sd_bus_error *error) { User *u = userdata; - dual_timestamp t; + dual_timestamp t = DUAL_TIMESTAMP_NULL; uint64_t k; assert(bus); diff --git a/src/login/logind-user.c b/src/login/logind-user.c index a9cf529e12..6720899def 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -619,7 +619,7 @@ int user_finalize(User *u) { int user_get_idle_hint(User *u, dual_timestamp *t) { Session *s; bool idle_hint = true; - dual_timestamp ts = { 0, 0 }; + dual_timestamp ts = DUAL_TIMESTAMP_NULL; assert(u); diff --git a/src/machine/machine-dbus.c b/src/machine/machine-dbus.c index 0892479a9a..9f026beb13 100644 --- a/src/machine/machine-dbus.c +++ b/src/machine/machine-dbus.c @@ -24,8 +24,8 @@ #include <sys/mount.h> /* When we include libgen.h because we need dirname() we immediately - * undefine basename() since libgen.h defines it as a macro to the XDG - * version which is really broken. */ + * undefine basename() since libgen.h defines it as a macro to the POSIX + * version which is really broken. We prefer GNU basename(). */ #include <libgen.h> #undef basename diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index eea994d0b3..3c31629d1e 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -1013,6 +1013,9 @@ static int parse_argv(int argc, char *argv[]) { return -EINVAL; } + if (arg_userns && access("/proc/self/uid_map", F_OK) < 0) + return log_error_errno(EOPNOTSUPP, "--private-users= is not supported, kernel compiled without user namespace support."); + arg_retain = (arg_retain | plus | (arg_private_network ? 1ULL << CAP_NET_ADMIN : 0)) & ~minus; if (arg_boot && arg_kill_signal <= 0) diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 40bea87dfa..23fc946fbf 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -1183,7 +1183,7 @@ static int list_timers(sd_bus *bus, char **args) { for (u = unit_infos; u < unit_infos + n; u++) { _cleanup_strv_free_ char **triggered = NULL; - dual_timestamp next = {}; + dual_timestamp next = DUAL_TIMESTAMP_NULL; usec_t m, last = 0; if (!endswith(u->id, ".timer")) diff --git a/src/test/test-cgroup-mask.c b/src/test/test-cgroup-mask.c index 289dddbaac..72f874d8a9 100644 --- a/src/test/test-cgroup-mask.c +++ b/src/test/test-cgroup-mask.c @@ -77,12 +77,12 @@ static int test_cgroup_mask(void) { assert_se(unit_get_members_mask(root) == (CGROUP_CPU | CGROUP_CPUACCT | CGROUP_BLKIO | CGROUP_MEMORY)); /* Verify aggregation of sibling masks. */ - assert_se(unit_get_siblings_mask(son) == ((CGROUP_CPU | CGROUP_CPUACCT | CGROUP_MEMORY) & m->cgroup_supported)); - assert_se(unit_get_siblings_mask(daughter) == ((CGROUP_CPU | CGROUP_CPUACCT | CGROUP_MEMORY) & m->cgroup_supported)); + assert_se(unit_get_siblings_mask(son) == (CGROUP_CPU | CGROUP_CPUACCT | CGROUP_MEMORY)); + assert_se(unit_get_siblings_mask(daughter) == (CGROUP_CPU | CGROUP_CPUACCT | CGROUP_MEMORY)); assert_se(unit_get_siblings_mask(grandchild) == 0); - assert_se(unit_get_siblings_mask(parent_deep) == ((CGROUP_CPU | CGROUP_CPUACCT | CGROUP_MEMORY) & m->cgroup_supported)); - assert_se(unit_get_siblings_mask(parent) == ((CGROUP_CPU | CGROUP_CPUACCT | CGROUP_BLKIO | CGROUP_MEMORY) & m->cgroup_supported)); - assert_se(unit_get_siblings_mask(root) == ((CGROUP_CPU | CGROUP_CPUACCT | CGROUP_BLKIO | CGROUP_MEMORY) & m->cgroup_supported)); + assert_se(unit_get_siblings_mask(parent_deep) == (CGROUP_CPU | CGROUP_CPUACCT | CGROUP_MEMORY)); + assert_se(unit_get_siblings_mask(parent) == (CGROUP_CPU | CGROUP_CPUACCT | CGROUP_BLKIO | CGROUP_MEMORY)); + assert_se(unit_get_siblings_mask(root) == (CGROUP_CPU | CGROUP_CPUACCT | CGROUP_BLKIO | CGROUP_MEMORY)); /* Verify aggregation of target masks. */ assert_se(unit_get_target_mask(son) == ((CGROUP_CPU | CGROUP_CPUACCT | CGROUP_MEMORY) & m->cgroup_supported)); diff --git a/src/test/test-hashmap-plain.c b/src/test/test-hashmap-plain.c index c1a5ccf1f5..057b6c1dc1 100644 --- a/src/test/test-hashmap-plain.c +++ b/src/test/test-hashmap-plain.c @@ -465,6 +465,7 @@ static void test_hashmap_foreach_key(void) { hashmap_put(m, key, (void*) (const char*) "my dummy val"); HASHMAP_FOREACH_KEY(s, key, m, i) { + assert(s); if (!key_found[0] && streq(key, "key 1")) key_found[0] = true; else if (!key_found[1] && streq(key, "key 2")) diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 027a5c2ca8..42f757c4b7 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -496,9 +496,10 @@ static int dir_cleanup( } if (mountpoint && S_ISREG(s.st_mode)) - if ((streq(dent->d_name, ".journal") && s.st_uid == 0) || - streq(dent->d_name, "aquota.user") || - streq(dent->d_name, "aquota.group")) { + if (s.st_uid == 0 && STR_IN_SET(dent->d_name, + ".journal", + "aquota.user", + "aquota.group")) { log_debug("Skipping \"%s\".", sub_path); continue; } diff --git a/src/udev/udevd.c b/src/udev/udevd.c index d3797bb5e6..5ce11606c9 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -735,14 +735,14 @@ static void manager_exit(Manager *manager) { "STATUS=Starting shutdown..."); /* close sources of new events and discard buffered events */ - manager->ctrl = udev_ctrl_unref(manager->ctrl); manager->ctrl_event = sd_event_source_unref(manager->ctrl_event); + manager->ctrl = udev_ctrl_unref(manager->ctrl); - manager->fd_inotify = safe_close(manager->fd_inotify); manager->inotify_event = sd_event_source_unref(manager->inotify_event); + manager->fd_inotify = safe_close(manager->fd_inotify); - manager->monitor = udev_monitor_unref(manager->monitor); manager->uevent_event = sd_event_source_unref(manager->uevent_event); + manager->monitor = udev_monitor_unref(manager->monitor); /* discard queued events and kill workers */ event_queue_cleanup(manager, EVENT_QUEUED); |