X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fstatd%2Fstatd.c;h=cf30fe46d0a17c3da481346b85f3955dd1165d9f;hp=93c394f160401fa896dfece800cb2ea09d022b64;hb=a75c6d57688b6f4435bac41ffac7c3b8eab1aab1;hpb=430052cab3c8044ef6d1be7b5a5ded13c45d0c40 diff --git a/utils/statd/statd.c b/utils/statd/statd.c index 93c394f..cf30fe4 100644 --- a/utils/statd/statd.c +++ b/utils/statd/statd.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "statd.h" #include "version.h" @@ -209,6 +210,7 @@ int main (int argc, char **argv) int pid; int arg; int port = 0, out_port = 0; + struct rlimit rlim; int pipefds[2] = { -1, -1}; char status; @@ -320,6 +322,21 @@ int main (int argc, char **argv) daemon mode. */ } + if (getrlimit (RLIMIT_NOFILE, &rlim) != 0) + fprintf(stderr, "%s: getrlimit (RLIMIT_NOFILE) failed: %s\n", + argv [0], strerror(errno)); + else { + /* glibc sunrpc code dies if getdtablesize > FD_SETSIZE */ + if (rlim.rlim_cur > FD_SETSIZE) { + rlim.rlim_cur = FD_SETSIZE; + + if (setrlimit (RLIMIT_NOFILE, &rlim) != 0) { + fprintf(stderr, "%s: setrlimit (RLIMIT_NOFILE) failed: %s\n", + argv [0], strerror(errno)); + } + } + } + #ifdef SIMULATIONS if (argc > 1) /* LH - I _really_ need to update simulator... */ @@ -382,6 +399,11 @@ int main (int argc, char **argv) signal (SIGTERM, killer); /* WARNING: the following works on Linux and SysV, but not BSD! */ signal(SIGCHLD, SIG_IGN); + /* + * Ignore SIGPIPE to avoid statd dying when peers close their + * TCP connection while we're trying to reply to them. + */ + signal(SIGPIPE, SIG_IGN); /* initialize out_port */ statd_get_socket(out_port);