summaryrefslogtreecommitdiff
path: root/src/libsystemd
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsystemd')
-rw-r--r--src/libsystemd/sd-bus/bus-container.c6
-rw-r--r--src/libsystemd/sd-bus/bus-kernel.c26
-rw-r--r--src/libsystemd/sd-bus/bus-message.c4
-rw-r--r--src/libsystemd/sd-bus/bus-socket.c4
-rw-r--r--src/libsystemd/sd-bus/sd-bus.c4
-rw-r--r--src/libsystemd/sd-bus/sd-memfd.c4
-rw-r--r--src/libsystemd/sd-bus/test-bus-chat.c2
-rw-r--r--src/libsystemd/sd-bus/test-bus-kernel-benchmark.c2
-rw-r--r--src/libsystemd/sd-bus/test-bus-kernel.c6
-rw-r--r--src/libsystemd/sd-event/sd-event.c31
-rw-r--r--src/libsystemd/sd-login/sd-login.c8
-rw-r--r--src/libsystemd/sd-resolve/sd-resolve.c3
-rw-r--r--src/libsystemd/sd-rtnl/sd-rtnl.c4
13 files changed, 42 insertions, 62 deletions
diff --git a/src/libsystemd/sd-bus/bus-container.c b/src/libsystemd/sd-bus/bus-container.c
index d330363b6f..2cd0e1f99e 100644
--- a/src/libsystemd/sd-bus/bus-container.c
+++ b/src/libsystemd/sd-bus/bus-container.c
@@ -154,8 +154,7 @@ int bus_container_connect_kernel(sd_bus *b) {
if (child == 0) {
pid_t grandchild;
- close_nointr_nofail(pair[0]);
- pair[0] = -1;
+ pair[0] = safe_close(pair[0]);
r = namespace_enter(pidnsfd, mntnsfd, rootfd);
if (r < 0)
@@ -202,8 +201,7 @@ int bus_container_connect_kernel(sd_bus *b) {
_exit(si.si_status);
}
- close_nointr_nofail(pair[1]);
- pair[1] = -1;
+ pair[1] = safe_close(pair[1]);
r = wait_for_terminate(child, &si);
if (r < 0)
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;
}
diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c
index e32f2b827f..4fcc693543 100644
--- a/src/libsystemd/sd-bus/bus-message.c
+++ b/src/libsystemd/sd-bus/bus-message.c
@@ -70,7 +70,7 @@ static void message_free_part(sd_bus_message *m, struct bus_body_part *part) {
if (part->mapped > 0)
assert_se(munmap(part->data, part->mapped) == 0);
- close_nointr_nofail(part->memfd);
+ safe_close(part->memfd);
}
} else if (part->munmap_this)
@@ -1274,7 +1274,7 @@ static int message_push_fd(sd_bus_message *m, int fd) {
f = realloc(m->fds, sizeof(int) * (m->n_fds + 1));
if (!f) {
m->poisoned = true;
- close_nointr_nofail(copy);
+ safe_close(copy);
return -ENOMEM;
}
diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c
index 016f8a1c9f..bccf501222 100644
--- a/src/libsystemd/sd-bus/bus-socket.c
+++ b/src/libsystemd/sd-bus/bus-socket.c
@@ -750,7 +750,7 @@ int bus_socket_exec(sd_bus *b) {
assert_se(dup3(s[1], STDOUT_FILENO, 0) == STDOUT_FILENO);
if (s[1] != STDIN_FILENO && s[1] != STDOUT_FILENO)
- close_nointr_nofail(s[1]);
+ safe_close(s[1]);
fd_cloexec(STDIN_FILENO, false);
fd_cloexec(STDOUT_FILENO, false);
@@ -767,7 +767,7 @@ int bus_socket_exec(sd_bus *b) {
_exit(EXIT_FAILURE);
}
- close_nointr_nofail(s[1]);
+ safe_close(s[1]);
b->output_fd = b->input_fd = s[0];
bus_socket_setup(b);
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index ba8a8a244a..2794a4483f 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -63,10 +63,10 @@ static void bus_close_fds(sd_bus *b) {
detach_io_events(b);
if (b->input_fd >= 0)
- close_nointr_nofail(b->input_fd);
+ safe_close(b->input_fd);
if (b->output_fd >= 0 && b->output_fd != b->input_fd)
- close_nointr_nofail(b->output_fd);
+ safe_close(b->output_fd);
b->input_fd = b->output_fd = -1;
}
diff --git a/src/libsystemd/sd-bus/sd-memfd.c b/src/libsystemd/sd-bus/sd-memfd.c
index 8f9e236392..fcf3e73124 100644
--- a/src/libsystemd/sd-bus/sd-memfd.c
+++ b/src/libsystemd/sd-bus/sd-memfd.c
@@ -107,7 +107,7 @@ _public_ int sd_memfd_new(sd_memfd **m, const char *name) {
n = new0(struct sd_memfd, 1);
if (!n) {
- close_nointr_nofail(cmd->fd);
+ safe_close(cmd->fd);
return -ENOMEM;
}
@@ -144,7 +144,7 @@ _public_ void sd_memfd_free(sd_memfd *m) {
if (m->f)
fclose(m->f);
else
- close_nointr_nofail(m->fd);
+ safe_close(m->fd);
free(m);
}
diff --git a/src/libsystemd/sd-bus/test-bus-chat.c b/src/libsystemd/sd-bus/test-bus-chat.c
index 113d15ba97..1b9d98fa75 100644
--- a/src/libsystemd/sd-bus/test-bus-chat.c
+++ b/src/libsystemd/sd-bus/test-bus-chat.c
@@ -232,7 +232,7 @@ static int server(sd_bus *bus) {
if (write(fd, &x, 1) < 0) {
log_error("Failed to write to fd: %m");
- close_nointr_nofail(fd);
+ safe_close(fd);
goto fail;
}
diff --git a/src/libsystemd/sd-bus/test-bus-kernel-benchmark.c b/src/libsystemd/sd-bus/test-bus-kernel-benchmark.c
index bfeee59d2f..90257d4f3c 100644
--- a/src/libsystemd/sd-bus/test-bus-kernel-benchmark.c
+++ b/src/libsystemd/sd-bus/test-bus-kernel-benchmark.c
@@ -270,7 +270,7 @@ int main(int argc, char *argv[]) {
CPU_SET(0, &cpuset);
pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
- close_nointr_nofail(bus_ref);
+ safe_close(bus_ref);
sd_bus_unref(b);
switch (mode) {
diff --git a/src/libsystemd/sd-bus/test-bus-kernel.c b/src/libsystemd/sd-bus/test-bus-kernel.c
index 2f0f5aa00b..34d000f1c6 100644
--- a/src/libsystemd/sd-bus/test-bus-kernel.c
+++ b/src/libsystemd/sd-bus/test-bus-kernel.c
@@ -137,14 +137,12 @@ int main(int argc, char *argv[]) {
assert_se(write(pipe_fds[1], "x", 1) == 1);
- close_nointr_nofail(pipe_fds[1]);
- pipe_fds[1] = -1;
+ pipe_fds[1] = safe_close(pipe_fds[1]);
r = sd_bus_message_append(m, "h", pipe_fds[0]);
assert_se(r >= 0);
- close_nointr_nofail(pipe_fds[0]);
- pipe_fds[0] = -1;
+ pipe_fds[0] = safe_close(pipe_fds[0]);
r = sd_bus_send(b, m, NULL);
assert_se(r >= 0);
diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
index db7643347f..3bda7f31ad 100644
--- a/src/libsystemd/sd-event/sd-event.c
+++ b/src/libsystemd/sd-event/sd-event.c
@@ -331,20 +331,11 @@ static void event_free(sd_event *e) {
if (e->default_event_ptr)
*(e->default_event_ptr) = NULL;
- if (e->epoll_fd >= 0)
- close_nointr_nofail(e->epoll_fd);
-
- if (e->signal_fd >= 0)
- close_nointr_nofail(e->signal_fd);
-
- if (e->realtime_fd >= 0)
- close_nointr_nofail(e->realtime_fd);
-
- if (e->monotonic_fd >= 0)
- close_nointr_nofail(e->monotonic_fd);
-
- if (e->watchdog_fd >= 0)
- close_nointr_nofail(e->watchdog_fd);
+ safe_close(e->epoll_fd);
+ safe_close(e->signal_fd);
+ safe_close(e->realtime_fd);
+ safe_close(e->monotonic_fd);
+ safe_close(e->watchdog_fd);
prioq_free(e->pending);
prioq_free(e->prepare);
@@ -673,7 +664,7 @@ static int event_setup_timer_fd(
r = epoll_ctl(e->epoll_fd, EPOLL_CTL_ADD, fd, &ev);
if (r < 0) {
- close_nointr_nofail(fd);
+ safe_close(fd);
return -errno;
}
@@ -809,9 +800,7 @@ static int event_update_signal_fd(sd_event *e) {
r = epoll_ctl(e->epoll_fd, EPOLL_CTL_ADD, e->signal_fd, &ev);
if (r < 0) {
- close_nointr_nofail(e->signal_fd);
- e->signal_fd = -1;
-
+ e->signal_fd = safe_close(e->signal_fd);
return -errno;
}
@@ -2272,8 +2261,7 @@ _public_ int sd_event_set_watchdog(sd_event *e, int b) {
} else {
if (e->watchdog_fd >= 0) {
epoll_ctl(e->epoll_fd, EPOLL_CTL_DEL, e->watchdog_fd, NULL);
- close_nointr_nofail(e->watchdog_fd);
- e->watchdog_fd = -1;
+ e->watchdog_fd = safe_close(e->watchdog_fd);
}
}
@@ -2281,8 +2269,7 @@ _public_ int sd_event_set_watchdog(sd_event *e, int b) {
return e->watchdog;
fail:
- close_nointr_nofail(e->watchdog_fd);
- e->watchdog_fd = -1;
+ e->watchdog_fd = safe_close(e->watchdog_fd);
return r;
}
diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c
index d24b2ed1fd..39445a191b 100644
--- a/src/libsystemd/sd-login/sd-login.c
+++ b/src/libsystemd/sd-login/sd-login.c
@@ -775,7 +775,7 @@ _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) {
if (!category || streq(category, "seat")) {
k = inotify_add_watch(fd, "/run/systemd/seats/", IN_MOVED_TO|IN_DELETE);
if (k < 0) {
- close_nointr_nofail(fd);
+ safe_close(fd);
return -errno;
}
@@ -785,7 +785,7 @@ _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) {
if (!category || streq(category, "session")) {
k = inotify_add_watch(fd, "/run/systemd/sessions/", IN_MOVED_TO|IN_DELETE);
if (k < 0) {
- close_nointr_nofail(fd);
+ safe_close(fd);
return -errno;
}
@@ -795,7 +795,7 @@ _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) {
if (!category || streq(category, "uid")) {
k = inotify_add_watch(fd, "/run/systemd/users/", IN_MOVED_TO|IN_DELETE);
if (k < 0) {
- close_nointr_nofail(fd);
+ safe_close(fd);
return -errno;
}
@@ -805,7 +805,7 @@ _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) {
if (!category || streq(category, "machine")) {
k = inotify_add_watch(fd, "/run/systemd/machines/", IN_MOVED_TO|IN_DELETE);
if (k < 0) {
- close_nointr_nofail(fd);
+ safe_close(fd);
return -errno;
}
diff --git a/src/libsystemd/sd-resolve/sd-resolve.c b/src/libsystemd/sd-resolve/sd-resolve.c
index f05fe10b6a..d81012467f 100644
--- a/src/libsystemd/sd-resolve/sd-resolve.c
+++ b/src/libsystemd/sd-resolve/sd-resolve.c
@@ -593,8 +593,7 @@ _public_ sd_resolve* sd_resolve_unref(sd_resolve *resolve) {
/* Close all communication channels */
for (i = 0; i < _FD_MAX; i++)
- if (resolve->fds[i] >= 0)
- close_nointr_nofail(resolve->fds[i]);
+ safe_close(resolve->fds[i]);
for (i = 0; i < QUERIES_MAX && resolve->n_queries > 0; i++)
if (resolve->queries[i])
diff --git a/src/libsystemd/sd-rtnl/sd-rtnl.c b/src/libsystemd/sd-rtnl/sd-rtnl.c
index 1c2c8902f9..e5610b4335 100644
--- a/src/libsystemd/sd-rtnl/sd-rtnl.c
+++ b/src/libsystemd/sd-rtnl/sd-rtnl.c
@@ -132,9 +132,7 @@ sd_rtnl *sd_rtnl_unref(sd_rtnl *rtnl) {
free(f);
}
- if (rtnl->fd >= 0)
- close_nointr_nofail(rtnl->fd);
-
+ safe_close(rtnl->fd);
free(rtnl);
}