summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-bus/bus-kernel.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-03-18 19:22:43 +0100
committerLennart Poettering <lennart@poettering.net>2014-03-18 19:31:34 +0100
commit03e334a1c7dc8c20c38902aa039440763acc9b17 (patch)
treebc30b522de8ef9c251bf3ff2fe2d52c92dd8b1ea /src/libsystemd/sd-bus/bus-kernel.c
parent9459781ee66eb57709c8b8701701365ba60a9f1c (diff)
util: replace close_nointr_nofail() by a more useful safe_close()
safe_close() automatically becomes a NOP when a negative fd is passed, and returns -1 unconditionally. This makes it easy to write lines like this: fd = safe_close(fd); Which will close an fd if it is open, and reset the fd variable correctly. By making use of this new scheme we can drop a > 200 lines of code that was required to test for non-negative fds or to reset the closed fd variable afterwards.
Diffstat (limited to 'src/libsystemd/sd-bus/bus-kernel.c')
-rw-r--r--src/libsystemd/sd-bus/bus-kernel.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c
index 5c955f4a07..e229baf266 100644
--- a/src/libsystemd/sd-bus/bus-kernel.c
+++ b/src/libsystemd/sd-bus/bus-kernel.c
@@ -811,7 +811,7 @@ static void close_kdbus_msg(sd_bus *bus, struct kdbus_msg *k) {
if (d->type == KDBUS_ITEM_FDS)
close_many(d->fds, (d->size - offsetof(struct kdbus_item, fds)) / sizeof(int));
else if (d->type == KDBUS_ITEM_PAYLOAD_MEMFD)
- close_nointr_nofail(d->memfd.fd);
+ safe_close(d->memfd.fd);
}
}
@@ -1165,7 +1165,7 @@ static void close_and_munmap(int fd, void *address, size_t size) {
if (size > 0)
assert_se(munmap(address, PAGE_ALIGN(size)) >= 0);
- close_nointr_nofail(fd);
+ safe_close(fd);
}
void bus_kernel_push_memfd(sd_bus *bus, int fd, void *address, size_t mapped, size_t allocated) {
@@ -1313,14 +1313,14 @@ int bus_kernel_create_bus(const char *name, bool world, char **s) {
make->flags = world ? KDBUS_MAKE_ACCESS_WORLD : 0;
if (ioctl(fd, KDBUS_CMD_BUS_MAKE, make) < 0) {
- close_nointr_nofail(fd);
+ safe_close(fd);
return -errno;
}
/* The higher 32bit of the flags field are considered
* 'incompatible flags'. Refuse them all for now. */
if (make->flags > 0xFFFFFFFFULL) {
- close_nointr_nofail(fd);
+ safe_close(fd);
return -ENOTSUP;
}
@@ -1329,7 +1329,7 @@ int bus_kernel_create_bus(const char *name, bool world, char **s) {
p = strjoin("/dev/kdbus/", n->str, "/bus", NULL);
if (!p) {
- close_nointr_nofail(fd);
+ safe_close(fd);
return -ENOMEM;
}
@@ -1424,7 +1424,7 @@ int bus_kernel_create_starter(const char *bus, const char *name, BusNamePolicy *
hello->pool_size = KDBUS_POOL_SIZE;
if (ioctl(fd, KDBUS_CMD_HELLO, hello) < 0) {
- close_nointr_nofail(fd);
+ safe_close(fd);
return -errno;
}
@@ -1432,12 +1432,12 @@ int bus_kernel_create_starter(const char *bus, const char *name, BusNamePolicy *
* 'incompatible flags'. Refuse them all for now. */
if (hello->bus_flags > 0xFFFFFFFFULL ||
hello->conn_flags > 0xFFFFFFFFULL) {
- close_nointr_nofail(fd);
+ safe_close(fd);
return -ENOTSUP;
}
if (!bloom_validate_parameters((size_t) hello->bloom.size, (unsigned) hello->bloom.n_hash)) {
- close_nointr_nofail(fd);
+ safe_close(fd);
return -ENOTSUP;
}
@@ -1469,14 +1469,14 @@ int bus_kernel_create_domain(const char *name, char **s) {
make->flags = KDBUS_MAKE_ACCESS_WORLD;
if (ioctl(fd, KDBUS_CMD_DOMAIN_MAKE, make) < 0) {
- close_nointr_nofail(fd);
+ safe_close(fd);
return -errno;
}
/* The higher 32bit of the flags field are considered
* 'incompatible flags'. Refuse them all for now. */
if (make->flags > 0xFFFFFFFFULL) {
- close_nointr_nofail(fd);
+ safe_close(fd);
return -ENOTSUP;
}
@@ -1485,7 +1485,7 @@ int bus_kernel_create_domain(const char *name, char **s) {
p = strappend("/dev/kdbus/domain/", name);
if (!p) {
- close_nointr_nofail(fd);
+ safe_close(fd);
return -ENOMEM;
}
@@ -1515,7 +1515,7 @@ int bus_kernel_create_monitor(const char *bus) {
hello->pool_size = KDBUS_POOL_SIZE;
if (ioctl(fd, KDBUS_CMD_HELLO, hello) < 0) {
- close_nointr_nofail(fd);
+ safe_close(fd);
return -errno;
}
@@ -1523,7 +1523,7 @@ int bus_kernel_create_monitor(const char *bus) {
* 'incompatible flags'. Refuse them all for now. */
if (hello->bus_flags > 0xFFFFFFFFULL ||
hello->conn_flags > 0xFFFFFFFFULL) {
- close_nointr_nofail(fd);
+ safe_close(fd);
return -ENOTSUP;
}