X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fmountd%2Fmountd.c;h=f785ef23e6a75a45727081c5a8d217595139812b;hp=e93f0ba73121d017946697accf2cb98d6d4165be;hb=a1c827e358e11fcf27e223ed45a54f6d328e78bc;hpb=47e5725d85dc2fed09c584d5de16afbe1b434887 diff --git a/utils/mountd/mountd.c b/utils/mountd/mountd.c index e93f0ba..f785ef2 100644 --- a/utils/mountd/mountd.c +++ b/utils/mountd/mountd.c @@ -31,7 +31,7 @@ static struct nfs_fh_len *get_rootfh(struct svc_req *, dirpath *, int *, int v3) static struct option longopts[] = { { "foreground", 0, 0, 'F' }, - { "descriptors", 0, 0, 'o' }, + { "descriptors", 1, 0, 'o' }, { "debug", 1, 0, 'd' }, { "help", 0, 0, 'h' }, { "exports-file", 1, 0, 'f' }, @@ -484,6 +484,13 @@ main(int argc, char **argv) /* WARNING: the following works on Linux and SysV, but not BSD! */ sigaction(SIGCHLD, &sa, NULL); + /* Daemons should close all extra filehandles ... *before* RPC init. */ + if (!foreground) { + int fd = sysconf (_SC_OPEN_MAX); + while (--fd > 2) + (void) close(fd); + } + if (nfs_version & 0x1) rpc_init("mountd", MOUNTPROG, MOUNTVERS, mount_dispatch, port); @@ -512,17 +519,11 @@ main(int argc, char **argv) /* Now we remove ourselves from the foreground. Redirect stdin/stdout/stderr first. */ { - int fd, fdmax; - - fd = open("/dev/null", O_RDWR); + int fd = open("/dev/null", O_RDWR); (void) dup2(fd, 0); (void) dup2(fd, 1); (void) dup2(fd, 2); - - fdmax = sysconf (_SC_OPEN_MAX); - for (fd = 3; fd < fdmax; fd++) { - close (fd); - } + if (fd > 2) (void) close(fd); } setsid(); xlog_background();