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.
This commit is contained in:
parent
217f71d80c
commit
e9988ceda3
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=166439
@ -7,4 +7,7 @@ WARNS?= 6
|
|||||||
MAN= mount.8
|
MAN= mount.8
|
||||||
# We do NOT install the getmntopts.3 man page.
|
# We do NOT install the getmntopts.3 man page.
|
||||||
|
|
||||||
|
DPADD= ${LIBUTIL}
|
||||||
|
LDADD= -lutil
|
||||||
|
|
||||||
.include <bsd.prog.mk>
|
.include <bsd.prog.mk>
|
||||||
|
@ -58,6 +58,7 @@ static const char rcsid[] =
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <libutil.h>
|
||||||
|
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
#include "mntopts.h"
|
#include "mntopts.h"
|
||||||
@ -204,14 +205,33 @@ specified_ro(const char *arg)
|
|||||||
return (ret);
|
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
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
const char *mntfromname, **vfslist, *vfstype;
|
const char *mntfromname, **vfslist, *vfstype;
|
||||||
struct fstab *fs;
|
struct fstab *fs;
|
||||||
struct statfs *mntbuf;
|
struct statfs *mntbuf;
|
||||||
FILE *mountdfp;
|
|
||||||
pid_t pid;
|
|
||||||
int all, ch, i, init_flags, late, mntsize, rval, have_fstab, ro;
|
int all, ch, i, init_flags, late, mntsize, rval, have_fstab, ro;
|
||||||
char *cp, *ep, *options;
|
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
|
* 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 &&
|
if (rval == 0 && getuid() == 0)
|
||||||
(mountdfp = fopen(_PATH_MOUNTDPID, "r")) != NULL) {
|
restart_mountd();
|
||||||
if (fscanf(mountdfp, "%d", &pid) == 1 &&
|
|
||||||
pid > 0 && kill(pid, SIGHUP) == -1 && errno != ESRCH)
|
|
||||||
err(1, "signal mountd");
|
|
||||||
(void)fclose(mountdfp);
|
|
||||||
}
|
|
||||||
|
|
||||||
exit(rval);
|
exit(rval);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user