mirror of
https://github.com/systemd/systemd.git
synced 2025-05-30 05:05:57 +03:00
activate: use _cleanup_close_ attribute
This commit is contained in:
parent
a723521fd2
commit
9c9e1ceecc
@ -49,9 +49,12 @@ static int add_epoll(int epoll_fd, int fd) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int open_sockets(int *epoll_fd, bool accept) {
|
static int open_sockets(int *ret_epoll_fd, bool accept) {
|
||||||
|
_cleanup_close_ int epoll_fd = -EBADF;
|
||||||
int n, r, count = 0;
|
int n, r, count = 0;
|
||||||
|
|
||||||
|
assert(ret_epoll_fd);
|
||||||
|
|
||||||
n = sd_listen_fds(true);
|
n = sd_listen_fds(true);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
return log_error_errno(n, "Failed to read listening file descriptors from environment: %m");
|
return log_error_errno(n, "Failed to read listening file descriptors from environment: %m");
|
||||||
@ -101,8 +104,8 @@ static int open_sockets(int *epoll_fd, bool accept) {
|
|||||||
log_set_open_when_needed(false);
|
log_set_open_when_needed(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
*epoll_fd = epoll_create1(EPOLL_CLOEXEC);
|
epoll_fd = epoll_create1(EPOLL_CLOEXEC);
|
||||||
if (*epoll_fd < 0)
|
if (epoll_fd < 0)
|
||||||
return log_error_errno(errno, "Failed to create epoll object: %m");
|
return log_error_errno(errno, "Failed to create epoll object: %m");
|
||||||
|
|
||||||
for (int fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + count; fd++) {
|
for (int fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + count; fd++) {
|
||||||
@ -111,11 +114,12 @@ static int open_sockets(int *epoll_fd, bool accept) {
|
|||||||
getsockname_pretty(fd, &name);
|
getsockname_pretty(fd, &name);
|
||||||
log_info("Listening on %s as %i.", strna(name), fd);
|
log_info("Listening on %s as %i.", strna(name), fd);
|
||||||
|
|
||||||
r = add_epoll(*epoll_fd, fd);
|
r = add_epoll(epoll_fd, fd);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*ret_epoll_fd = TAKE_FD(epoll_fd);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -434,8 +438,8 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int run(int argc, char **argv) {
|
static int run(int argc, char **argv) {
|
||||||
|
_cleanup_close_ int epoll_fd = -EBADF;
|
||||||
int r, n;
|
int r, n;
|
||||||
int epoll_fd = -EBADF;
|
|
||||||
|
|
||||||
log_show_color(true);
|
log_show_color(true);
|
||||||
log_parse_environment();
|
log_parse_environment();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user