aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Blapp <mbr@FreeBSD.org>2002-12-10 08:47:18 +0000
committerMartin Blapp <mbr@FreeBSD.org>2002-12-10 08:47:18 +0000
commitb1c56f9c37c222d58c2aca36bdcb0aff4bd270f9 (patch)
tree2b0c9c2d370ad7d46f6f5553f947935334fcf13f
parent11c419e1651c3ec017665f96bcea6d0223e5c3b9 (diff)
Notes
-rw-r--r--usr.sbin/rpcbind/rpcbind.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/usr.sbin/rpcbind/rpcbind.c b/usr.sbin/rpcbind/rpcbind.c
index af6bc0794679..b2ad5f1de65f 100644
--- a/usr.sbin/rpcbind/rpcbind.c
+++ b/usr.sbin/rpcbind/rpcbind.c
@@ -61,6 +61,7 @@ static char sccsid[] = "@(#)rpcbind.c 1.35 89/04/21 Copyr 1984 Sun Micro";
#include <netinet/in.h>
#endif
#include <arpa/inet.h>
+#include <fcntl.h>
#include <netdb.h>
#include <stdio.h>
#include <netconfig.h>
@@ -82,6 +83,8 @@ rpcblist_ptr list_rbl; /* A list of version 3/4 rpcbind services */
/* who to suid to if -s is given */
#define RUN_AS "daemon"
+#define RPCBINDDLOCK "/var/run/rpcbind.lock"
+
int runasdaemon = 0;
int insecure = 0;
int oldstyle_local = 0;
@@ -90,6 +93,7 @@ int verboselog = 0;
char **hosts = NULL;
int nhosts = 0;
int on = 1;
+int rpcbindlockfd;
#ifdef WARMSTART
/* Local Variable */
@@ -123,6 +127,14 @@ main(int argc, char *argv[])
parseargs(argc, argv);
+ /* Check that another rpcbind isn't already running. */
+ if ((rpcbindlockfd = (open(RPCBINDDLOCK,
+ O_RDONLY|O_CREAT, 0444))) == -1)
+ err(1, "%s", RPCBINDDLOCK);
+
+ if(flock(rpcbindlockfd, LOCK_EX|LOCK_NB) == -1 && errno == EWOULDBLOCK)
+ errx(1, "another rpcbind is already running. Aborting");
+
getrlimit(RLIMIT_NOFILE, &rl);
if (rl.rlim_cur < 128) {
if (rl.rlim_max <= 128)
@@ -647,6 +659,7 @@ rbllist_add(rpcprog_t prog, rpcvers_t vers, struct netconfig *nconf,
static void
terminate(int dummy __unused)
{
+ close(rpcbindlockfd);
#ifdef WARMSTART
syslog(LOG_ERR,
"rpcbind terminating on signal. Restart with \"rpcbind -w\"");