commit:     b794dc4c4fc421713d82c75d8a14be9b85ba2482
Author:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
AuthorDate: Sun Mar  9 05:16:54 2025 +0000
Commit:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
CommitDate: Sun Mar  9 18:22:21 2025 +0000
URL:        https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=b794dc4c

libsbutil: move sb_close_all_fds into libsandbox

Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>

 libsandbox/trace.c   | 25 ++++++++++++++++++++++++-
 libsbutil/local.mk   |  1 -
 libsbutil/sb_close.c | 35 -----------------------------------
 libsbutil/sbutil.h   |  1 -
 4 files changed, 24 insertions(+), 38 deletions(-)

diff --git a/libsandbox/trace.c b/libsandbox/trace.c
index 40d83cd..b9a9470 100644
--- a/libsandbox/trace.c
+++ b/libsandbox/trace.c
@@ -524,6 +524,29 @@ static void trace_loop(void)
        } while (1);
 }
 
+static void close_all_fds(void)
+{
+       DIR *dirp;
+       struct dirent *de;
+       int dfd, fd;
+       const char *fd_dir = sb_get_fd_dir();
+
+       dirp = opendir(fd_dir);
+       if (!dirp)
+               sb_ebort("could not process %s\n", fd_dir);
+       dfd = dirfd(dirp);
+
+       while ((de = readdir(dirp)) != NULL) {
+               if (de->d_name[0] == '.')
+                       continue;
+               fd = atoi(de->d_name);
+               if (fd != dfd)
+                       close(fd);
+       }
+
+       closedir(dirp);
+}
+
 void trace_main(void)
 {
        struct sigaction old_sa, sa = { .sa_handler = SIG_DFL, };
@@ -545,7 +568,7 @@ void trace_main(void)
                                PTRACE_O_TRACEEXIT |
                                PTRACE_O_TRACESYSGOOD
                        ));
-               sb_close_all_fds();
+               close_all_fds();
                trace_loop();
                sb_ebort("ISE: child should have quit, as should we\n");
        }

diff --git a/libsbutil/local.mk b/libsbutil/local.mk
index 12d6526..b1980de 100644
--- a/libsbutil/local.mk
+++ b/libsbutil/local.mk
@@ -25,7 +25,6 @@ noinst_LIBRARIES += %D%/libsbutil.a
        %D%/sb_stat.c                             \
        %D%/sb_write.c                            \
        %D%/sb_write_fd.c                         \
-       %D%/sb_close.c                            \
        %D%/sb_printf.c                           \
        %D%/sb_proc.c                             \
        %D%/sb_memory.c                           \

diff --git a/libsbutil/sb_close.c b/libsbutil/sb_close.c
deleted file mode 100644
index 5f7def7..0000000
--- a/libsbutil/sb_close.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * sb_close.c
- *
- * IO functions.
- *
- * Copyright 1999-2012 Gentoo Foundation
- * Licensed under the GPL-2
- */
-
-#include "headers.h"
-#include "sbutil.h"
-
-/* Quickly close all the open fds (good for daemonization) */
-void sb_close_all_fds(void)
-{
-       DIR *dirp;
-       struct dirent *de;
-       int dfd, fd;
-       const char *fd_dir = sb_get_fd_dir();
-
-       dirp = opendir(fd_dir);
-       if (!dirp)
-               sb_ebort("could not process %s\n", fd_dir);
-       dfd = dirfd(dirp);
-
-       while ((de = readdir(dirp)) != NULL) {
-               if (de->d_name[0] == '.')
-                       continue;
-               fd = atoi(de->d_name);
-               if (fd != dfd)
-                       close(fd);
-       }
-
-       closedir(dirp);
-}

diff --git a/libsbutil/sbutil.h b/libsbutil/sbutil.h
index d092868..5d74c93 100644
--- a/libsbutil/sbutil.h
+++ b/libsbutil/sbutil.h
@@ -107,7 +107,6 @@ extern const char sbio_fallback_path[];
 int sb_open(const char *path, int flags, mode_t mode);
 size_t sb_read(int fd, void *buf, size_t count);
 size_t sb_write(int fd, const void *buf, size_t count);
-void sb_close_all_fds(void);
 int sb_copy_file_to_fd(const char *file, int ofd);
 int sb_exists(int dirfd, const char *pathname, int flags);
 int sb_fstat(int fd, mode_t *mode, int64_t *size);

Reply via email to