mirror of
https://github.com/systemd/systemd.git
synced 2024-12-25 01:34:28 +03:00
sd-bus: use automatic cleanup more
This commit is contained in:
parent
0639f1354c
commit
01c4dcaffb
@ -232,33 +232,30 @@ static void bus_free(sd_bus *b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_public_ int sd_bus_new(sd_bus **ret) {
|
_public_ int sd_bus_new(sd_bus **ret) {
|
||||||
sd_bus *r;
|
_cleanup_free_ sd_bus *b = NULL;
|
||||||
|
|
||||||
assert_return(ret, -EINVAL);
|
assert_return(ret, -EINVAL);
|
||||||
|
|
||||||
r = new0(sd_bus, 1);
|
b = new0(sd_bus, 1);
|
||||||
if (!r)
|
if (!b)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
r->n_ref = REFCNT_INIT;
|
b->n_ref = REFCNT_INIT;
|
||||||
r->input_fd = r->output_fd = -1;
|
b->input_fd = b->output_fd = -1;
|
||||||
r->inotify_fd = -1;
|
b->inotify_fd = -1;
|
||||||
r->message_version = 1;
|
b->message_version = 1;
|
||||||
r->creds_mask |= SD_BUS_CREDS_WELL_KNOWN_NAMES|SD_BUS_CREDS_UNIQUE_NAME;
|
b->creds_mask |= SD_BUS_CREDS_WELL_KNOWN_NAMES|SD_BUS_CREDS_UNIQUE_NAME;
|
||||||
r->accept_fd = true;
|
b->accept_fd = true;
|
||||||
r->original_pid = getpid_cached();
|
b->original_pid = getpid_cached();
|
||||||
r->n_groups = (size_t) -1;
|
b->n_groups = (size_t) -1;
|
||||||
|
|
||||||
assert_se(pthread_mutex_init(&r->memfd_cache_mutex, NULL) == 0);
|
assert_se(pthread_mutex_init(&b->memfd_cache_mutex, NULL) == 0);
|
||||||
|
|
||||||
/* We guarantee that wqueue always has space for at least one
|
/* We guarantee that wqueue always has space for at least one entry */
|
||||||
* entry */
|
if (!GREEDY_REALLOC(b->wqueue, b->wqueue_allocated, 1))
|
||||||
if (!GREEDY_REALLOC(r->wqueue, r->wqueue_allocated, 1)) {
|
|
||||||
free(r);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
|
||||||
|
|
||||||
*ret = r;
|
*ret = TAKE_PTR(b);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,7 +289,8 @@ _public_ int sd_bus_set_fd(sd_bus *bus, int input_fd, int output_fd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_public_ int sd_bus_set_exec(sd_bus *bus, const char *path, char *const argv[]) {
|
_public_ int sd_bus_set_exec(sd_bus *bus, const char *path, char *const argv[]) {
|
||||||
char *p, **a;
|
_cleanup_free_ char *p = NULL;
|
||||||
|
char **a;
|
||||||
|
|
||||||
assert_return(bus, -EINVAL);
|
assert_return(bus, -EINVAL);
|
||||||
assert_return(bus = bus_resolve(bus), -ENOPKG);
|
assert_return(bus = bus_resolve(bus), -ENOPKG);
|
||||||
@ -306,10 +304,8 @@ _public_ int sd_bus_set_exec(sd_bus *bus, const char *path, char *const argv[])
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
a = strv_copy(argv);
|
a = strv_copy(argv);
|
||||||
if (!a) {
|
if (!a)
|
||||||
free(p);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
|
||||||
|
|
||||||
free_and_replace(bus->exec_path, p);
|
free_and_replace(bus->exec_path, p);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user