summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2005-08-24 19:17:06 +0000
committerpjd <pjd@FreeBSD.org>2005-08-24 19:17:06 +0000
commita834e2610e36c1ba370a2d6b444f1916e46cf280 (patch)
tree2f552d0c07836fe5a797fa5b55e9c58cdedf2de3 /usr.sbin
parentda18f6ae6cb11507a5f6ae3b411b195917f3858b (diff)
downloadFreeBSD-src-a834e2610e36c1ba370a2d6b444f1916e46cf280.zip
FreeBSD-src-a834e2610e36c1ba370a2d6b444f1916e46cf280.tar.gz
Use pidfile(3) in mountd(8). There is no need to use /var/run/mountd.lock
anymore.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/mountd/Makefile3
-rw-r--r--usr.sbin/mountd/mountd.c30
2 files changed, 16 insertions, 17 deletions
diff --git a/usr.sbin/mountd/Makefile b/usr.sbin/mountd/Makefile
index d015160..5091485 100644
--- a/usr.sbin/mountd/Makefile
+++ b/usr.sbin/mountd/Makefile
@@ -6,4 +6,7 @@ MAN= exports.5 netgroup.5 mountd.8
WARNS?= 2
+DPADD= ${LIBUTIL}
+LDADD= -lutil
+
.include <bsd.prog.mk>
diff --git a/usr.sbin/mountd/mountd.c b/usr.sbin/mountd/mountd.c
index bd57299..e557b59 100644
--- a/usr.sbin/mountd/mountd.c
+++ b/usr.sbin/mountd/mountd.c
@@ -73,6 +73,7 @@ __FBSDID("$FreeBSD$");
#include <err.h>
#include <errno.h>
#include <grp.h>
+#include <libutil.h>
#include <limits.h>
#include <netdb.h>
#include <pwd.h>
@@ -87,10 +88,6 @@ __FBSDID("$FreeBSD$");
#include <stdarg.h>
#endif
-#ifndef MOUNTDLOCK
-#define MOUNTDLOCK "/var/run/mountd.lock"
-#endif
-
/*
* Structures for keeping the mount list and export list
*/
@@ -228,7 +225,7 @@ int got_sighup = 0;
int opt_flags;
static int have_v6 = 1;
-int mountdlockfd;
+struct pidfh *pfh = NULL;
/* Bits for opt_flags above */
#define OP_MAPROOT 0x01
#define OP_MAPALL 0x02
@@ -266,6 +263,7 @@ main(argc, argv)
char *endptr;
SVCXPRT *udptransp, *tcptransp, *udp6transp, *tcp6transp;
struct netconfig *udpconf, *tcpconf, *udp6conf, *tcp6conf;
+ pid_t otherpid;
int udpsock, tcpsock, udp6sock, tcp6sock;
int xcreated = 0, s;
int maxrec = RPC_MAXDATASIZE;
@@ -277,11 +275,13 @@ main(argc, argv)
udp6sock = tcp6sock = 0;
/* Check that another mountd isn't already running. */
- if ((mountdlockfd = (open(MOUNTDLOCK, O_RDONLY|O_CREAT, 0444))) == -1)
- err(1, "%s", MOUNTDLOCK);
+ pfh = pidfile_open(_PATH_MOUNTDPID, 0644, &otherpid);
+ if (pfh == NULL) {
+ if (errno == EEXIST)
+ errx(1, "mountd already running, pid: %d.", otherpid);
+ warn("cannot open or create pidfile");
+ }
- if(flock(mountdlockfd, LOCK_EX|LOCK_NB) == -1 && errno == EWOULDBLOCK)
- errx(1, "another mountd is already running. Aborting");
s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
if (s < 0)
have_v6 = 0;
@@ -346,12 +346,9 @@ main(argc, argv)
}
signal(SIGHUP, huphandler);
signal(SIGTERM, terminate);
- { FILE *pidfile = fopen(_PATH_MOUNTDPID, "w");
- if (pidfile != NULL) {
- fprintf(pidfile, "%d\n", getpid());
- fclose(pidfile);
- }
- }
+
+ pidfile_write(pfh);
+
rpcb_unset(RPCPROG_MNT, RPCMNT_VER1, NULL);
rpcb_unset(RPCPROG_MNT, RPCMNT_VER3, NULL);
udpsock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
@@ -2531,8 +2528,7 @@ huphandler(int sig)
void terminate(sig)
int sig;
{
- close(mountdlockfd);
- unlink(MOUNTDLOCK);
+ pidfile_remove(pfh);
rpcb_unset(RPCPROG_MNT, RPCMNT_VER1, NULL);
rpcb_unset(RPCPROG_MNT, RPCMNT_VER3, NULL);
exit (0);
OpenPOWER on IntegriCloud