From 98db583e9b2e7aa8e095a75a6bb5f42b0d65ae79 Mon Sep 17 00:00:00 2001 From: Csaba Henk Date: Tue, 9 May 2017 19:23:18 +0200 Subject: libglusterfs: extract some functionality to functions - code in run.c to close all file descriptors, except for specified ones is extracted to int close_fds_except (int *fdv, size_t count); - tokenizing and editing a string that consists of comma-separated tokens (as done eg. in mount_param_to_flag() of contrib/fuse/mount.c is abstacted into the following API: char *token_iter_init (char *str, char sep, token_iter_t *tit); gf_boolean_t next_token (char **tokenp, token_iter_t *tit); void drop_token (char *token, token_iter_t *tit); Updates #153 Change-Id: I7cb5bda38f680f08882e2a7ef84f9142ffaa54eb Signed-off-by: Csaba Henk Reviewed-on: https://review.gluster.org/17229 Smoke: Gluster Build System NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System Reviewed-by: Amar Tumballi --- libglusterfs/src/run.c | 35 +++-------------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) (limited to 'libglusterfs/src/run.c') diff --git a/libglusterfs/src/run.c b/libglusterfs/src/run.c index ff587f7e4de..a7d98af502f 100644 --- a/libglusterfs/src/run.c +++ b/libglusterfs/src/run.c @@ -23,7 +23,6 @@ #include #include #include -#include #include "syscall.h" #ifdef RUN_STANDALONE @@ -274,37 +273,9 @@ runner_start (runner_t *runner) } if (ret != -1 ) { -#ifdef GF_LINUX_HOST_OS - DIR *d = NULL; - struct dirent *de = NULL; - struct dirent scratch[2] = {{0,},}; - char *e = NULL; - - d = sys_opendir ("/proc/self/fd"); - if (d) { - for (;;) { - errno = 0; - de = sys_readdir (d, scratch); - if (!de || errno != 0) - break; - i = strtoul (de->d_name, &e, 10); - if (*e == '\0' && i > 2 && - i != dirfd (d) && i != xpi[1]) - sys_close (i); - } - sys_closedir (d); - } else - ret = -1; -#else /* !GF_LINUX_HOST_OS */ - struct rlimit rl; - ret = getrlimit (RLIMIT_NOFILE, &rl); - GF_ASSERT (ret == 0); - - for (i = 3; i < rl.rlim_cur; i++) { - if (i != xpi[1]) - sys_close (i); - } -#endif /* !GF_LINUX_HOST_OS */ + int fdv[4] = {0, 1, 2, xpi[1]}; + + ret = close_fds_except(fdv, sizeof (fdv) / sizeof (*fdv)); } if (ret != -1) { -- cgit