diff options
author | Mats O Jansson <maja@cvs.openbsd.org> | 1997-08-09 23:10:13 +0000 |
---|---|---|
committer | Mats O Jansson <maja@cvs.openbsd.org> | 1997-08-09 23:10:13 +0000 |
commit | 294e852c3de0388d727c104dc887e2f92429ee9e (patch) | |
tree | dab54a31d2094319524ce210ea959c3f86e80505 | |
parent | b980b74f83a52e777efcf8f5bfefc61d0e42c56c (diff) |
Increased performance in ypserv by two different actions:
1) ypdb_open_db now check error condition when something goes wrong.
Instead of always as before. by request of theo.
2) turned on -DOPTDB in Makefile. This will cause ypserv to keep databases
opened. If not defined ypserv will open and close the map for every
request. I think it was turned off before when yppush didn't work.
If a map changes yppush will signal to ypserv that the map has changed
and ypserv will reopen the map.
ypserv will start closing maps when it run out of file descriptors. Then
it will close the map least resent used.
-moj
-rw-r--r-- | usr.sbin/ypserv/ypserv/Makefile | 4 | ||||
-rw-r--r-- | usr.sbin/ypserv/ypserv/ypserv_db.c | 75 |
2 files changed, 39 insertions, 40 deletions
diff --git a/usr.sbin/ypserv/ypserv/Makefile b/usr.sbin/ypserv/ypserv/Makefile index d95e2b7dab8..4f8e70a90e9 100644 --- a/usr.sbin/ypserv/ypserv/Makefile +++ b/usr.sbin/ypserv/ypserv/Makefile @@ -1,11 +1,11 @@ -# $OpenBSD: Makefile,v 1.4 1997/03/30 20:51:17 maja Exp $ +# $OpenBSD: Makefile,v 1.5 1997/08/09 23:10:11 maja Exp $ PROG= ypserv SRCS= ypserv.c ypserv_proc.c ypserv_db.c acl.c yplog.c ypdb.c ypserv_xdr.c \ ypserv_xdr_v1.c MAN= ypserv.acl.5 securenet.5 ypserv.8 .PATH: ${.CURDIR}/../common -CFLAGS+=-DDAEMON -I${.CURDIR}/../common +CFLAGS+=-DDAEMON -DOPTDB -I${.CURDIR}/../common #CFLAGS=-DDAEMON -I${.CURDIR}/../common -DDEBUG -g .include <bsd.prog.mk> diff --git a/usr.sbin/ypserv/ypserv/ypserv_db.c b/usr.sbin/ypserv/ypserv/ypserv_db.c index 3c796d6e905..2b1ae9ed960 100644 --- a/usr.sbin/ypserv/ypserv/ypserv_db.c +++ b/usr.sbin/ypserv/ypserv/ypserv_db.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ypserv_db.c,v 1.12 1997/05/01 22:14:48 niklas Exp $ */ +/* $OpenBSD: ypserv_db.c,v 1.13 1997/08/09 23:10:12 maja Exp $ */ /* * Copyright (c) 1994 Mats O Jansson <moj@stacken.kth.se> @@ -34,7 +34,7 @@ */ #ifndef LINT -static char rcsid[] = "$OpenBSD: ypserv_db.c,v 1.12 1997/05/01 22:14:48 niklas Exp $"; +static char rcsid[] = "$OpenBSD: ypserv_db.c,v 1.13 1997/08/09 23:10:12 maja Exp $"; #endif /* @@ -62,6 +62,7 @@ static char rcsid[] = "$OpenBSD: ypserv_db.c,v 1.12 1997/05/01 22:14:48 niklas E #include <netinet/in.h> #include <arpa/inet.h> #include <syslog.h> +#include <sys/errno.h> #include "yplog.h" #include "ypdb.h" #include "ypdef.h" @@ -234,7 +235,9 @@ ypdb_open_db(domain, map, status, map_info) struct opt_domain *d = NULL; struct opt_map *m = NULL; datum k,v; - +#ifdef OPTDB + int i; +#endif /* * check for preloaded domain, map */ @@ -263,57 +266,53 @@ ypdb_open_db(domain, map, status, map_info) return(m->db); } - /* - * database not open, first check for "out of fd" and close a db if - * out... - */ - - fd = open("/", O_RDONLY); - if (fd < 0) - ypdb_close_last(); - else - close(fd); + /* Check for illegal charcaters */ if (strchr(domain, '/')) { *status = YP_NODOM; return (NULL); } - if (strchr(domain, '/')) { + if (strchr(map, '/')) { *status = YP_NOMAP; return (NULL); } + /* - * check for domain, file. + * open map */ - - snprintf(map_path, sizeof(map_path), "%s/%s", YP_DB_PATH, domain); - if (stat(map_path, &finfo) < 0 || - (finfo.st_mode & S_IFMT) != S_IFDIR) { -#ifdef DEBUG - yplog(" ypdb_open_db: no domain %s (map=%s)", domain, map); +#ifdef OPTDB + i = 0; + while (i == 0) { #endif - *status = YP_NODOM; - return(NULL); - } - snprintf(map_path, sizeof(map_path), "%s/%s/%s%s", YP_DB_PATH, - domain, map, YPDB_SUFFIX); - if (stat(map_path, &finfo) < 0) { + snprintf(map_path, sizeof(map_path), "%s/%s/%s", YP_DB_PATH, + domain, map); + db = ypdb_open(map_path, O_RDONLY, 0444); +#ifdef OPTDB + if (db == NULL) { #ifdef DEBUG - yplog(" ypdb_open_db: no map %s (domain=%s)", map, domain); + yplog(" ypdb_open_db: errno %d (%s)", + errno,sys_errlist[errno]); +#endif + if ((errno == ENFILE) || (errno == EMFILE)) { + ypdb_close_last(); + } else { + i = errno; + } + } else { + i = 4711; + } + }; #endif - *status = YP_NOMAP; - return(NULL); - } - - /* - * open map - */ - snprintf(map_path, sizeof(map_path), "%s/%s/%s", YP_DB_PATH, - domain, map); - db = ypdb_open(map_path, O_RDONLY, 0444); *status = YP_NOMAP; /* see note below */ if (db == NULL) { + if (errno == ENOENT) { +#ifdef DEBUG + yplog(" ypdb_open_db: no map %s (domain=%s)", + map, domain); +#endif + return(NULL); + } #ifdef DEBUG yplog(" ypdb_open_db: ypdb_open FAILED: map %s (domain=%s)", map, domain); |