sd-bus: don't clobber return values on failure in bus_kernel_open_bus_fd()

This commit is contained in:
Lennart Poettering 2014-11-26 02:54:11 +01:00
parent fa7796e97b
commit 8aee3fc7ea

View file

@ -1514,20 +1514,29 @@ int bus_kernel_open_bus_fd(const char *bus, char **path) {
int fd;
size_t len;
assert(bus);
len = strlen("/sys/fs/kdbus/") + DECIMAL_STR_MAX(uid_t) + 1 + strlen(bus) + strlen("/bus") + 1;
if (path) {
p = malloc(len);
p = new(char, len);
if (!p)
return -ENOMEM;
*path = p;
} else
p = alloca(len);
p = newa(char, len);
sprintf(p, "/sys/fs/kdbus/" UID_FMT "-%s/bus", getuid(), bus);
fd = open(p, O_RDWR|O_NOCTTY|O_CLOEXEC);
if (fd < 0)
if (fd < 0) {
if (path)
free(p);
return -errno;
}
if (path)
*path = p;
return fd;
}