diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-02-17 09:49:01 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-02-17 09:49:51 +0900 |
commit | 9c9e1ceecc10e9894e0105e4c526b532a0059a0c (patch) | |
tree | 4653cbf2609535d552b93463ce33c452730588e6 /src/activate | |
parent | a723521fd26d40ce90357e4e9b8131f1e1656ab5 (diff) | |
download | systemd-9c9e1ceecc10e9894e0105e4c526b532a0059a0c.tar.gz |
activate: use _cleanup_close_ attribute
Diffstat (limited to 'src/activate')
-rw-r--r-- | src/activate/activate.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/activate/activate.c b/src/activate/activate.c index 6d9a4c41cc..ea141c54bd 100644 --- a/src/activate/activate.c +++ b/src/activate/activate.c @@ -49,9 +49,12 @@ static int add_epoll(int epoll_fd, int fd) { 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; + assert(ret_epoll_fd); + n = sd_listen_fds(true); if (n < 0) 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); } - *epoll_fd = epoll_create1(EPOLL_CLOEXEC); - if (*epoll_fd < 0) + epoll_fd = epoll_create1(EPOLL_CLOEXEC); + if (epoll_fd < 0) 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++) { @@ -111,11 +114,12 @@ static int open_sockets(int *epoll_fd, bool accept) { getsockname_pretty(fd, &name); 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) return r; } + *ret_epoll_fd = TAKE_FD(epoll_fd); return count; } @@ -434,8 +438,8 @@ static int parse_argv(int argc, char *argv[]) { } static int run(int argc, char **argv) { + _cleanup_close_ int epoll_fd = -EBADF; int r, n; - int epoll_fd = -EBADF; log_show_color(true); log_parse_environment(); |