summaryrefslogtreecommitdiffstats
path: root/sbin/mount
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2007-02-02 23:58:10 +0000
committerpjd <pjd@FreeBSD.org>2007-02-02 23:58:10 +0000
commitdc15ae189680b2124fae98087bdac446047f0f6d (patch)
treea98cd63beae75f8d995eac365b06b1b441489ec5 /sbin/mount
parenta6c57fe6a9788e1153c281f016d466b04726484b (diff)
downloadFreeBSD-src-dc15ae189680b2124fae98087bdac446047f0f6d.zip
FreeBSD-src-dc15ae189680b2124fae98087bdac446047f0f6d.tar.gz
Use pidfile(3) API to restart mountd(8) on success mount.
This why we won't kill random process if there is a stale PID in /var/run/mountd.pid.
Diffstat (limited to 'sbin/mount')
-rw-r--r--sbin/mount/Makefile3
-rw-r--r--sbin/mount/mount.c35
2 files changed, 28 insertions, 10 deletions
diff --git a/sbin/mount/Makefile b/sbin/mount/Makefile
index 49005fb..4186f00 100644
--- a/sbin/mount/Makefile
+++ b/sbin/mount/Makefile
@@ -7,4 +7,7 @@ WARNS?= 6
MAN= mount.8
# We do NOT install the getmntopts.3 man page.
+DPADD= ${LIBUTIL}
+LDADD= -lutil
+
.include <bsd.prog.mk>
diff --git a/sbin/mount/mount.c b/sbin/mount/mount.c
index b5ce18e..df8d3ff 100644
--- a/sbin/mount/mount.c
+++ b/sbin/mount/mount.c
@@ -58,6 +58,7 @@ static const char rcsid[] =
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <libutil.h>
#include "extern.h"
#include "mntopts.h"
@@ -204,14 +205,33 @@ specified_ro(const char *arg)
return (ret);
}
+static void
+restart_mountd(void)
+{
+ struct pidfh *pfh;
+ pid_t mountdpid;
+
+ pfh = pidfile_open(_PATH_MOUNTDPID, 0600, &mountdpid);
+ if (pfh != NULL) {
+ /* Mountd is not running. */
+ pidfile_remove(pfh);
+ return;
+ }
+ if (errno != EEXIST) {
+ /* Cannot open pidfile for some reason. */
+ return;
+ }
+ /* We have mountd(8) PID in mountdpid varible, let's signal it. */
+ if (kill(mountdpid, SIGHUP) == -1)
+ err(1, "signal mountd");
+}
+
int
main(int argc, char *argv[])
{
const char *mntfromname, **vfslist, *vfstype;
struct fstab *fs;
struct statfs *mntbuf;
- FILE *mountdfp;
- pid_t pid;
int all, ch, i, init_flags, late, mntsize, rval, have_fstab, ro;
char *cp, *ep, *options;
@@ -411,15 +431,10 @@ main(int argc, char *argv[])
/*
* If the mount was successfully, and done by root, tell mountd the
- * good news. Pid checks are probably unnecessary, but don't hurt.
+ * good news.
*/
- if (rval == 0 && getuid() == 0 &&
- (mountdfp = fopen(_PATH_MOUNTDPID, "r")) != NULL) {
- if (fscanf(mountdfp, "%d", &pid) == 1 &&
- pid > 0 && kill(pid, SIGHUP) == -1 && errno != ESRCH)
- err(1, "signal mountd");
- (void)fclose(mountdfp);
- }
+ if (rval == 0 && getuid() == 0)
+ restart_mountd();
exit(rval);
}
OpenPOWER on IntegriCloud