PERFORCE change 84780 for review
soc-bushman
soc-bushman at FreeBSD.org
Tue Oct 4 05:03:13 PDT 2005
http://perforce.freebsd.org/chv.cgi?CH=84780
Change 84780 by soc-bushman at soc-bushman_stinger on 2005/10/04 12:02:28
SIGPIPE is now ignored
multipart snapshots are made when lookups are performed by ourselves
some bugs fixed in the marshalling code
Affected files ...
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/Makefile#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/Makefile.inc#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/hosts.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/hosts.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/passwd.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/passwd.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/services.c#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/services.h#3 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.8#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.c#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.conf#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.conf.5#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cachelib.c#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cachelib.h#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cacheplcs.c#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cacheplcs.h#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/config.c#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/config.h#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/debug.c#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/debug.h#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/hashtable.h#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/log.c#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/log.h#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_rs_query.c#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_rs_query.h#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_ws_query.c#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_ws_query.h#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/parser.c#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/parser.h#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/protocol.c#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/protocol.h#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/query.c#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/query.h#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/singletons.c#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/singletons.h#7 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/gethostnamadr.c#6 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/name6.c#6 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/nscache.c#6 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/nscachedcli.c#6 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nscache.c#10 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nscachedcli.c#5 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nsdispatch.c#11 edit
.. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nsdispatch_test.c#10 edit
Differences ...
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/Makefile#7 (text+ko) ====
@@ -10,6 +10,7 @@
CFLAGS+= -DCONFIG_PATH="\"${PREFIX}/etc/cached.conf\""
DPADD+=${LIBM} ${LIBPTHREAD}
LDADD+=${LIBM} ${LIBPTHREAD}
+LDFLAGS+= -Xlinker --export-dynamic
FILESGROUPS=STARTUP CONF
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/Makefile.inc#3 (text+ko) ====
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/hosts.c#3 (text+ko) ====
@@ -40,6 +40,10 @@
#define GETHOSTBYXXX_LOOKUP 1
#define GETIPNODEBYXXX_LOOKUP 2
+static int hostent_marshal_func(struct hostent *, char *, size_t *);
+static int addrinfo_marshal_func(struct addrinfo *, char *, size_t *);
+static int hosts_lookup_func(const char *, size_t, char **, size_t *);
+
static int
hostent_marshal_func(struct hostent *ht, char *buffer, size_t *buffer_size)
{
@@ -50,7 +54,7 @@
TRACE_IN(hostent_marshal_func);
desired_size = ALIGNBYTES + sizeof(struct hostent) + sizeof(char *);
if (ht->h_name != NULL)
- strlen(ht->h_name) + 1;
+ desired_size += strlen(ht->h_name) + 1;
if (ht->h_aliases != NULL) {
aliases_size = 0;
@@ -68,13 +72,13 @@
for (iter = ht->h_addr_list; *iter; ++iter)
++addr_size;
- desired_size += addr_size * _ALIGN(ht->h_length);
+ desired_size += addr_size * ALIGN(ht->h_length);
desired_size += ALIGNBYTES + (addr_size + 1) * sizeof(char *);
}
- if (desired_size > *buffer_size) {
- /* this assignment is here for future use */
+ if (desired_size > *buffer_size) {
*buffer_size = desired_size;
+ TRACE_OUT(hostent_marshal_func);
return (NS_RETURN);
}
@@ -147,6 +151,7 @@
if (desired_size > *buffer_size) {
/* this assignment is here for future use */
*buffer_size = desired_size;
+ TRACE_OUT(addrinfo_marshal_func);
return (NS_RETURN);
}
@@ -342,8 +347,13 @@
case GETIPNODEBYXXX_LOOKUP:
switch (lookup_type) {
case nss_lt_name:
+ TRACE_STR(hostname);
+ TRACE_INT(type);
ht_result = getipnodebyname(hostname, type,
- AI_DEFAULT, &res);
+ AI_ADDRCONFIG | AI_V4MAPPED, &res);
+ TRACE_INT(res);
+ TRACE_STR(hstrerror(res));
+ TRACE_PTR(ht_result);
break;
case nss_lt_id:
ht_result = getipnodebyaddr(addr, len, type, &res);
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/hosts.h#3 (text+ko) ====
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/passwd.c#3 (text+ko) ====
@@ -34,6 +34,12 @@
#include "../debug.h"
#include "passwd.h"
+static int passwd_marshal_func(struct passwd *, char *, size_t *);
+static int passwd_lookup_func(const char *, size_t, char **, size_t *);
+static void *passwd_mp_init_func();
+static int passwd_mp_lookup_func(char **, size_t *, void *);
+static void passwd_mp_destroy_func(void *mdata);
+
static int
passwd_marshal_func(struct passwd *pwd, char *buffer, size_t *buffer_size)
{
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/passwd.h#3 (text+ko) ====
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/services.c#3 (text+ko) ====
@@ -35,6 +35,12 @@
#include "../debug.h"
#include "services.h"
+static int services_marshal_func(struct servent *, char *, size_t *);
+static int services_lookup_func(const char *, size_t, char **, size_t *);
+static void *services_mp_init_func();
+static int services_mp_lookup_func(char **, size_t *, void *);
+static void services_mp_destroy_func(void *);
+
static int
services_marshal_func(struct servent *serv, char *buffer, size_t *buffer_size)
{
@@ -63,9 +69,9 @@
(aliases_size + 1);
}
- if (*buffer_size < desired_size) {
- /* this assignment is here for future use */
+ if (*buffer_size < desired_size) {
*buffer_size = desired_size;
+ TRACE_OUT(services_marshal_func);
return (NS_RETURN);
}
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/services.h#3 (text+ko) ====
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.8#7 (text+ko) ====
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.c#7 (text+ko) ====
@@ -34,6 +34,7 @@
#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -135,7 +136,7 @@
asprintf(&pid_string,"%u",getpid());
assert(pid_string != NULL);
- fwrite(pid_string,strlen(pid_string),1,pidfile);
+ fwrite(pid_string,strlen(pid_string), 1, pidfile);
free(pid_string);
fclose(pidfile);
@@ -146,7 +147,7 @@
print_version_info(void)
{
TRACE_IN(print_version_info);
- printf("cached v0.1 (19 Aug 2005)\nwas developed during SoC 2005\n");
+ printf("cached v0.2 (19 Aug 2005)\nwas developed during SoC 2005\n");
TRACE_OUT(print_version_info);
}
@@ -276,9 +277,9 @@
struct query_state *qstate;
struct sockaddr addr;
- socklen_t addr_len;
- int fd;
- int res;
+ socklen_t addr_len;
+ int fd;
+ int res;
uid_t euid;
gid_t egid;
@@ -324,10 +325,10 @@
struct kevent eventlist[2];
struct timeval query_timeout;
struct timespec kevent_timeout;
- int nevents;
- int eof_res, res;
- ssize_t io_res;
- struct query_state *qstate;
+ int nevents;
+ int eof_res, res;
+ ssize_t io_res;
+ struct query_state *qstate;
TRACE_IN(process_socket_event);
eof_res = event_data->flags & EV_EOF ? 1 : 0;
@@ -564,9 +565,17 @@
processing_thread(void *data)
{
struct processing_thread_args *args;
+ sigset_t new;
- TRACE_MSG("=> processing_thread");
+ TRACE_MSG("=> processing_thread");
args = (struct processing_thread_args *)data;
+
+ sigemptyset(&new);
+ sigaddset(&new, SIGPIPE);
+ if (pthread_sigmask(SIG_BLOCK, &new, NULL) != 0)
+ LOG_ERR_1("processing thread",
+ "thread can't block the SIGPIPE signal");
+
processing_loop(args->the_cache, args->the_runtime_env,
args->the_configuration);
free(args);
@@ -633,7 +642,10 @@
if (trace_mode_enabled == 1)
TRACE_ON();
-
+
+ /* blocking the main thread from receiving SIGPIPE signal */
+ sigblock(sigmask(SIGPIPE));
+
/* daemonization */
if (do_not_daemonize == 0) {
res = daemon(0, trace_mode_enabled == 0 ? 0 : 1);
@@ -659,7 +671,14 @@
register_agent(s_agent_table, init_group_mp_agent());
register_agent(s_agent_table, init_services_agent());
register_agent(s_agent_table, init_services_mp_agent());
- register_agent(s_agent_table, init_hosts_agent());
+
+ /*
+ * Hosts agent can't work properly until we have access to the
+ * appropriate dtab structures, which are used in nsdispatch
+ * calls
+ *
+ register_agent(s_agent_table, init_hosts_agent());
+ */
/* configuration initialization */
s_configuration = init_configuration();
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.conf#7 (text+ko) ====
@@ -1,168 +1,10 @@
-socket_path = "/var/run/cached"
-pidfile_path = "/var/run/cached.pid"
-threads = 8
+#
+# Default caching daemon configuration file
+#
-entry "passwd" {
- type = common
- policy = lru
- max_lifetime = 43200
- max_elemsize = 10000
-}
-
-entry "passwd" {
- type = common
- policy = lru
- max_lifetime = 43200
- max_elemsize = 10000
- euid = 0
-}
-
-entry "passwd_mp" {
- type = multipart
- max_lifetime = 43200
- max_elemsize = 5000
- timeout = 60
-}
-
-entry "passwd_mp" {
- type = multipart
- max_lifetime = 43200
- max_elemsize = 5000
- timeout = 60
- euid = 0
-}
-
-entry "group" {
- type = common
- policy = lru
- max_lifetime = 43200
- max_elemsize = 10000
-}
-
-entry "group" {
- type = common
- policy = lru
- max_lifetime = 43200
- max_elemsize = 10000
- euid = 0
-}
-
-entry "group_mp" {
- type = multipart
- max_lifetime = 43200
- max_elemsize = 5000
- timeout = 60
-}
-
-entry "group_mp" {
- type = multipart
- max_lifetime = 43200
- max_elemsize = 5000
- timeout = 60
- euid = 0
-}
-
-entry "services" {
- type = common
- policy = lru
- max_lifetime = 43200
- max_elemsize = 10000
-}
-
-entry "services" {
- type = common
- policy = lru
- max_lifetime = 43200
- max_elemsize = 10000
- euid = 0
-}
-
-entry "services_mp" {
- type = multipart
- max_lifetime = 43200
- max_elemsize = 5000
- timeout = 60
-}
-
-entry "services_mp" {
- type = multipart
- max_lifetime = 43200
- max_elemsize = 5000
- timeout = 60
- euid = 0
-}
-
-entry "protocols" {
- type = common
- policy = lru
- max_lifetime = 43200
- max_elemsize = 10000
-}
-
-entry "protocols" {
- type = common
- policy = lru
- max_lifetime = 43200
- max_elemsize = 10000
- euid = 0
-}
-
-entry "protocols_mp" {
- type = multipart
- max_lifetime = 43200
- max_elemsize = 5000
- timeout = 60
-}
-
-entry "protocols_mp" {
- type = multipart
- max_lifetime = 43200
- max_elemsize = 5000
- timeout = 60
- euid = 0
-}
-
-entry "rpc" {
- type = common
- policy = lru
- max_lifetime = 43200
- max_elemsize = 10000
-}
-
-entry "rpc" {
- type = common
- policy = lru
- max_lifetime = 43200
- max_elemsize = 10000
- euid = 0
-}
-
-entry "rpc_mp" {
- type = multipart
- max_lifetime = 43200
- max_elemsize = 5000
- timeout = 60
-}
-
-entry "rpc_mp" {
- type = multipart
- max_lifetime = 43200
- max_elemsize = 5000
- timeout = 60
- euid = 0
-}
-
-entry "hosts" {
- type = common
- policy = lru
- max_lifetime = 43200
- max_elemsize = 10000
-}
-
-entry "hosts" {
- type = common
- policy = lru
- max_lifetime = 43200
- max_elemsize = 10000
- euid = 0
-}
+enable-cache passwd yes
+enable-cache group yes
+enable-cache hosts yes
+enable-cache services yes
+enable-cache protocols yes
+enable-cache rpc yes
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.conf.5#7 (text+ko) ====
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cachelib.c#7 (text+ko) ====
@@ -500,7 +500,7 @@
memcpy(&new_common_entry->common_params, params,
sizeof(struct common_cache_entry_params));
new_common_entry->params =
- (struct cache_entry_params *)&new_common_entry->common_params;
+ (struct cache_entry_params *)&new_common_entry->common_params;
new_common_entry->common_params.entry_name = (char *)malloc(
entry_name_size+1);
@@ -509,7 +509,8 @@
entry_name_size + 1);
strncpy(new_common_entry->common_params.entry_name,
params->entry_name, entry_name_size);
- new_common_entry->name = new_common_entry->common_params.entry_name;
+ new_common_entry->name =
+ new_common_entry->common_params.entry_name;
TRACE_STR(new_common_entry->name);
TRACE_POINT();
@@ -547,7 +548,8 @@
}
}
- new_common_entry->get_time_func = the_cache->params.get_time_func;
+ new_common_entry->get_time_func =
+ the_cache->params.get_time_func;
the_cache->entries[the_cache->entries_size++] =
(struct cache_entry_ *)new_common_entry;
break;
@@ -785,7 +787,8 @@
if (common_entry->policies_size > 1) {
TRACE_POINT();
- connected_policy_item = common_entry->policies[1]->create_item_func();
+ connected_policy_item =
+ common_entry->policies[1]->create_item_func();
memcpy(&connected_policy_item->creation_time,
&policy_item->creation_time,
sizeof(struct timeval));
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cachelib.h#7 (text+ko) ====
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cacheplcs.c#7 (text+ko) ====
@@ -192,10 +192,14 @@
retval->parent_data.add_item_func = cache_queue_policy_add_item;
retval->parent_data.remove_item_func = cache_queue_policy_remove_item;
- retval->parent_data.get_first_item_func = cache_queue_policy_get_first_item;
- retval->parent_data.get_last_item_func = cache_queue_policy_get_last_item;
- retval->parent_data.get_next_item_func = cache_queue_policy_get_next_item;
- retval->parent_data.get_prev_item_func = cache_queue_policy_get_prev_item;
+ retval->parent_data.get_first_item_func =
+ cache_queue_policy_get_first_item;
+ retval->parent_data.get_last_item_func =
+ cache_queue_policy_get_last_item;
+ retval->parent_data.get_next_item_func =
+ cache_queue_policy_get_next_item;
+ retval->parent_data.get_prev_item_func =
+ cache_queue_policy_get_prev_item;
TAILQ_INIT(&retval->head);
TRACE_OUT(init_cache_queue_policy);
@@ -361,7 +365,8 @@
TRACE_INT(lfu_item->frequency);
TRACE_INT(index);
- TAILQ_REMOVE(&(lfu_policy->groups[lfu_item->frequency]), lfu_item, entries);
+ TAILQ_REMOVE(&(lfu_policy->groups[lfu_item->frequency]), lfu_item,
+ entries);
lfu_item->frequency = index;
TAILQ_INSERT_HEAD(&(lfu_policy->groups[index]), lfu_item, entries);
@@ -379,7 +384,8 @@
lfu_policy = (struct cache_lfu_policy_ *)policy;
lfu_item = (struct cache_lfu_policy_item_ *)item;
- TAILQ_REMOVE(&(lfu_policy->groups[lfu_item->frequency]), lfu_item, entries);
+ TAILQ_REMOVE(&(lfu_policy->groups[lfu_item->frequency]), lfu_item,
+ entries);
TRACE_OUT(cache_lfu_policy_remove_item);
}
@@ -442,22 +448,9 @@
TRACE_INT(((struct cache_lfu_policy_item_ *)item)->frequency);
for (i = ((struct cache_lfu_policy_item_ *)item)->frequency + 1;
i < CACHELIB_MAX_FREQUENCY; ++i) {
- TRACE_PTR(&(lfu_policy->groups[i]));
if (!TAILQ_EMPTY(&(lfu_policy->groups[i]))) {
- TRACE_POINT();
- lfu_item = TAILQ_FIRST(&(lfu_policy->groups[i]));
- for (; lfu_item != NULL; lfu_item=TAILQ_NEXT(lfu_item,entries)) {
- TRACE_INT(lfu_item->frequency);
- TRACE_POINT();
- }
-
- TRACE_POINT();
- lfu_item = TAILQ_FIRST(&(lfu_policy->groups[i]));
- TRACE_INT(i);
- lfu_item = TAILQ_FIRST(&(lfu_policy->groups[i]));
- TRACE_INT(lfu_item->frequency);
- TRACE_PTR(lfu_item);
- break;
+ lfu_item = TAILQ_FIRST(&(lfu_policy->groups[i]));
+ break;
}
}
}
@@ -512,10 +505,14 @@
retval->parent_data.update_item_func = cache_lfu_policy_update_item;
retval->parent_data.remove_item_func = cache_lfu_policy_remove_item;
- retval->parent_data.get_first_item_func = cache_lfu_policy_get_first_item;
- retval->parent_data.get_last_item_func = cache_lfu_policy_get_last_item;
- retval->parent_data.get_next_item_func = cache_lfu_policy_get_next_item;
- retval->parent_data.get_prev_item_func = cache_lfu_policy_get_prev_item;
+ retval->parent_data.get_first_item_func =
+ cache_lfu_policy_get_first_item;
+ retval->parent_data.get_last_item_func =
+ cache_lfu_policy_get_last_item;
+ retval->parent_data.get_next_item_func =
+ cache_lfu_policy_get_next_item;
+ retval->parent_data.get_prev_item_func =
+ cache_lfu_policy_get_prev_item;
for (i = 0; i < CACHELIB_MAX_FREQUENCY; ++i)
TAILQ_INIT(&(retval->groups[i]));
@@ -536,7 +533,8 @@
for (i = 0; i < CACHELIB_MAX_FREQUENCY; ++i) {
while (!TAILQ_EMPTY(&(lfu_policy->groups[i]))) {
lfu_item = TAILQ_FIRST(&(lfu_policy->groups[i]));
- TAILQ_REMOVE(&(lfu_policy->groups[i]), lfu_item, entries);
+ TAILQ_REMOVE(&(lfu_policy->groups[i]), lfu_item,
+ entries);
cache_lfu_policy_destroy_item(
(struct cache_policy_item_ *)lfu_item);
}
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cacheplcs.h#7 (text+ko) ====
==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/config.c#7 (text+ko) ====
@@ -65,29 +65,6 @@
static int
configuration_entry_cmp(const void *e1, const void *e2)
{
-/* struct configuration_entry *entry1;
- struct configuration_entry *entry2;
- int res;
-
- entry1 = *((struct configuration_entry **)e1);
- entry2 = *((struct configuration_entry **)e2);
-
- res = strcmp(entry1->name, entry2->name);
- if (res == 0) {
- if ((entry1->use_desired_euid == 0) &&
- (entry2->use_desired_euid != 0))
- res = -1;
- else if ((entry1->use_desired_euid != 0) &&
- (entry2->use_desired_euid == 0))
- res = 1;
- else if ((entry1->use_desired_euid != 0) &&
- (entry2->use_desired_euid != 0))
- res = entry1->desired_euid - entry2->desired_euid;
- else
- res = 0;
- }
-
- return (res);*/
return (strcmp((const char *)e1,
(*((struct configuration_entry **)e2))->name
));
@@ -184,67 +161,6 @@
TRACE_OUT(create_configuration_entry);
return (retval);
-/* switch (params->entry_type) {
- case CET_COMMON:
- size = sizeof(struct common_cache_entry_params);
- break;
- case CET_MULTIPART:
- size = sizeof(struct mp_cache_entry_params);
- break;
- default:
- assert(0);
- TRACE_OUT(create_configuration_entry);
- return (NULL);
- }
-
- res = pthread_mutexattr_init(&attr);
- if (res != 0) {
- TRACE_INT(res);
- TRACE_OUT(create_configuration_entry);
- return (NULL);
- }
- pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
-
- retval = (struct configuration_entry *)malloc(
- sizeof(struct configuration_entry));
- assert(retval != NULL);
- memset(retval, 0, sizeof(struct configuration_entry));
-
- res = pthread_mutex_init(&retval->lock, &attr);
- if (res != 0) {
- free(retval);
- pthread_mutexattr_destroy(&attr);
- TRACE_OUT(create_configuration_entry);
- return (NULL);
- }
- pthread_mutexattr_destroy(&attr);
-
- retval->c_params = (struct cache_entry_params *)malloc(size);
- assert(retval->c_params != NULL);
- memcpy(retval->c_params, params, size);
-
- size = strlen(name);
- retval->name = (char *)malloc(size + 1);
- assert(retval->name != NULL);
- memset(retval->name, 0, size + 1);
- strncpy(retval->name, name, size);
-
- if (use_desired_euid == 0)
- retval->c_params->entry_name = retval->name;
- else {
- asprintf(&retval->c_params->entry_name, "%s_%d",
- name, desired_euid);
- assert(retval->c_params->entry_name != NULL);
- TRACE_STR(name);
- TRACE_STR(retval->c_params->entry_name);
- }
-
- retval->desired_euid = desired_euid;
- retval->use_desired_euid = use_desired_euid;
- memcpy(&retval->query_timeout, timeout, sizeof(struct timeval));
-
- TRACE_OUT(create_configuration_entry);
- return (retval);*/
}
struct configuration_entry *
@@ -350,287 +266,6 @@
return (0);
}
-/*static int
-process_root_parser_pair(struct configuration *config,
- struct parser_pair_ *pair, char const **error_str, int *error_line)
-{
- char *endp;
- long l;
- size_t size;
- int res;
-
- TRACE_IN(process_root_parser_pair);
- assert(config != NULL);
- assert(pair != NULL);
-
- res = 0;
- if (strcmp(pair->key, "socket_path") == 0) {
- free(config->socket_path);
-
- size = strlen(pair->value);
- config->socket_path = (char *)malloc(size + 1);
- memset(config->socket_path, 0, size + 1);
- strncpy(config->socket_path, pair->value, size);
- } else if (strcmp(pair->key, "pidfile_path") == 0) {
- free(config->pidfile_path);
-
- size = strlen(pair->value);
- config->pidfile_path = (char *)malloc(size + 1);
- memset(config->pidfile_path, 0, size + 1);
- strncpy(config->pidfile_path, pair->value, size);
- } else if (strcmp(pair->key, "query_timeout") == 0) {
- l = strtol(pair->value, &endp, 10);
- if ((*endp == '\0') && (l >= 0))
- config->query_timeout = l;
- else {
- *error_str = "query timeout must be a positive integer";
- *error_line = pair->fline;
- res = -1;
- }
- } else if (strcmp(pair->key, "threads") == 0) {
- l = strtol(pair->value, &endp, 10);
- if ((*endp == '\0') && (l >= 1) && (l <= 32))
- config->threads_num = l;
- else {
- *error_str = "threads number must be a "
- "positive integer between 1 and 32 (inclusive)";
- *error_line = pair->fline;
- res = -1;
- }
- } else {
- *error_str = "unknown parameter";
- *error_line = pair->fline;
- res = -1;
- }
-
- TRACE_OUT(process_root_parser_pair);
- return (res);
-}
-
-static int
-process_parser_common_group_pair(struct common_cache_entry_params *params,
- struct parser_pair_ *pair, char const **error_str, int *error_line)
-{
- char *endp;
- long l;
- int res;
-
- TRACE_IN(process_parser_common_group_pair);
- res = 0;
- if (strcmp(pair->key, "policy") == 0) {
- if (strcmp(pair->value, "fifo") == 0) {
- params->policy = CPT_FIFO;
- } else if (strcmp(pair->value, "lru") == 0) {
- params->policy = CPT_LRU;
- } else if (strcmp(pair->value, "lfu") == 0) {
- params->policy = CPT_LFU;
- } else {
- *error_str = "policy must be one of "
- "'fifo', 'lru' or 'lfu' values";
- *error_line = pair->fline;
- res = -1;
- }
- } else if (strcmp(pair->key, "max_lifetime") == 0) {
- l = strtol(pair->value, &endp, 10);
- if ((*endp == '\0') && (l >= 0)) {
- params->max_lifetime.tv_sec = l;
- } else {
- *error_str = "max_lifetime must be a positive integer";
- *error_line = pair->fline;
- res = -1;
- }
- } else if (strcmp(pair->key, "max_elemsize") == 0) {
- l = strtol(pair->value, &endp, 10);
- if ((*endp == '\0') && (l >= 0)) {
- params->max_elemsize = l;
- } else {
- *error_str = "max_elemsize must be a positive integer";
- *error_line = pair->fline;
- res = -1;
- }
- } else {
- *error_str = "unexpected parameter";
- *error_line = pair->fline;
- res = -1;
- }
-
- TRACE_OUT(process_parser_common_group_pair);
- return (res);
-}
-
-static int
-process_parser_mp_group_pair(struct mp_cache_entry_params *params,
- struct parser_pair_ *pair, char const **error_str, int *error_line)
-{
- char *endp;
- long l;
- int res;
-
- TRACE_IN(process_parser_mp_group_pair);
- res = 0;
- if (strcmp(pair->key, "max_sessions") == 0) {
- l = strtol(pair->value, &endp, 10);
- if ((*endp == '\0') && (l >= 0)) {
- params->max_sessions = l;
- } else {
- *error_str = "max_sessions must be a positive integer";
- *error_line = pair->fline;
- res = -1;
- }
- } else if (strcmp(pair->key, "max_lifetime") == 0) {
- l = strtol(pair->value, &endp, 10);
- if ((*endp == '\0') && (l >= 0)) {
- params->max_lifetime.tv_sec = l;
- } else {
- *error_str = "max_lifetime must be a positive integer";
- *error_line = pair->fline;
- res = -1;
- }
- } else if (strcmp(pair->key, "max_elemsize") == 0) {
- l = strtol(pair->value, &endp, 10);
- if ((*endp == '\0') && (l >= 0)) {
- params->max_elemsize = l;
- } else {
- *error_str = "max_elemsize must be a positive integer";
- *error_line = pair->fline;
- res = -1;
- }
- } else {
- *error_str = "unexpected parameter";
- *error_line = pair->fline;
- res = -1;
- }
-
- TRACE_OUT(process_parser_mp_group_pair);
- return (res);
-}
-
-static int
-process_parser_group(struct configuration *config, struct parser_group_ *group,
- char const **error_str, int *error_line)
-{
- char *endp;
- long l;
-
- struct configuration_entry *config_entry;
- struct cache_entry_params *params;
- uid_t desired_euid;
- int use_desired_euid;
- struct timeval timeout;
-
- struct parser_pair_ *pair;
- size_t size, i;
- int res;
-
- TRACE_IN(process_parser_group);
- assert(config != NULL);
- assert(group != NULL);
-
- res = 0;
- params = NULL;
- desired_euid = -1;
- use_desired_euid = 0;
- memset(&timeout, 0, sizeof(struct timeval));
- size = parser_group_get_pairs_size(group);
- if (size >= 1) {
- pair = parser_group_get_pair(group, 0);
- if (strcmp(pair->key, "type") == 0) {
- TRACE_STR(pair->value);
- if (strcmp(pair->value, "common") == 0) {
- params = (struct cache_entry_params *)malloc(
- sizeof(struct common_cache_entry_params));
- assert(params != NULL);
- memset(params, 0,
- sizeof(struct common_cache_entry_params));
-
- params->entry_type = CET_COMMON;
- } else if (strcmp(pair->value, "multipart") == 0) {
- params = (struct cache_entry_params *)malloc(
- sizeof(struct mp_cache_entry_params));
- assert(params != NULL);
- memset(params, 0,
- sizeof(struct mp_cache_entry_params));
-
- params->entry_type = CET_MULTIPART;
- } else {
- *error_str = "entry type must be one of 'common'"
- "and 'multipart' values";
- *error_line = pair->fline;
- res = -1;
- goto fin;
- }
- } else {
- *error_str = "'type' parameter expected";
- *error_line = pair->fline;
- res = -1;
- goto fin;
- }
-
- for (i = 1; i < size; ++i) {
- pair = parser_group_get_pair(group, i);
- if (params->entry_type == CET_COMMON) {
- res = process_parser_common_group_pair(
- (struct common_cache_entry_params *)params,
- pair, error_str, error_line);
- } else {
- res = process_parser_mp_group_pair(
- (struct mp_cache_entry_params *)params,
- pair, error_str,
- error_line);
- }
-
- if (res != 0) {
- if (strcmp(pair->key, "euid") == 0) {
- l = strtol(pair->value, &endp, 10);
- if ((*endp == '\0') && (l >= 0)) {
- desired_euid = l;
- use_desired_euid = 1;
- } else {
- TRACE_STR(pair->value);
- *error_str = "euid parameter "
- "must be a positive integer";
- *error_line = pair->fline;
- res = -1;
- goto fin;
- }
- } else if (strcmp(pair->key, "timeout") == 0) {
- l = strtol(pair->value, &endp, 10);
- if ((*endp == '\0') && (l >= 0)) {
- timeout.tv_sec = l;
- timeout.tv_usec = 0;
- } else {
- *error_str = "timeout must be a"
- " positive integer";
- *error_line = pair->fline;
- res = -1;
- goto fin;
- }
- } else
- goto fin;
- }
- }
-
- config_entry = create_configuration_entry(group->name,
- desired_euid, use_desired_euid, &timeout, params);
- res = add_configuration_entry(config, config_entry);
- if (res != 0) {
- destroy_configuration_entry(config_entry);
- *error_str = "duplicate entry";
- *error_line = group->fline;
- }
- } else {
- *error_str = "at least entry type ('common' or 'multipart')"
- "must be specified";
- *error_line = group->fline;
- res = -1;
- }
-
-fin:
- free(params);
>>> TRUNCATED FOR MAIL (1000 lines) <<<
More information about the p4-projects
mailing list