diff options
author | mbr <mbr@FreeBSD.org> | 2002-12-10 08:47:18 +0000 |
---|---|---|
committer | mbr <mbr@FreeBSD.org> | 2002-12-10 08:47:18 +0000 |
commit | 7a78c7de7613c880ae5e230de389f98ab57af25a (patch) | |
tree | 2b0c9c2d370ad7d46f6f5553f947935334fcf13f /usr.sbin/rpcbind | |
parent | 9ca0668125efcb2bdd338072641abe92dac21946 (diff) | |
download | FreeBSD-src-7a78c7de7613c880ae5e230de389f98ab57af25a.zip FreeBSD-src-7a78c7de7613c880ae5e230de389f98ab57af25a.tar.gz |
Check if rpcbind is already running and print a warning.
Fixes segfault if rpcbind is started up a second time.
Solution has been taken from mountd(8).
Reviewed by: phk
Approved by: re (rwatson)
Diffstat (limited to 'usr.sbin/rpcbind')
-rw-r--r-- | usr.sbin/rpcbind/rpcbind.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/usr.sbin/rpcbind/rpcbind.c b/usr.sbin/rpcbind/rpcbind.c index af6bc07..b2ad5f1 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\""); |