]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
activate: use _cleanup_close_ attribute 26453/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 17 Feb 2023 00:49:01 +0000 (09:49 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 17 Feb 2023 00:49:51 +0000 (09:49 +0900)
src/activate/activate.c

index 6d9a4c41cc2c77880e4ddecc2a328199af17cc6e..ea141c54bdf65ee48d6ae29d63aacea645402624 100644 (file)
@@ -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();