diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/bitmap.c | 16 | ||||
-rw-r--r-- | src/bus-proxyd/driver.c | 37 | ||||
-rw-r--r-- | src/test/test-bitmap.c | 20 |
3 files changed, 59 insertions, 14 deletions
diff --git a/src/basic/bitmap.c b/src/basic/bitmap.c index bf9d8d4d7c..7ea3357031 100644 --- a/src/basic/bitmap.c +++ b/src/basic/bitmap.c @@ -145,7 +145,10 @@ bool bitmap_isclear(Bitmap *b) { void bitmap_clear(Bitmap *b) { assert(b); + free(b->bitmaps); + b->bitmaps = NULL; b->n_bitmaps = 0; + b->bitmaps_allocated = 0; } bool bitmap_iterate(Bitmap *b, Iterator *i, unsigned *n) { @@ -184,6 +187,9 @@ bool bitmap_iterate(Bitmap *b, Iterator *i, unsigned *n) { } bool bitmap_equal(Bitmap *a, Bitmap *b) { + size_t common_n_bitmaps; + Bitmap *c; + unsigned i; if (!a ^ !b) return false; @@ -191,8 +197,14 @@ bool bitmap_equal(Bitmap *a, Bitmap *b) { if (!a) return true; - if (a->n_bitmaps != b->n_bitmaps) + common_n_bitmaps = MIN(a->n_bitmaps, b->n_bitmaps); + if (memcmp(a->bitmaps, b->bitmaps, sizeof(uint64_t) * common_n_bitmaps) != 0) return false; - return memcmp(a->bitmaps, b->bitmaps, sizeof(uint64_t) * a->n_bitmaps) == 0; + c = a->n_bitmaps > b->n_bitmaps ? a : b; + for (i = common_n_bitmaps; i < c->n_bitmaps; i++) + if (c->bitmaps[i] != 0) + return false; + + return true; } diff --git a/src/bus-proxyd/driver.c b/src/bus-proxyd/driver.c index 133454ddbf..951f515808 100644 --- a/src/bus-proxyd/driver.c +++ b/src/bus-proxyd/driver.c @@ -610,6 +610,7 @@ int bus_proxy_process_driver(Proxy *p, sd_bus *a, sd_bus *b, sd_bus_message *m, _cleanup_bus_message_unref_ sd_bus_message *msg = NULL; ProxyActivation *activation; const char *name; + uint64_t cookie; uint32_t flags; if (!sd_bus_message_has_signature(m, "su")) @@ -631,19 +632,33 @@ int bus_proxy_process_driver(Proxy *p, sd_bus *a, sd_bus *b, sd_bus_message *m, if (p->n_activations >= PROXY_ACTIVATIONS_MAX) return synthetic_reply_method_errno(m, -EMFILE, NULL); + r = sd_bus_message_get_cookie(m, &cookie); + if (r < 0) + return synthetic_reply_method_errno(m, r, NULL); + + r = sd_bus_message_new_method_call(a, + &msg, + name, + "/", + "org.freedesktop.DBus.Peer", + "Ping"); + if (r < 0) + return synthetic_reply_method_errno(m, r, NULL); + + r = bus_message_seal(msg, cookie, BUS_DEFAULT_TIMEOUT); + if (r < 0) + return synthetic_reply_method_errno(m, r, NULL); + activation = new0(ProxyActivation, 1); if (!activation) return synthetic_reply_method_errno(m, -ENOMEM, NULL); - r = sd_bus_call_method_async(a, - &activation->slot, - name, - "/", - "org.freedesktop.DBus.Peer", - "Ping", - driver_activation, - activation, - NULL); + r = sd_bus_call_async(a, + &activation->slot, + msg, + driver_activation, + activation, + 0); if (r < 0) { free(activation); return synthetic_reply_method_errno(m, r, NULL); @@ -692,8 +707,8 @@ int bus_proxy_process_driver(Proxy *p, sd_bus *a, sd_bus *b, sd_bus_message *m, if (r < 0) return synthetic_reply_method_errno(m, r, NULL); - if (!args) - return synthetic_reply_method_errno(m, -EINVAL, NULL); + if (strv_isempty(args)) /* nothing to do? */ + return synthetic_reply_method_return(m, NULL); r = sd_bus_message_new_method_call( a, diff --git a/src/test/test-bitmap.c b/src/test/test-bitmap.c index 96deeded7e..ff22117745 100644 --- a/src/test/test-bitmap.c +++ b/src/test/test-bitmap.c @@ -20,7 +20,7 @@ #include "bitmap.h" int main(int argc, const char *argv[]) { - _cleanup_bitmap_free_ Bitmap *b = NULL; + _cleanup_bitmap_free_ Bitmap *b = NULL, *b2 = NULL; Iterator it; unsigned n = (unsigned) -1, i = 0; @@ -101,5 +101,23 @@ int main(int argc, const char *argv[]) { assert_se(bitmap_set(b, (unsigned) -1) == -ERANGE); + bitmap_free(b); + b = NULL; + assert_se(bitmap_ensure_allocated(&b) == 0); + assert_se(bitmap_ensure_allocated(&b2) == 0); + + assert_se(bitmap_equal(b, b2)); + assert_se(bitmap_set(b, 0) == 0); + bitmap_unset(b, 0); + assert_se(bitmap_equal(b, b2)); + + assert_se(bitmap_set(b, 1) == 0); + bitmap_clear(b); + assert_se(bitmap_equal(b, b2)); + + assert_se(bitmap_set(b, 0) == 0); + assert_se(bitmap_set(b2, 0) == 0); + assert_se(bitmap_equal(b, b2)); + return 0; } |