Deleted Added
full compact
46c46
< __FBSDID("$FreeBSD: head/usr.sbin/mountd/mountd.c 146187 2005-05-13 16:31:11Z ume $");
---
> __FBSDID("$FreeBSD: head/usr.sbin/mountd/mountd.c 149433 2005-08-24 19:17:06Z pjd $");
75a76
> #include <libutil.h>
90,93d90
< #ifndef MOUNTDLOCK
< #define MOUNTDLOCK "/var/run/mountd.lock"
< #endif
<
231c228
< int mountdlockfd;
---
> struct pidfh *pfh = NULL;
268a266
> pid_t otherpid;
280,281c278,283
< 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");
> }
283,284d284
< if(flock(mountdlockfd, LOCK_EX|LOCK_NB) == -1 && errno == EWOULDBLOCK)
< errx(1, "another mountd is already running. Aborting");
349,354c349,351
< { FILE *pidfile = fopen(_PATH_MOUNTDPID, "w");
< if (pidfile != NULL) {
< fprintf(pidfile, "%d\n", getpid());
< fclose(pidfile);
< }
< }
---
>
> pidfile_write(pfh);
>
2534,2535c2531
< close(mountdlockfd);
< unlink(MOUNTDLOCK);
---
> pidfile_remove(pfh);