mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-11-25 18:12:57 +01:00
Use pidfile(3) in mountd(8). There is no need to use /var/run/mountd.lock
anymore.
This commit is contained in:
parent
f670195163
commit
a032b226c8
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=149433
@ -6,4 +6,7 @@ MAN= exports.5 netgroup.5 mountd.8
|
||||
|
||||
WARNS?= 2
|
||||
|
||||
DPADD= ${LIBUTIL}
|
||||
LDADD= -lutil
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user