X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fnfsd%2Fnfssvc.c;h=7ecaea9e76cc26eee99037a9897794ceafbe4017;hp=025554d6fa118530c1026d9313f01d1c090f0807;hb=4c477855cd025a18ac9decaf1bc9002aaae75689;hpb=775dea70ccc7556ac613def7896b3d3c1ff85ab5 diff --git a/utils/nfsd/nfssvc.c b/utils/nfsd/nfssvc.c index 025554d..7ecaea9 100644 --- a/utils/nfsd/nfssvc.c +++ b/utils/nfsd/nfssvc.c @@ -32,27 +32,43 @@ */ char buf[128]; -static void -nfssvc_setfds(int port, unsigned int ctlbits, char *haddr) +/* + * Are there already sockets configured? If not, then it is safe to try to + * open some and pass them through. + * + * Note: If the user explicitly asked for 'udp', then we should probably check + * if that is open, and should open it if not. However we don't yet. All + * sockets have to be opened when the first daemon is started. + */ +int +nfssvc_inuse(void) { - int fd, n, on=1; - int udpfd = -1, tcpfd = -1; - struct sockaddr_in sin; + int fd, n; fd = open(NFSD_PORTS_FILE, O_RDONLY); + + /* problem opening file, assume that nothing is configured */ if (fd < 0) - return; + return 0; + n = read(fd, buf, sizeof(buf)); close(fd); - if (n != 0) + + xlog(D_GENERAL, "knfsd is currently %s", (n > 0) ? "up" : "down"); + + return (n > 0); +} + +static void +nfssvc_setfds(int port, unsigned int ctlbits, char *haddr) +{ + int fd, on=1; + int udpfd = -1, tcpfd = -1; + struct sockaddr_in sin; + + if (nfssvc_inuse()) return; - /* there are no ports currently open, so it is safe to - * try to open some and pass them through. - * Note: If the user explicitly asked for 'udp', then - * we should probably check if that is open, and should - * open it if not. However we don't yet. All sockets - * have to be opened when the first daemon is started. - */ + fd = open(NFSD_PORTS_FILE, O_WRONLY); if (fd < 0) return;