X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Frquotad%2Frquota_svc.c;h=4b3cdc2746ff19fbcd8fb7ae657820a464cef140;hp=104ba7eb8946cdb2675439f84d5896eaefd4c016;hb=87fe487c6f5abe9f40f2f036c3cf6c7f02fa0385;hpb=9ee7da8230adead93a1b42b1ac2c78e02227fe15 diff --git a/utils/rquotad/rquota_svc.c b/utils/rquotad/rquota_svc.c index 104ba7e..4b3cdc2 100644 --- a/utils/rquotad/rquota_svc.c +++ b/utils/rquotad/rquota_svc.c @@ -25,6 +25,7 @@ #endif #include +#include #include #include "rquota.h" #include @@ -37,6 +38,7 @@ #include #include #include +#include #ifdef __STDC__ #define SIG_PF void(*)(int) @@ -221,11 +223,20 @@ usage(const char *prog, int n) exit(n); } +static void +killer (int sig) +{ + (void) pmap_unset(RQUOTAPROG, RQUOTAVERS); + (void) pmap_unset(RQUOTAPROG, EXT_RQUOTAVERS); + syslog(LOG_ERR, "caught signal %d, un-registering and exiting.", sig); +} + int main(int argc, char **argv) { register SVCXPRT *transp; char c; int port = 0; + struct sigaction sa; (void) pmap_unset(RQUOTAPROG, RQUOTAVERS); (void) pmap_unset(RQUOTAPROG, EXT_RQUOTAVERS); @@ -254,13 +265,28 @@ int main(int argc, char **argv) } } + if (chdir(NFS_STATEDIR)) { + fprintf(stderr, "%s: chdir(%s) failed: %s\n", + argv [0], NFS_STATEDIR, strerror(errno)); + + exit(1); + } + /* WARNING: the following works on Linux and SysV, but not BSD! */ - signal(SIGCHLD, SIG_IGN); + sa.sa_handler = SIG_IGN; + sa.sa_flags = 0; + sigemptyset(&sa.sa_mask); + sigaction(SIGCHLD, &sa, NULL); + + sa.sa_handler = killer; + sigaction(SIGHUP, &sa, NULL); + sigaction(SIGINT, &sa, NULL); + sigaction(SIGTERM, &sa, NULL); if (port) transp = svcudp_create(makesock(port, IPPROTO_UDP)); else - transp = svcudp_create(RPC_ANYSOCK); + transp = svcudp_create(svcudp_socket (RQUOTAPROG, 1)); if (transp == NULL) { syslog(LOG_ERR, "cannot create udp service."); exit(1);