Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Aug 2005 16:13:58 GMT
From:      soc-bushman <soc-bushman@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 82772 for review
Message-ID:  <200508291613.j7TGDwGK071969@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=82772

Change 82772 by soc-bushman@soc-bushman_stinger on 2005/08/29 16:13:34

	changes to conform style(9) guidelines

Affected files ...

.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/Makefile#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/cached.8#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/cached.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/cached.conf#4 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/cached.conf.5#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/config.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/config.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/debug.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/debug.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/log.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/log.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/mp_rs_query.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/mp_rs_query.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/mp_ws_query.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/mp_ws_query.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/parser.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/parser.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/protocol.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/protocol.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/query.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/query.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/singletons.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/singletons.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/cachelib/Makefile#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/cachelib/cachelib.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/cachelib/hashfuncs.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/cachelib/hashfuncs.h#3 delete
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/cachelib/hashtable.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/cachelib/hashtable.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/cachelib/include/cachelib.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/cachelib/policies.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/cachelib/policies.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/test/Makefile#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/test/debug.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/test/debug.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/test/test.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/test/test.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/src/include/nscache.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/src/include/nscachedcli.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/src/include/nsswitch.h#8 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/gen/getgrent.c#5 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/gen/getpwent.c#6 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getaddrinfo.c#4 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/gethostnamadr.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getprotoent.c#6 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getservent.c#16 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/name6.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/nscache.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/nscachedcli.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/nsdispatch.c#6 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/nsparser.y#3 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/rpc/getrpcent.c#6 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/Makefile#4 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/host_marshal.c#4 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nscache.c#5 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nsdispatch.c#4 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nsdispatch_test.c#5 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nsswitch.h#3 edit

Differences ...

==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/Makefile#3 (text+ko) ====

@@ -9,10 +9,11 @@
 MANDIR?=${PREFIX}/man/man
 
 WARNS?=2
-SRCS=cached.c debug.c log.c config.c query.c mp_ws_query.c mp_rs_query.c singletons.c protocol.c parser.c
-CFLAGS+= -I${.CURDIR}/../ ${PTHREAD_LIBS} -DCONFIG_PATH="\"${PREFIX}/etc/cached.conf\""
-DPADD+=${LIBM}
-LDADD+=${.CURDIR}/../cachelib/libcachelib.a -lm -lc_r
+SRCS=cached.c debug.c log.c config.c query.c mp_ws_query.c mp_rs_query.c\
+	singletons.c protocol.c parser.c
+CFLAGS+= -I${.CURDIR}/../ -DCONFIG_PATH="\"${PREFIX}/etc/cached.conf\""
+DPADD+=${LIBM} ${LIBPTHREAD}
+LDADD+=${.CURDIR}/../cachelib/libcachelib.a -lm -lpthread
 
 FILESGROUPS=STARTUP
 
@@ -23,6 +24,7 @@
 REINPLACE_CMD?=/usr/bin/sed -i.bak -e
 
 afterinstall:
-		${REINPLACE_CMD} 's!#cached_bindir#!${BINDIR}!g' ${PREFIX}/etc/rc.d/cached.sh
+	${REINPLACE_CMD} 's!#cached_bindir#!${BINDIR}!g'\
+		${PREFIX}/etc/rc.d/cached.sh
 
 .include <bsd.prog.mk>

==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/cached.8#3 (text+ko) ====

@@ -1,54 +1,103 @@
-.\" Copyright (C) 2003-2004, Michael Bushkov <bushman@rsu.ru>
-.TH "cached" "8" "0.1" "Michael Bushkov" "FreeBSD System's Manual"
-.SH "NAME"
-.LP 
-\fBcached\fR \- the caching daemon
-.SH "SYNTAX"
-.LP 
-\fBcached\fR [\fB\-n\fR] [\fB-t\fR] [\fB-s\fR]
-.SH "DESCRIPTION"
-.LP 
-.br
-.LP
-\fBcached\fR - is the system caching daemon. It can cache almost all types of data and is basically intended to be used with \fBnsswitch\fR subsystem. \fBcached\fR supports 2 types of caching:
-.br
-.LP
-.TP
-\fBCommon caching\fR
-Each cached element is the the key+value pair. This type of caching supports policies, which are applied, when maximum number of cached elements is exceeded. 3 policies are available: \fBFIFO\fR (first in - first out), \fBLRU\fR (least recently used) and \fBLFU\fR (least frequently used). This type of caching is used with get**byname-like functions.
-.br
-.LP
-.TP
-\fBMultipart caching
-Each cached element is the part of the elements sequence. This type of caching is intended to be used with get**ent-like functions.
-.br
-.LP
-You can use sample configuration file \fIcached.conf.sample\fP in your examples folder to start working with \fBcached\fR.
-.SH "OPTIONS"
-.LP 
-.TP 
-\fB\-n\fR
-Do not daemonize. \fBcached\fR doesn't fork and doesn't disconnect itself from the terminal.
-.TP 
-\fB\-t\fR
-Trace mode. All trace messages would be written to the stdout. This mode is usually used with \fB-n\fR and \fB-s\fR flags for debugging purposes.
-.TP
-\fB\-s\fR
-Single-threaded mode. Forces using only one thread for all processing purposes (it overrides the \fBthreads\fR parameter in the \fIcached.conf\fP file).
-.SH "FILES"
-.LP 
-\fIcached.conf\fP 
-.SH "SEE ALSO"
-.na
-.nf
-cached.conf(5)
-nsswitch.conf(5),
-nsdispatch(3)
-.SH "AUTHORS"
-.LP 
-Michael Bushkov <bushman@rsu.ru>
-.SH "BUGS"
-.LP 
-To report bugs or suggestions on what you would like to see in the \fBcached\fR please mail me <bushman@rsu.ru>.
-.br
-You can also find latest news and source code snapshots at: \fIhttp://wikitest.freebsd.org/moin.cgi/MichaelBushkov\fP
+.\" Copyright (c) 2005 Michael Bushkov <bushman@rsu.ru>
+.\" All rights reserved.
+.\" 
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\" 
+
+.Dd August 29, 2005
+.Dt CACHED 8
+.Os
+.Sh NAME
+.Nm cached
+.Nd caching server daemon
+.Sh SYNOPSIS
+.Nm
+.Op Fl nst
+.Sh DESCRIPTION
+.Nm
+- is the system caching daemon. 
+It can cache almost all types of data and is basically intended to be used 
+with 
+.Pa nsswitch
+subsystem. 
+.Nm
+supports 2 types of caching:
+.Bl -tag -width Pair
+.It Sy Type
+.Sy Description
+.It Common caching
+Each cached element is the the key+value pair. 
+This type of caching supports policies, which are applied, when maximum 
+number of cached elements is exceeded. 
+3 policies are available: 
+.Pa FIFO
+(first in - first out), 
+.Pa LRU
+(least recently used) and
+.Pa LFU 
+(least frequently used). 
+This type of caching is used with 
+.Fn getXXXbyname 
+- like functions.
+.It Multipart caching
+Each cached element is the part of the elements sequence. 
+This type of caching is intended to be used with 
+.Fn getXXXent 
+- like functions.
+.El
+.Pp
+.Nm
+recognizes the following runtime options:
+.Bl -tag -width indent
+.It Fl n
+Do not daemonize. 
+.Nm
+doesn't fork and doesn't disconnect itself from the terminal.
+.It Fl s
+Single-threaded mode. 
+Forces using only one thread for all processing purposes (it overrides 
+the 
+.Pa threads
+parameter in the 
+.Xr cached.conf 5 
+file).
+.It Fl t 
+Trace mode. 
+All trace messages would be written to the stdout. 
+This mode is usually used with 
+.Fl n 
+and 
+.Fl s
+flags for debugging purposes.
+.El
+.Sh FILES
+.Xr cached.conf 5
+.Sh SEE ALSO
+.Xr cached.conf 5
+.Xr nsswitch.conf 5
+.Xr nsdispatch 3
+.Sh "AUTHORS"
+Michael Bushkov 
+.Aq bushman@rsu.ru
+.Sh "BUGS"
+To report bugs or suggestions please mail me 
+.Aq bushman@rsu.ru.

==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/cached.c#3 (text+ko) ====

@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2004 Michael Bushkov <bushman@rsu.ru>
+ * Copyright (c) 2005 Michael Bushkov <bushman@rsu.ru>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -24,20 +24,22 @@
  * SUCH DAMAGE.
  *
  */
- 
-#include <cachelib/include/cachelib.h>
+  
+#include <sys/types.h>
 #include <sys/event.h>
 #include <sys/socket.h>
 #include <sys/time.h>
-#include <sys/types.h>
 #include <sys/un.h>
 #include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <pthread.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+
+#include <cachelib/include/cachelib.h>
 #include "config.h"
 #include "debug.h"
 #include "log.h"
@@ -61,34 +63,42 @@
 static pthread_rwlock_t	s_time_lock = PTHREAD_RWLOCK_INITIALIZER;
 static pthread_t		s_time_thread;
 
+static void accept_connection(struct kevent *, struct runtime_env *, 
+	struct configuration *);
+static void destroy_global_timer(void);
+static void destroy_cache_(cache);
+static void destroy_runtime_env(struct runtime_env *);
+static cache init_cache_(struct configuration *);
+static int init_global_timer(void);
+static struct runtime_env *init_runtime_env(struct configuration *);
+static void *get_time_thread(void *);
+static void print_version_info(void);
+static void processing_loop(cache, struct runtime_env *, 
+	struct configuration *);
+static void process_socket_event(struct kevent *, struct runtime_env *,
+	struct configuration *);
+static void process_timer_event(struct kevent *, struct runtime_env *,
+	struct configuration *);
+static void *processing_thread(void *);
+static int write_pid_file(const char *);
+static void usage(void);
+
+void get_time_func(struct timeval *);
+	
 static void *
 get_time_thread(void *args)
 {
-	TRACE_MSG("=> get_time_thread");
 	for (;;) {
 		sleep(1);
 		pthread_rwlock_wrlock(&s_time_lock);
 		++s_time.tv_sec;
 		pthread_rwlock_unlock(&s_time_lock);		
 	}
-	TRACE_MSG("<= get_time_thread");
 	return (NULL);
 }
 
-void
-get_time_func(struct timeval *time)
-{
-	TRACE_IN(get_time_func);
-	pthread_rwlock_rdlock(&s_time_lock);
-	memcpy(time, &s_time, sizeof(struct timeval));
-	TRACE_INT(s_time.tv_sec);
-	TRACE_INT(s_time.tv_usec);
-	pthread_rwlock_unlock(&s_time_lock);
-	TRACE_OUT(get_time_func);
-}
-
 static int
-init_global_timer()
+init_global_timer(void)
 {
 	int res;
 	
@@ -100,7 +110,7 @@
 }
 
 static void
-destroy_global_timer()
+destroy_global_timer(void)
 {
 	TRACE_IN(destroy_global_timer);
 	pthread_rwlock_destroy(&s_time_lock);
@@ -136,38 +146,27 @@
 }
 
 static void
-print_usage_info(void)
+usage(void)
 {
-	TRACE_IN(print_usage_info);
-	printf("usage: cached [-n] [-t] [-s]\n"
-		"\t-n: no-daemon mode - cached won't fork and daemonize itself\n"
-		"\t-t: trace mode - all trace messages would be written to the stdout\n"
-		"\t-s: forced single-threaded mode\n"
-		"\n\ttypical usage for debug purposes: cached -n -t -s\n");
-	TRACE_OUT(print_usage_info);
+	fprintf(stderr,"usage: cached [-nst]\n");	
+	exit(1);
 }
 
 static cache
 init_cache_(struct configuration *config)
 {
-	struct cache_params					params;
-	cache	retval;
+	struct cache_params params;
+	cache retval;
 		
-	struct configuration_entry	*config_entry;
+	struct configuration_entry *config_entry;
 	size_t	size, i;
 	
 	TRACE_IN(init_cache_);
 	
 	memset(&params, 0, sizeof(struct cache_params));		
 	params.get_time_func = get_time_func;
-//	params.num_levels = 2;	
 	retval = init_cache(&params);
 	
-/*	memset(&entry_params, 0, sizeof(struct common_cache_entry_params));
-	entry_params.entry_type = CEL_COMMON;
-	entry_params.entry_name = "users";
-	entry_params.policy = CPT_FIFO;
-	register_cache_entry(retval, (struct cache_entry_params *)&entry_params);*/
 	size = configuration_get_entries_size(config);
 	for (i = 0; i < size; ++i) {
 		config_entry = configuration_get_entry(config, i);
@@ -189,13 +188,13 @@
 static struct runtime_env *
 init_runtime_env(struct configuration *config)
 {
-	int	serv_addr_len;
-	struct sockaddr_un	serv_addr;		
+	int serv_addr_len;
+	struct sockaddr_un serv_addr;		
 	
 	struct kevent eventlist;
 	struct timespec timeout;
 	
-	struct runtime_env	*retval;
+	struct runtime_env *retval;
 		
 	TRACE_IN(init_runtime_env);
 	retval = (struct runtime_env *)malloc(sizeof(struct runtime_env));
@@ -209,10 +208,13 @@
 
 	memset(&serv_addr, 0, sizeof(struct sockaddr_un));
 	serv_addr.sun_family = PF_LOCAL;
-	strncpy(serv_addr.sun_path, config->socket_path, sizeof(serv_addr.sun_path));
-	serv_addr_len = sizeof(serv_addr.sun_family) + strlen(serv_addr.sun_path) + 1;
+	strncpy(serv_addr.sun_path, config->socket_path, 
+		sizeof(serv_addr.sun_path));
+	serv_addr_len = sizeof(serv_addr.sun_family) + 
+		strlen(serv_addr.sun_path) + 1;
 	
-	if (bind(retval->sockfd, (struct sockaddr *)&serv_addr, serv_addr_len) == -1) {
+	if (bind(retval->sockfd, (struct sockaddr *)&serv_addr, 
+		serv_addr_len) == -1) {
 		TRACE_INT(errno);
 		close(retval->sockfd);
 		free(retval);
@@ -227,7 +229,8 @@
 	retval->queue = kqueue();
 	assert(retval->queue != -1);
 	
-	EV_SET(&eventlist, retval->sockfd, EVFILT_READ, EV_ADD | EV_CLEAR, 0, 0, 0);
+	EV_SET(&eventlist, retval->sockfd, EVFILT_READ, EV_ADD | EV_CLEAR,
+		0, 0, 0);
 	memset(&timeout, 0, sizeof(struct timespec));
 	kevent(retval->queue, &eventlist, 1, NULL, 0, &timeout);		
 	
@@ -315,51 +318,41 @@
 			return;
 		}
 	}
-	TRACE_POINT();
-	qstate = (struct query_state *)event_data->udata;		
-/*	if ((qstate->process_func == NULL) || (res != 0)) {
-		TRACE_INT(res);
-		destroy_query_state(qstate);
-		//shutdown(event_data->ident, SHUT_RDWR);
-		close(event_data->ident);
-		TRACE_POINT();
-		TRACE_OUT(process_socket_event);
-		return;
-	}		*/
+	qstate = (struct query_state *)event_data->udata;	
 	
-	TRACE_POINT();	
-	if ( ((qstate->use_alternate_io == 0) && (qstate->kevent_watermark <= event_data->data)) ||
-		 ((qstate->use_alternate_io != 0) && (qstate->io_buffer_watermark <= event_data->data)) )	{
+	if (((qstate->use_alternate_io == 0) && 
+		(qstate->kevent_watermark <= event_data->data)) ||
+		((qstate->use_alternate_io != 0) && 
+		(qstate->io_buffer_watermark <= event_data->data))) {
 		if (qstate->use_alternate_io != 0) {
 			TRACE_INT(qstate->use_alternate_io);
 			switch (qstate->io_buffer_filter) {
 			case EVFILT_READ:
-				io_res = query_socket_read(qstate, qstate->io_buffer_p, qstate->io_buffer_watermark);
+				io_res = query_socket_read(qstate, 
+					qstate->io_buffer_p, 
+					qstate->io_buffer_watermark);
 				if (io_res < 0) {
 					qstate->use_alternate_io = 0;
 					qstate->process_func = NULL;
 				} else {
 					qstate->io_buffer_p += io_res;
 					TRACE_INT(qstate->kevent_watermark);
-					TRACE_INT(qstate->io_buffer + qstate->io_buffer_size - qstate->io_buffer_p);
+					TRACE_INT(qstate->io_buffer + 
+				    		qstate->io_buffer_size - 
+						qstate->io_buffer_p);
 					TRACE_INT(io_res);
 					TRACE_INT(event_data->data);
 					TRACE_INT(qstate->io_buffer_size);
-					if (qstate->io_buffer_p == qstate->io_buffer + qstate->io_buffer_size) {
+					if (qstate->io_buffer_p == 
+					    	qstate->io_buffer + 
+						qstate->io_buffer_size) {
 						qstate->io_buffer_p = qstate->io_buffer;
 						qstate->use_alternate_io = 0;
 					}
 				}				
 			break;
-/*			case EVFILT_WRITE:
-				TRACE_POINT();
-				io_res = query_socket_write(qstate, qstate->io_buffer_p, qstate->io_buffer_watermark);
-				if (io_res < 0) {
-					qstate->use_alternate_io = 0;
-					qstate->process_func = NULL;
-				} else
-					qstate->io_buffer_p += io_res;
-			break;*/
+			default:
+			break;
 			}
 		}
 		
@@ -375,9 +368,11 @@
 		}
 		
 		TRACE_INT(qstate->use_alternate_io);
-		if ((qstate->use_alternate_io != 0) && (qstate->io_buffer_filter == EVFILT_WRITE)) {
+		if ((qstate->use_alternate_io != 0) && 
+			(qstate->io_buffer_filter == EVFILT_WRITE)) {
 			TRACE_POINT();
-			io_res = query_socket_write(qstate, qstate->io_buffer_p, qstate->io_buffer_watermark);
+			io_res = query_socket_write(qstate, qstate->io_buffer_p, 
+				qstate->io_buffer_watermark);
 			if (io_res < 0) {
 				qstate->use_alternate_io = 0;
 				qstate->process_func = NULL;
@@ -393,9 +388,10 @@
 	TRACE_INT(event_data->data);
 	TRACE_INT(qstate->kevent_watermark);
 	TRACE_PTR(qstate->process_func);
-	if (((qstate->process_func == NULL) && (qstate->use_alternate_io == 0)) || (eof_res != 0) || (res != 0)) {
+	if (((qstate->process_func == NULL) && 
+	    	(qstate->use_alternate_io == 0)) || 
+		(eof_res != 0) || (res != 0)) {
 		destroy_query_state(qstate);
-		//shutdown(event_data->ident, SHUT_RDWR);
 		close(event_data->ident);
 		TRACE_POINT();
 		TRACE_OUT(process_socket_event);
@@ -408,9 +404,11 @@
 	if (query_timeout.tv_sec > qstate->timeout.tv_sec)
 		query_timeout.tv_sec = 0;
 	else
-		query_timeout.tv_sec = qstate->timeout.tv_sec - query_timeout.tv_sec;		
+		query_timeout.tv_sec = qstate->timeout.tv_sec - 
+			query_timeout.tv_sec;		
 	
-	if ((qstate->use_alternate_io != 0) && (qstate->io_buffer_p == qstate->io_buffer + qstate->io_buffer_size))
+	if ((qstate->use_alternate_io != 0) && (qstate->io_buffer_p == 
+		qstate->io_buffer + qstate->io_buffer_size))
 		qstate->use_alternate_io = 0;					
 		
 	if (qstate->use_alternate_io == 0) {
@@ -418,7 +416,8 @@
 			if (qstate->io_buffer != NULL)
 				free(qstate->io_buffer);
 			
-			qstate->io_buffer = (char *)malloc(qstate->kevent_watermark);
+			qstate->io_buffer = (char *)malloc(
+				qstate->kevent_watermark);
 			assert(qstate->io_buffer != NULL);
 			memset(qstate->io_buffer, 0, qstate->kevent_watermark);
 			
@@ -433,29 +432,36 @@
 				qstate->use_alternate_io = 1;
 			
 			qstate->io_buffer_watermark = MAX_SOCKET_IO_SIZE;
-			EV_SET(&eventlist[0], event_data->ident, qstate->kevent_filter,
-				EV_ADD | EV_ONESHOT, NOTE_LOWAT, MAX_SOCKET_IO_SIZE, qstate);
+			EV_SET(&eventlist[0], event_data->ident, 
+				qstate->kevent_filter, EV_ADD | EV_ONESHOT, 
+				NOTE_LOWAT, MAX_SOCKET_IO_SIZE, qstate);
 		} else {
-			EV_SET(&eventlist[0], event_data->ident, qstate->kevent_filter,
-				EV_ADD | EV_ONESHOT, NOTE_LOWAT, qstate->kevent_watermark, qstate);		
+			EV_SET(&eventlist[0], event_data->ident, 
+		    		qstate->kevent_filter, EV_ADD | EV_ONESHOT, 
+		    		NOTE_LOWAT, qstate->kevent_watermark, qstate);		
 		}
 	} else {
 		TRACE_POINT();
-		if (qstate->io_buffer + qstate->io_buffer_size - qstate->io_buffer_p < MAX_SOCKET_IO_SIZE) {
-			qstate->io_buffer_watermark = qstate->io_buffer + qstate->io_buffer_size - qstate->io_buffer_p;
-			EV_SET(&eventlist[0], event_data->ident, qstate->io_buffer_filter,
+		if (qstate->io_buffer + qstate->io_buffer_size - 
+		    	qstate->io_buffer_p < 
+			MAX_SOCKET_IO_SIZE) {
+			qstate->io_buffer_watermark = qstate->io_buffer + 
+				qstate->io_buffer_size - qstate->io_buffer_p;
+			EV_SET(&eventlist[0], event_data->ident, 
+			    	qstate->io_buffer_filter,
 				EV_ADD | EV_ONESHOT, NOTE_LOWAT, 
 				qstate->io_buffer_watermark,
 				qstate);
 		} else {
 			TRACE_POINT();
 			qstate->io_buffer_watermark = MAX_SOCKET_IO_SIZE;
-			EV_SET(&eventlist[0], event_data->ident, qstate->io_buffer_filter,
-				EV_ADD | EV_ONESHOT, NOTE_LOWAT, MAX_SOCKET_IO_SIZE, qstate);
+			EV_SET(&eventlist[0], event_data->ident, 
+		    		qstate->io_buffer_filter, EV_ADD | EV_ONESHOT, 
+		    		NOTE_LOWAT, MAX_SOCKET_IO_SIZE, qstate);
 		}
 	}
-	EV_SET(&eventlist[1], event_data->ident, EVFILT_TIMER, EV_ADD | EV_ONESHOT,
-		0, query_timeout.tv_sec * 1000, qstate);	
+	EV_SET(&eventlist[1], event_data->ident, EVFILT_TIMER, 
+		EV_ADD | EV_ONESHOT, 0, query_timeout.tv_sec * 1000, qstate);	
 	kevent(env->queue, eventlist, 2, NULL, 0, &kevent_timeout);
 		
 	TRACE_OUT(process_socket_event);
@@ -470,7 +476,6 @@
 	TRACE_IN(process_timer_event);
 	qstate = (struct query_state *)event_data->udata;
 	destroy_query_state(qstate);
-	//shutdown(event_data->ident, SHUT_RDWR);
 	close(event_data->ident);	
 	TRACE_OUT(process_timer_event);	
 }
@@ -489,7 +494,8 @@
 	memset(&eventlist, 0, sizeof(struct kevent) * eventlist_size);
 	
 	for (;;) {
-		nevents = kevent(env->queue, NULL, 0, eventlist, eventlist_size, NULL);
+		nevents = kevent(env->queue, NULL, 0, eventlist, 
+	    		eventlist_size, NULL);
 		
 		if (nevents == 1) {
 			struct kevent *event_data;
@@ -501,10 +507,12 @@
 				switch (event_data->filter) {
 				case EVFILT_READ:
 				case EVFILT_WRITE:
-					process_socket_event(event_data, env, config);
+					process_socket_event(event_data, 
+						env, config);
 					break;
 				case EVFILT_TIMER:
-					process_timer_event(event_data, env, config);
+					process_timer_event(event_data,
+						env, config);
 					break;
 				default:
 					break;
@@ -525,13 +533,22 @@
 	
 	TRACE_MSG("=> processing_thread");
 	args = (struct processing_thread_args *)data;
-	processing_loop(args->the_cache, args->the_runtime_env, args->the_configuration);
+	processing_loop(args->the_cache, args->the_runtime_env, 
+		args->the_configuration);
 	free(args);
 	TRACE_MSG("<= processing_thread");
 	
 	return (NULL);
 }
 
+void
+get_time_func(struct timeval *time)
+{
+	pthread_rwlock_rdlock(&s_time_lock);
+	memcpy(time, &s_time, sizeof(struct timeval));
+	pthread_rwlock_unlock(&s_time_lock);
+}
+
 int 
 main(int argc, char *argv[])
 {
@@ -557,18 +574,21 @@
 	trace_mode_enabled = 0;
 	force_single_threaded = 0;
 	do_not_daemonize = 0;
-	if (argc > 1) {
-		for (i = 1; i < argc; ++i) {
-			if (strcmp(argv[i], "-t") == 0)
-				trace_mode_enabled = 1;
-			else if (strcmp(argv[i], "-s") == 0)
-				force_single_threaded = 1;
-			else if (strcmp(argv[i], "-n") == 0)
-				do_not_daemonize = 1;
-			else {
-				print_usage_info();
-				return (-1);
-			}
+	while ((res = getopt(argc, argv, "nst")) != -1) {
+		switch (res) {
+		case 'n':
+			do_not_daemonize = 1;
+			break;
+		case 's':
+			force_single_threaded = 1;
+			break;
+		case 't':
+			trace_mode_enabled = 1;
+			break;
+		case '?':
+		default:
+			usage();
+			/* NOT REACHED */
 		}
 	}
 	
@@ -579,7 +599,8 @@
 	if (do_not_daemonize == 0) {
 		res = daemon(1, trace_mode_enabled == 0 ? 0 : 1);
 		if (res != 0) {
-			LOG_ERR_1("main", "can't daemonize myself: %s", strerror(errno));
+			LOG_ERR_1("main", "can't daemonize myself: %s", 
+		    		strerror(errno));
 			goto fin;
 		} else
 			LOG_MSG_1("main", "successfully daemonized");
@@ -599,19 +620,22 @@
 	error_str = NULL;
 	error_line = 0;
 	config_file = CONFIG_PATH;
-	res = read_configuration(config_file, s_configuration, &error_str, &error_line);
+	res = read_configuration(config_file, s_configuration, &error_str, 
+		&error_line);
 	if ((res != 0) && (error_str == NULL)) {
 		config_file = DEFAULT_CONFIG_PATH;
-		res = read_configuration(config_file, s_configuration, &error_str, &error_line);
+		res = read_configuration(config_file, s_configuration, 
+	    		&error_str, &error_line);
 	}
 	
 	if (res != 0) {
 		if (error_str != NULL) {
-			LOG_ERR_1("main", "error in configuration file(%s, %d): %s\n", config_file, 
-				error_line, error_str);
+		LOG_ERR_1("main", "error in configuration file(%s, %d): %s\n", 
+			config_file, error_line, error_str);
 		} else {
-			LOG_ERR_1("main", "no configuration file found - was looking for %s and %s",
-				CONFIG_PATH, DEFAULT_CONFIG_PATH);
+		LOG_ERR_1("main", 
+			"no configuration file found - was looking for %s and %s",
+			CONFIG_PATH, DEFAULT_CONFIG_PATH);
 		}
 		destroy_configuration(s_configuration);
 		return (-1);
@@ -646,16 +670,21 @@
 	}
 		
 	if (s_configuration->threads_num > 1) {
-		threads = (pthread_t *)malloc(sizeof(pthread_t) * s_configuration->threads_num);
-		memset(threads, 0, sizeof(pthread_t) * s_configuration->threads_num);
+		threads = (pthread_t *)malloc(sizeof(pthread_t) * 
+			s_configuration->threads_num);
+		memset(threads, 0, sizeof(pthread_t) * 
+	    		s_configuration->threads_num);
 		for (i = 0; i < s_configuration->threads_num; ++i) {
-			thread_args = (struct processing_thread_args *)malloc(sizeof(struct processing_thread_args));
+			thread_args = (struct processing_thread_args *)malloc(
+				sizeof(struct processing_thread_args));
 			thread_args->the_cache = s_cache;
 			thread_args->the_runtime_env = s_runtime_env;
 			thread_args->the_configuration = s_configuration;
 		
-			LOG_MSG_1("main", "thread #%d was successfully created", i);
-			pthread_create(&threads[i], NULL, processing_thread, thread_args);		
+			LOG_MSG_1("main", "thread #%d was successfully created",
+				i);
+			pthread_create(&threads[i], NULL, processing_thread, 
+				thread_args);		
 			
 			thread_args = NULL;
 		}

==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/cached.conf#4 (text+ko) ====

@@ -58,14 +58,14 @@
 	euid = 0
 }
 
-entry "hosts" {
+entry "services" {
 	type = common
 	policy = lru
 	max_lifetime = 43200
 	max_elemsize = 1000
 }
 
-entry "hosts" {
+entry "services" {
 	type = common
 	policy = lru
 	max_lifetime = 43200
@@ -73,27 +73,27 @@
 	euid = 0
 }
 
-entry "hosts_mp" {
+entry "services_mp" {
 	type = multipart
 	max_lifetime = 43200
 	timeout = 60
 }
 
-entry "hosts_mp" {
+entry "services_mp" {
 	type = multipart
 	max_lifetime = 43200
 	timeout = 60
 	euid = 0
 }
 
-entry "services" {
+entry "protocols" {
 	type = common
 	policy = lru
 	max_lifetime = 43200
 	max_elemsize = 1000
 }
 
-entry "services" {
+entry "protocols" {
 	type = common
 	policy = lru
 	max_lifetime = 43200
@@ -101,27 +101,27 @@
 	euid = 0
 }
 
-entry "services_mp" {
+entry "protocols_mp" {
 	type = multipart
 	max_lifetime = 43200
 	timeout = 60
 }
 
-entry "services_mp" {
+entry "protocols_mp" {
 	type = multipart
 	max_lifetime = 43200
 	timeout = 60
 	euid = 0
 }
 
-entry "protocols" {
+entry "rpc" {
 	type = common
 	policy = lru
 	max_lifetime = 43200
 	max_elemsize = 1000
 }
 
-entry "protocols" {
+entry "rpc" {
 	type = common
 	policy = lru
 	max_lifetime = 43200
@@ -129,43 +129,30 @@
 	euid = 0
 }
 
-entry "protocols_mp" {
+entry "rpc_mp" {
 	type = multipart
 	max_lifetime = 43200
 	timeout = 60
 }
 
-entry "protocols_mp" {
+entry "rpc_mp" {
 	type = multipart
 	max_lifetime = 43200
 	timeout = 60
 	euid = 0
 }
 
-entry "rpc" {
+entry "hosts" {
 	type = common
 	policy = lru
 	max_lifetime = 43200
 	max_elemsize = 1000
 }
 
-entry "rpc" {
+entry "hosts" {
 	type = common
 	policy = lru
 	max_lifetime = 43200
 	max_elemsize = 1000
 	euid = 0
 }
-
-entry "rpc_mp" {
-	type = multipart
-	max_lifetime = 43200
-	timeout = 60
-}
-
-entry "rpc_mp" {
-	type = multipart
-	max_lifetime = 43200
-	timeout = 60
-	euid = 0
-}

==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.1/bin/cached.conf.5#3 (text+ko) ====

@@ -1,32 +1,86 @@
-.\" Copyright (C) 2005, Michael Bushkov <bushman@rsu.ru>
-.TH "cached.conf" "5" "0.1" "Michael Bushkov" "FreeBSD File Formats Manual"
-.SH "NAME"
-.LP 
-\fBcached.conf\fR \- the caching daemon (\fBcached\fR) configuration file
-.SH "DESCRIPTION"
-\fBcached.conf\fR consists has 2 types of elements: \fIkey=value pairs\fP and \fIgroups of such pairs\fP. Groups are used to specify needed cache entries, and "global" key=value pairs allow to change some global \fBcached\fR parameters.
-.br
-.SS Gobal pairs
-.br
-Global pairs are usually specified in the beginning of the \fIcached.conf\fP file. They have the following form: \fBkey\fR=\fIvalue\fP.
-.LP
-.TP
-\fBsocket_path\fR=\fIstring\fP
-Defines the path to the unix socket, which \fBcached\fR will use to communicate with client applications. The default is \fI/var/run/cached\fP.
-.TP
-\fBpidfile_path\fR=\fIstring\fP
-Defines the path to the pid file, which will be used by the startup script to control \fBcached\fR execution. The default is \fI/var/run/cached.pid\fP.
-.TP
-\fBquery_timeout\fR=\fIpositive_integer\fP
-Specifies the query timeout in seconds. When this time is expired, the \fBcached\fR will close the connection with the client. This parameter can be overriden for each cache entry. The default is \fI8\fP.
-.TP
-\fBthreads\fR=\fIpositive_integer_between_1_and_32\fP
-Defines the number of threads, which \fBcached\fR will use to process the requests. The default is \fI8\fP.
-.br
-.SS Groups
-.br
-Each group describes one cache entry. Groups are defined using the following form:
-.br
+.\" Copyright (c) 2005 Michael Bushkov <bushman@rsu.ru>
+.\" All rights reserved.
+.\" 
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\" 
+
+.Dd August 29, 2005
+.Dt CACHED.CONF 5
+.Os
+.Sh NAME
+.Nm cached.conf
+.Nd "caching daemon configuration file manual page"
+.Sh "DESCRIPTION"
+.Nm
+has 2 types of elements: 
+.Pa key=value pairs
+and
+.Pa groups of such pairs.
+Groups are used to specify needed cache entries, and "global" key=value 
+pairs allow to change some global
+.Xr cached 8
+parameters.
+.Ss Gobal pairs
+Global pairs are usually specified in the beginning of the 
+.Nm
+file. 
+They have the following form: key=value.
+.Pp
+.Bl -tag -width Pair
+.It Sy Pair
+.Sy Description
+.It socket_path = [string]
+Defines the path to the unix socket, which 
+.Xr cached 8
+will use to 
+communicate with client applications. 
+The default is
+.Pa /var/run/cached .
+.It pidfile_path= [string]
+Defines the path to the pid file, which will be used by the startup script 
+to control
+.Xr cached 8
+execution. 
+The default is 
+.Pa /var/run/cached.pid .

>>> TRUNCATED FOR MAIL (1000 lines) <<<



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200508291613.j7TGDwGK071969>