From c767cb699114bfaaa593f90ea50e98c0c3974c3d Mon Sep 17 00:00:00 2001 From: short <> Date: Fri, 29 Aug 2003 12:43:17 +0000 Subject: [PATCH] Close all fds for the daemon for compatibility with usermount(8). --- lufsd/daemon.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/lufsd/daemon.c b/lufsd/daemon.c index 89df831..2b3d6a8 100644 --- a/lufsd/daemon.c +++ b/lufsd/daemon.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -96,6 +97,50 @@ tempsock(char *base, char *name){ return sock; } +/* From captive/src/libcaptive/sandbox/split.c/captive_sandbox_fd_closeup(): */ +#define g_return_if_fail(cond) do { if (!(cond)) { ERROR("FAIL: " #cond ); return; } } while (0) +#define g_assert(cond) do { if (!(cond)) ERROR("FAIL: " #cond ); } while (0) +static void fd_closeup(int fd_first_to_delete,int exception) +{ +DIR *dir; +int errint; +int dir_fd; +struct dirent *dirent; + + dir=opendir("/proc/self/fd/"); + g_return_if_fail(dir!=NULL); + dir_fd=dirfd(dir); + g_return_if_fail(dir_fd!=-1); + + while (errno=0,(dirent=readdir(dir))) { +long dirent_fd; +char *endptr; + + if (0 + || !strcmp(dirent->d_name,".") + || !strcmp(dirent->d_name,"..")) + continue; + dirent_fd=strtol(dirent->d_name,&endptr,10 /* base */); + g_assert(dirent_fd>=0 && (!endptr || !*endptr)); + if (dirent_fd -o [options, ...]", argv[0]); exit(1); @@ -181,7 +234,8 @@ main(int argc, char **argv){ free(nopts); - if(quiet){ + /* FIXME: 'quiet' option has no meaning now; check fd_closeup(). */ + if(1 || quiet){ int stdfd; TRACE("going dumb..."); -- 1.8.3.1