X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fstatd%2Fstatd.c;h=4fc135abee256c58484947734f3e8a415aa85787;hp=e758707887963aca31ddfae79785e39e36bcadc3;hb=e7a90e99053a6c0575efcb19f3ddda3abd5f59cd;hpb=012d7fd50654b1623e63c447905187929e559cff diff --git a/utils/statd/statd.c b/utils/statd/statd.c index e758707..4fc135a 100644 --- a/utils/statd/statd.c +++ b/utils/statd/statd.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -41,6 +42,7 @@ static struct option longopts[] = { "version", 0, 0, 'v' }, { "outgoing-port", 1, 0, 'o' }, { "port", 1, 0, 'p' }, + { "name", 1, 0, 'n' }, { NULL, 0, 0, 0 } }; @@ -125,6 +127,7 @@ usage() fprintf(stderr," -p, --port Port to listen on\n"); fprintf(stderr," -o, --outgoing-port Port for outgoing connections\n"); fprintf(stderr," -V, -v, --version Display version information and exit.\n"); + fprintf(stderr," -n, --name Specify a local hostname.\n"); } /* @@ -154,8 +157,11 @@ int main (int argc, char **argv) version_p = VERSION; } + /* Set hostname */ + MY_NAME = NULL; + /* Process command line switches */ - while ((arg = getopt_long(argc, argv, "h?vVFdp:o:", longopts, NULL)) != EOF) { + while ((arg = getopt_long(argc, argv, "h?vVFdn:p:o:", longopts, NULL)) != EOF) { switch (arg) { case 'V': /* Version */ case 'v': @@ -185,6 +191,9 @@ int main (int argc, char **argv) exit(1); } break; + case 'n': /* Specify local hostname */ + MY_NAME = xstrdup(optarg); + break; case '?': /* heeeeeelllllllpppp? heh */ case 'h': usage(); @@ -216,7 +225,7 @@ int main (int argc, char **argv) #endif if (!(run_mode & MODE_NODAEMON)) { - int filedes; + int filedes, fdmax, tempfd; if ((pid = fork ()) < 0) { perror ("Could not fork"); @@ -229,7 +238,12 @@ int main (int argc, char **argv) setsid (); chdir (DIR_BASE); - for (filedes = 0; filedes < sysconf (_SC_OPEN_MAX); filedes++) { + tempfd = open("/dev/null", O_RDWR); + close(0); dup2(tempfd, 0); + close(1); dup2(tempfd, 1); + close(2); dup2(tempfd, 2); + fdmax = sysconf (_SC_OPEN_MAX); + for (filedes = 3; filedes < fdmax; filedes++) { close (filedes); } }