diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c index a63937e1ce..3ee22c9638 100644 --- a/src/libsystemd/sd-bus/bus-control.c +++ b/src/libsystemd/sd-bus/bus-control.c @@ -713,7 +713,7 @@ _public_ int sd_bus_get_name_creds( } r = bus_creds_add_more(c, mask, pid, 0); - if (r < 0) + if (r < 0 && r != -ESRCH) /* Return the error, but ignore ESRCH which just means the process is already gone */ return r; } @@ -788,7 +788,7 @@ _public_ int sd_bus_get_owner_creds(sd_bus *bus, uint64_t mask, sd_bus_creds **r } r = bus_creds_add_more(c, mask, pid, 0); - if (r < 0) + if (r < 0 && r != -ESRCH) /* If the process vanished, then don't complain, just return what we got */ return r; *ret = TAKE_PTR(c); diff --git a/src/libsystemd/sd-bus/bus-convenience.c b/src/libsystemd/sd-bus/bus-convenience.c index 4bf228b436..ea2fd8935b 100644 --- a/src/libsystemd/sd-bus/bus-convenience.c +++ b/src/libsystemd/sd-bus/bus-convenience.c @@ -603,8 +603,9 @@ _public_ int sd_bus_set_property( return r; } -_public_ int sd_bus_query_sender_creds(sd_bus_message *call, uint64_t mask, sd_bus_creds **creds) { +_public_ int sd_bus_query_sender_creds(sd_bus_message *call, uint64_t mask, sd_bus_creds **ret) { sd_bus_creds *c; + int r; assert_return(call, -EINVAL); assert_return(call->sealed, -EPERM); @@ -618,7 +619,7 @@ _public_ int sd_bus_query_sender_creds(sd_bus_message *call, uint64_t mask, sd_b /* All data we need? */ if (c && (mask & ~c->mask) == 0) { - *creds = sd_bus_creds_ref(c); + *ret = sd_bus_creds_ref(c); return 0; } @@ -629,15 +630,22 @@ _public_ int sd_bus_query_sender_creds(sd_bus_message *call, uint64_t mask, sd_b if (call->sender) /* There's a sender, but the creds are missing. */ - return sd_bus_get_name_creds(call->bus, call->sender, mask, creds); + return sd_bus_get_name_creds(call->bus, call->sender, mask, ret); else /* There's no sender. For direct connections * the credentials of the AF_UNIX peer matter, * which may be queried via sd_bus_get_owner_creds(). */ - return sd_bus_get_owner_creds(call->bus, mask, creds); + return sd_bus_get_owner_creds(call->bus, mask, ret); } - return bus_creds_extend_by_pid(c, mask, creds); + r = bus_creds_extend_by_pid(c, mask, ret); + if (r == -ESRCH) { + /* Process doesn't exist anymore? propagate the few things we have */ + *ret = sd_bus_creds_ref(c); + return 0; + } + + return r; } _public_ int sd_bus_query_sender_privilege(sd_bus_message *call, int capability) {