summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ypbind
diff options
context:
space:
mode:
authorwpaul <wpaul@FreeBSD.org>1995-05-12 16:52:58 +0000
committerwpaul <wpaul@FreeBSD.org>1995-05-12 16:52:58 +0000
commit8c0e89af78b6c3f0d502b8ea4e44085b6c336102 (patch)
tree43667e449cc766d4da3495966dd79e150db0e5be /usr.sbin/ypbind
parentfddddf561e0c02ce5d599f7e9a4e9c0b214fde13 (diff)
downloadFreeBSD-src-8c0e89af78b6c3f0d502b8ea4e44085b6c336102.zip
FreeBSD-src-8c0e89af78b6c3f0d502b8ea4e44085b6c336102.tar.gz
One for the road: create a ypbind.lock file under /var/run and try to lock
it. If we can't it means there's already a ypbind running and we should abort.
Diffstat (limited to 'usr.sbin/ypbind')
-rw-r--r--usr.sbin/ypbind/ypbind.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/usr.sbin/ypbind/ypbind.c b/usr.sbin/ypbind/ypbind.c
index b95c673..21cd202 100644
--- a/usr.sbin/ypbind/ypbind.c
+++ b/usr.sbin/ypbind/ypbind.c
@@ -28,7 +28,7 @@
*/
#ifndef LINT
-static char rcsid[] = "$Id: ypbind.c,v 1.9 1995/05/03 18:34:22 wpaul Exp $";
+static char rcsid[] = "$Id: ypbind.c,v 1.11 1995/05/11 00:16:54 wpaul Exp $";
#endif
#include <sys/param.h>
@@ -65,6 +65,10 @@ static char rcsid[] = "$Id: ypbind.c,v 1.9 1995/05/03 18:34:22 wpaul Exp $";
#define BINDINGDIR "/var/yp/binding"
#endif
+#ifndef YPBINDLOCK
+#define YPBINDLOCK "/var/run/ypbind.lock"
+#endif
+
struct _dom_binding {
struct _dom_binding *dom_pnext;
char dom_domain[YPMAXDOMAIN + 1];
@@ -115,6 +119,7 @@ int child_fds[FD_SETSIZE];
static int fd[2];
int children = 0;
int domains = 0;
+int yplockfd;
SVCXPRT *udptransp, *tcptransp;
@@ -149,7 +154,7 @@ CLIENT *clnt;
break;
if(ypdb==NULL) {
- if (domains == MAX_DOMAINS) {
+ if (domains >= MAX_DOMAINS) {
syslog(LOG_WARNING, "domain limit (%d) exceeded",
MAX_DOMAINS);
res.ypbind_respbody.ypbind_error = YPBIND_ERR_RESC;
@@ -313,6 +318,8 @@ int sig;
ypdb->dom_domain, ypdb->dom_vers);
unlink(path);
}
+ close(yplockfd);
+ unlink(YPBINDLOCK);
pmap_unset(YPBINDPROG, YPBINDVERS);
exit(0);
}
@@ -329,6 +336,17 @@ char **argv;
DIR *dird;
struct dirent *dirp;
+ /* Check that another ypbind isn't already running. */
+ if ((yplockfd = (open(YPBINDLOCK, O_RDONLY|O_CREAT, 0444))) == -1) {
+ perror(YPBINDLOCK);
+ exit(1);
+ }
+
+ if(flock(yplockfd, LOCK_EX|LOCK_NB) == -1 && errno == EWOULDBLOCK) {
+ fprintf (stderr, "Another ypbind is already running. Aborting.\n");
+ exit(1);
+ }
+
yp_get_default_domain(&domainname);
if( domainname[0] == '\0') {
fprintf(stderr, "domainname not set. Aborting.\n");
OpenPOWER on IntegriCloud