Date: Fri, 17 Nov 2006 16:26:49 GMT From: Michael Bushkov <bushman@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 110158 for review Message-ID: <200611171626.kAHGQnL1071886@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=110158 Change 110158 by bushman@bushman_nss_ldap_cached on 2006/11/17 16:26:28 + commong_agent and multipart_agent structures were merged into one agent structure + each agent now supports check_changes_func, which checks if something has changed and cache should be flushed + support for check_changes_func was added to all implemented agents, to query.c, mp_ws_query.c and mp_rs_query.c * TODO: "check-files" configurations' file directive now should be connected with new functionality Affected files ... .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/Makefile#5 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agent.c#7 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agent.h#7 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/group.c#8 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/group.h#6 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/hosts.c#6 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/hosts.h#5 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/net.c#6 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/net.h#5 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/passwd.c#7 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/passwd.h#6 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/proto.c#6 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/proto.h#5 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/rpc.c#6 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/rpc.h#5 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/services.c#7 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/services.h#6 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/cached.c#11 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/cacheutil.c#1 add .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/cacheutil.h#1 add .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/config.c#7 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/config.h#7 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/mp_rs_query.c#8 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/mp_ws_query.c#6 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/parser.c#6 edit .. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/query.c#9 edit Differences ... ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/Makefile#5 (text) ==== @@ -5,9 +5,9 @@ MAN=cached.conf.5 cached.8 WARNS?=2 -SRCS= agent.c cached.c cachedcli.c cachelib.c cacheplcs.c debug.c log.c \ - config.c query.c mp_ws_query.c mp_rs_query.c singletons.c protocol.c \ - parser.c +SRCS= agent.c cached.c cachedcli.c cachelib.c cacheplcs.c cacheutil.c \ + debug.c log.c config.c query.c mp_ws_query.c mp_rs_query.c \ + singletons.c protocol.c parser.c CFLAGS+= -DCONFIG_PATH="\"${PREFIX}/etc/cached.conf\"" DPADD+=${LIBM} ${LIBPTHREAD} ${LIBUTIL} LDADD+=${LIBM} ${LIBPTHREAD} ${LIBUTIL} ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agent.c#7 (text) ==== @@ -46,25 +46,19 @@ { NULL, NULL, NULL } }; +struct standard_agent_file_check_mdata +{ + time_t nsswitch_conf_mtime; + time_t custom_file_mtime1; + time_t custom_file_mtime2; +}; static int agent_cmp_func(const void *a1, const void *a2) { - struct agent const *ap1 = *((struct agent const **)a1); - struct agent const *ap2 = *((struct agent const **)a2); - int res; - res = strcmp(ap1->name, ap2->name); - if (res == 0) { - if (ap1->type == ap2->type) - res = 0; - else if (ap1->type < ap2->type) - res = -1; - else - res = 1; - } - - return (res); + return (strcmp((*((struct agent const **)a1))->name, + (*((struct agent const **)a2))->name)); } int @@ -207,14 +201,14 @@ } struct agent * -find_agent(struct agent_table *at, const char *name, enum agent_type type) +find_agent(struct agent_table *at, const char *name) { struct agent **res; struct agent model, *model_p; TRACE_IN(find_agent); + memset(&model, 0, sizeof(struct agent)); model.name = (char *)name; - model.type = type; model_p = &model; res = bsearch(&model_p, at->agents, at->agents_num, sizeof(struct agent *), agent_cmp_func); @@ -241,8 +235,28 @@ } int +agent_check_changes(struct configuration_entry *config_entry, + struct agent *agent_) +{ + int retval; + + TRACE_IN(agent_check_changes); + if ((agent_ == NULL) || (agent_->check_changes_func == NULL)) { + TRACE_OUT(agent_check_changes); + return (0); + } + + configuration_lock_entry(config_entry, CELT_CHANGES_MDATA); + retval = agent_->check_changes_func(&config_entry->changes_mdata); + configuration_unlock_entry(config_entry, CELT_CHANGES_MDATA); + TRACE_OUT(agent_check_changes); + + return (retval); +} + +int agent_precache_results(struct configuration_entry *config_entry, - struct multipart_agent *mp_agent) + struct agent *mp_agent) { cache_mp_write_session ws; char *buffer, *keybuf, *dec_name, *en_bkp; @@ -356,3 +370,64 @@ TRACE_OUT(agent_precache_results); return (NS_SUCCESS); } + +extern int +standard_agent_file_check(char const *fname1, char const *fname2, void *md) +{ + struct standard_agent_file_check_mdata **mdata; + struct stat stat_; + time_t time1, time2, time3; + int rv; + + mdata = (struct standard_agent_file_check_mdata **)md; + if (*mdata == NULL) { + *mdata = malloc(sizeof(struct standard_agent_file_check_mdata)); + /* + * If we can't allocate memory let's just say that nothing + * changed. + */ + if (*mdata == NULL) + return (0); + memset(*mdata, 0, + sizeof(struct standard_agent_file_check_mdata)); + + stat(_PATH_NS_CONF, &stat_); + (*mdata)->nsswitch_conf_mtime = stat_.st_mtime; + + if (fname1 != NULL) { + stat(fname1, &stat_); + (*mdata)->custom_file_mtime1 = stat_.st_mtime; + } + + if (fname2 != NULL) { + stat(fname2, &stat_); + (*mdata)->custom_file_mtime2 = stat_.st_mtime; + } + + return (0); + } else { + rv = stat(_PATH_NS_CONF, &stat_); + time1 = (rv == 0) ? stat_.st_mtime : 0; + + if (fname1 != NULL) { + rv = stat(fname1, &stat_); + time2 = (rv == 0) ? stat_.st_mtime : 0; + } + + if (fname2 != NULL) { + rv = stat(fname2, &stat_); + time3 = (rv == 0) ? stat_.st_mtime : 0; + } + + rv = (time1 != (*mdata)->nsswitch_conf_mtime) || + ((fname1 != NULL) && (time2 != + (*mdata)->custom_file_mtime1)) || + ((fname2 != NULL) && (time3 != + (*mdata)->custom_file_mtime2)); + (*mdata)->nsswitch_conf_mtime = time1; + (*mdata)->custom_file_mtime1 = time2; + (*mdata)->custom_file_mtime2 = time2; + + return (rv); + } +} ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agent.h#7 (text) ==== @@ -126,11 +126,6 @@ * All agents are stored in the agents table, which is the singleton. */ -enum agent_type { - COMMON_AGENT = 0, - MULTIPART_AGENT = 1 -}; - typedef int (*agent_marshal_func)(char *, size_t *, void *, va_list, void *); typedef int (*agent_id_func)(char *, size_t *, va_list, void *); typedef int (*agent_lookup_func)(const char *, size_t, char **, size_t *); @@ -138,20 +133,13 @@ typedef int (*agent_mp_lookup_func)(char **, size_t *, void *, void *); typedef int (*agent_mp_keygen_func)(char **, size_t *, void *, void *); typedef void (*agent_mp_destroy_func)(void *); +typedef int (*agent_check_changes_func)(void *); struct agent { - char *name; - enum agent_type type; -}; + char *name; -struct common_agent { - struct agent parent; + agent_check_changes_func check_changes_func; agent_lookup_func lookup_func; -}; - -struct multipart_agent { - struct agent parent; - agent_mp_init_func mp_init_func; agent_mp_lookup_func mp_lookup_func; agent_mp_keygen_func mp_keygen_func; @@ -171,11 +159,14 @@ void *, ...); extern struct agent_table *init_agent_table(); extern int register_agent(struct agent_table *, struct agent *); -extern struct agent *find_agent(struct agent_table *, const char *, - enum agent_type); +extern struct agent *find_agent(struct agent_table *, const char *); extern void destroy_agent_table(struct agent_table *); +extern int agent_check_changes(struct configuration_entry *, + struct agent *); extern int agent_precache_results(struct configuration_entry *, - struct multipart_agent *); + struct agent *); + +extern int standard_agent_file_check(char const *, char const *, void *); #endif ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/group.c#8 (text) ==== @@ -58,6 +58,7 @@ { NULL, 0 } }; +static int group_check_changes_func(void *); static int group_id_func(char *, size_t *, va_list, void *); static int group_marshal_func(char *, size_t *, void *, va_list, void *); static int group_lookup_func(const char *, size_t, char **, size_t *); @@ -77,6 +78,13 @@ #endif static int +group_check_changes_func(void *mdata) +{ + + return (standard_agent_file_check(_PATH_GROUP, NULL, mdata)); +} + +static int group_id_func(char *buffer, size_t *buffer_size, va_list ap, void *cache_mdata) { char *name; @@ -436,55 +444,30 @@ struct agent * init_group_agent() { - struct common_agent *retval; + struct agent *retval; TRACE_IN(init_group_agent); - retval = malloc(sizeof(struct common_agent)); + retval = malloc(sizeof(struct agent)); if (retval == NULL) { TRACE_OUT(init_group_agent); return (NULL); } - memset(retval, 0, sizeof(struct common_agent)); + memset(retval, 0, sizeof(struct agent)); - retval->parent.name = strdup("group"); - if (retval->parent.name == NULL) { + retval->name = strdup("group"); + if (retval->name == NULL) { free(retval); TRACE_OUT(init_group_agent); return (NULL); } - retval->parent.type = COMMON_AGENT; + retval->check_changes_func = group_check_changes_func; retval->lookup_func = group_lookup_func; - - TRACE_OUT(init_group_agent); - return ((struct agent *)retval); -} - -struct agent * -init_group_mp_agent() -{ - struct multipart_agent *retval; - - TRACE_IN(init_group_mp_agent); - retval = malloc(sizeof(struct multipart_agent)); - if (retval == NULL) { - TRACE_OUT(init_group_mp_agent); - return (NULL); - } - memset(retval, 0, sizeof(struct multipart_agent)); - - retval->parent.name = strdup("group"); - if (retval->parent.name == NULL) { - free(retval); - TRACE_OUT(init_group_mp_agent); - return (NULL); - } - retval->parent.type = MULTIPART_AGENT; retval->mp_init_func = group_mp_init_func; retval->mp_lookup_func = group_mp_lookup_func; retval->mp_keygen_func = group_mp_keygen_func; retval->mp_destroy_func = group_mp_destroy_func; - TRACE_OUT(init_group_mp_agent); - return ((struct agent *)retval); + TRACE_OUT(init_group_agent); + return (retval); } ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/group.h#6 (text) ==== @@ -27,4 +27,3 @@ */ extern struct agent *init_group_agent(); -extern struct agent *init_group_mp_agent(); ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/hosts.c#6 (text+ko) ==== @@ -60,6 +60,7 @@ { NULL, 0 } }; +static int hosts_check_changes_func(void *); static int hostent_marshal_func(char *, size_t *, void *, va_list, void *); static int addrinfo_marshal_func(char *, size_t *, void *, va_list, void *); static int hosts_lookup_func(const char *, size_t, char **, size_t *); @@ -78,6 +79,13 @@ #define GETHOSTBY_OP_ID 1 static int +hosts_check_changes_func(void *mdata) +{ + + return (standard_agent_file_check(_PATH_HOSTS, NULL, mdata)); +} + +static int hostent_marshal_func(char *buffer, size_t *buffer_size, void *retval, va_list ap, void *cache_mdata) { @@ -447,26 +455,26 @@ struct agent * init_hosts_agent() { - struct common_agent *retval; + struct agent *retval; TRACE_IN(init_hosts_agent); - retval = malloc(sizeof(struct common_agent)); + retval = malloc(sizeof(struct agent)); if (retval == NULL) { TRACE_OUT(init_hosts_agent); return (NULL); } - memset(retval, 0, sizeof(struct common_agent)); + memset(retval, 0, sizeof(struct agent)); - retval->parent.name = strdup("hosts"); - if (retval->parent.name == NULL) { + retval->name = strdup("hosts"); + if (retval->name == NULL) { free(retval); TRACE_OUT(init_hosts_agent); return (NULL); } - retval->parent.type = COMMON_AGENT; + retval->check_changes_func = hosts_check_changes_func; retval->lookup_func = hosts_lookup_func; TRACE_OUT(init_hosts_agent); - return ((struct agent *)retval); + return (retval); } ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/hosts.h#5 (text+ko) ==== ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/net.c#6 (text+ko) ==== @@ -59,6 +59,7 @@ { 0 } }; +static int networks_check_changes_func(void *); static int networks_marshal_func(char *, size_t *, void *, va_list, void *); static int networks_lookup_func(const char *, size_t, char **, size_t *); @@ -73,6 +74,13 @@ #endif static int +networks_check_changes_func(void *mdata) +{ + + return (standard_agent_file_check(_PATH_NETWORKS, NULL, mdata)); +} + +static int networks_marshal_func(char *buffer, size_t *buffer_size, void *retval, va_list ap, void *cache_mdata) { @@ -278,26 +286,26 @@ struct agent * init_networks_agent() { - struct common_agent *retval; + struct agent *retval; TRACE_IN(init_networks_agent); - retval = malloc(sizeof(struct common_agent)); + retval = malloc(sizeof(struct agent)); if (retval == NULL) { TRACE_OUT(init_networks_agent); return (NULL); } - memset(retval, 0, sizeof(struct common_agent)); + memset(retval, 0, sizeof(struct agent)); - retval->parent.name = strdup("networks"); - if (retval->parent.name == NULL) { + retval->name = strdup("networks"); + if (retval->name == NULL) { free(retval); TRACE_OUT(init_networks_agent); return (NULL); } - retval->parent.type = COMMON_AGENT; + retval->check_changes_func = networks_check_changes_func; retval->lookup_func = networks_lookup_func; TRACE_OUT(init_networks_agent); - return ((struct agent *)retval); + return (retval); } ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/net.h#5 (text+ko) ==== ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/passwd.c#7 (text) ==== @@ -56,6 +56,7 @@ { NULL, 0 } }; +static int passwd_check_changes_func(void *); static int passwd_id_func(char *, size_t *, va_list, void *); static int passwd_marshal_func(char *, size_t *, void *, va_list, void *); static int passwd_lookup_func(const char *, size_t, char **, size_t *); @@ -67,6 +68,13 @@ AGENT_DECLARE_BUFFER_TLS_HANDLING(passwd); static int +passwd_check_changes_func(void *mdata) +{ + + return (standard_agent_file_check(_PATH_SMP_DB, _PATH_MP_DB, mdata)); +} + +static int passwd_id_func(char *buffer, size_t *buffer_size, va_list ap, void *cache_mdata) { char *name; @@ -432,55 +440,30 @@ struct agent * init_passwd_agent() { - struct common_agent *retval; + struct agent *retval; TRACE_IN(init_passwd_agent); - retval = malloc(sizeof(struct common_agent)); + retval = malloc(sizeof(struct agent)); if (retval == NULL) { TRACE_OUT(init_passwd_agent); return (NULL); } - memset(retval, 0, sizeof(struct common_agent)); + memset(retval, 0, sizeof(struct agent)); - retval->parent.name = strdup("passwd"); - if (retval->parent.name == NULL) { + retval->name = strdup("passwd"); + if (retval->name == NULL) { free(retval); TRACE_OUT(init_passwd_agent); return (NULL); } - retval->parent.type = COMMON_AGENT; + retval->check_changes_func = passwd_check_changes_func; retval->lookup_func = passwd_lookup_func; - - TRACE_OUT(init_passwd_agent); - return ((struct agent *)retval); -} - -struct agent * -init_passwd_mp_agent() -{ - struct multipart_agent *retval; - - TRACE_IN(init_passwd_mp_agent); - retval = malloc(sizeof(struct multipart_agent)); - if (retval == NULL) { - TRACE_OUT(init_passwd_mp_agent); - return (NULL); - } - memset(retval, 0, sizeof(struct multipart_agent)); - - retval->parent.name = strdup("passwd"); - if (retval->parent.name == NULL) { - free(retval); - TRACE_OUT(init_passwd_mp_agent); - return (NULL); - } - retval->parent.type = MULTIPART_AGENT; retval->mp_init_func = passwd_mp_init_func; retval->mp_lookup_func = passwd_mp_lookup_func; retval->mp_keygen_func = passwd_mp_keygen_func; retval->mp_destroy_func = passwd_mp_destroy_func; - TRACE_OUT(init_passwd_mp_agent); - return ((struct agent *)retval); + TRACE_OUT(init_passwd_agent); + return (retval); } ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/passwd.h#6 (text) ==== @@ -27,4 +27,3 @@ */ extern struct agent *init_passwd_agent(); -extern struct agent *init_passwd_mp_agent(); ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/proto.c#6 (text+ko) ==== @@ -64,6 +64,7 @@ { NULL, 0 } }; +static int protocols_check_changes_func(void *); static int protocols_id_func(char *, size_t *, va_list, void *); static int protocols_marshal_func(char *, size_t *, void *, va_list, void *); static int protocols_lookup_func(const char *, size_t, char **, size_t *); @@ -83,6 +84,13 @@ #endif static int +protocols_check_changes_func(void *mdata) +{ + + return (standard_agent_file_check(_PATH_PROTOCOLS, NULL, mdata)); +} + +static int protocols_id_func(char *buffer, size_t *buffer_size, va_list ap, void *cache_mdata) { @@ -455,55 +463,30 @@ struct agent * init_protocols_agent() { - struct common_agent *retval; + struct agent *retval; TRACE_IN(init_protocols_agent); - retval = malloc(sizeof(struct common_agent)); + retval = malloc(sizeof(struct agent)); if (retval == NULL) { TRACE_OUT(init_protocols_agent); return (NULL); } - memset(retval, 0, sizeof(struct common_agent)); + memset(retval, 0, sizeof(struct agent)); - retval->parent.name = strdup("protocols"); - if (retval->parent.name == NULL) { + retval->name = strdup("protocols"); + if (retval->name == NULL) { free(retval); TRACE_OUT(init_protocols_agent); return (NULL); } - retval->parent.type = COMMON_AGENT; + retval->check_changes_func = protocols_check_changes_func; retval->lookup_func = protocols_lookup_func; - - TRACE_OUT(init_protocols_agent); - return ((struct agent *)retval); -} - -struct agent * -init_protocols_mp_agent() -{ - struct multipart_agent *retval; - - TRACE_IN(init_protocols_mp_agent); - retval = malloc(sizeof(struct multipart_agent)); - if (retval == NULL) { - TRACE_OUT(init_protocols_mp_agent); - return (NULL); - } - memset(retval, 0, sizeof(struct multipart_agent)); - - retval->parent.name = strdup("protocols"); - if (retval->parent.name == NULL) { - free(retval); - TRACE_OUT(init_protocols_mp_agent); - return (NULL); - } - retval->parent.type = MULTIPART_AGENT; retval->mp_init_func = protocols_mp_init_func; retval->mp_lookup_func = protocols_mp_lookup_func; retval->mp_keygen_func = protocols_mp_keygen_func; retval->mp_destroy_func = protocols_mp_destroy_func; - TRACE_OUT(init_protocols_mp_agent); - return ((struct agent *)retval); + TRACE_OUT(init_protocols_agent); + return (retval); } ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/proto.h#5 (text+ko) ==== @@ -27,4 +27,3 @@ */ extern struct agent *init_protocols_agent(); -extern struct agent *init_protocols_mp_agent(); ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/rpc.c#6 (text+ko) ==== @@ -68,6 +68,7 @@ { NULL, 0 } }; +static int rpc_check_changes_func(void *); static int rpc_id_func(char *, size_t *, va_list, void *); static int rpc_marshal_func(char *, size_t *, void *, va_list, void *); static int rpc_lookup_func(const char *, size_t, char **, size_t *); @@ -78,6 +79,13 @@ AGENT_DECLARE_BUFFER_TLS_HANDLING(rpcent); +static int +rpc_check_changes_func(void *mdata) +{ + + return (standard_agent_file_check("/etc/rpc", NULL, mdata)); +} + static int rpc_id_func(char *buffer, size_t *buffer_size, va_list ap, void *cache_mdata) { @@ -449,55 +457,30 @@ struct agent * init_rpc_agent() { - struct common_agent *retval; + struct agent *retval; TRACE_IN(init_rpc_agent); - retval = malloc(sizeof(struct common_agent)); + retval = malloc(sizeof(struct agent)); if (retval == NULL) { TRACE_OUT(init_rpc_agent); return (NULL); } - memset(retval, 0, sizeof(struct common_agent)); + memset(retval, 0, sizeof(struct agent)); - retval->parent.name = strdup("rpc"); - if (retval->parent.name == NULL) { + retval->name = strdup("rpc"); + if (retval->name == NULL) { free(retval); TRACE_OUT(init_rpc_agent); return (NULL); } - retval->parent.type = COMMON_AGENT; + retval->check_changes_func = rpc_check_changes_func; retval->lookup_func = rpc_lookup_func; - - TRACE_OUT(init_rpc_agent); - return ((struct agent *)retval); -} - -struct agent * -init_rpc_mp_agent() -{ - struct multipart_agent *retval; - - TRACE_IN(init_rpc_mp_agent); - retval = malloc(sizeof(struct multipart_agent)); - if (retval == NULL) { - TRACE_OUT(init_rpc_mp_agent); - return (NULL); - } - memset(retval, 0, sizeof(struct multipart_agent)); - - retval->parent.name = strdup("rpc"); - if (retval->parent.name == NULL) { - free(retval); - TRACE_OUT(init_rpc_mp_agent); - return (NULL); - } - retval->parent.type = MULTIPART_AGENT; retval->mp_init_func = rpc_mp_init_func; retval->mp_lookup_func = rpc_mp_lookup_func; retval->mp_keygen_func = rpc_mp_keygen_func; retval->mp_destroy_func = rpc_mp_destroy_func; - TRACE_OUT(init_rpc_mp_agent); - return ((struct agent *)retval); + TRACE_OUT(init_rpc_agent); + return (retval); } ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/rpc.h#5 (text+ko) ==== @@ -27,4 +27,3 @@ */ extern struct agent *init_rpc_agent(); -extern struct agent *init_rpc_mp_agent(); ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/services.c#7 (text) ==== @@ -64,6 +64,7 @@ { NULL, 0 } }; +static int services_check_changes_func(void *); static int services_id_func(char *, size_t *, va_list, void *); static int services_marshal_func(char *, size_t *, void *, va_list, void *); static int services_lookup_func(const char *, size_t, char **, size_t *); @@ -75,6 +76,13 @@ AGENT_DECLARE_BUFFER_TLS_HANDLING(servent); static int +services_check_changes_func(void *mdata) +{ + + return (standard_agent_file_check(_PATH_SERVICES, NULL, mdata)); +} + +static int services_id_func(char *buffer, size_t *buffer_size, va_list ap, void *cache_mdata) { @@ -529,55 +537,30 @@ struct agent * init_services_agent() { - struct common_agent *retval; + struct agent *retval; TRACE_IN(init_services_agent); - retval = malloc(sizeof(struct common_agent)); + retval = malloc(sizeof(struct agent)); if (retval == NULL) { TRACE_OUT(init_services_agent); return (NULL); } - memset(retval, 0, sizeof(struct common_agent)); + memset(retval, 0, sizeof(struct agent)); - retval->parent.name = strdup("services"); - if (retval->parent.name == NULL) { + retval->name = strdup("services"); + if (retval->name == NULL) { free(retval); TRACE_OUT(init_services_agent); return (NULL); } - retval->parent.type = COMMON_AGENT; + retval->check_changes_func = services_check_changes_func; retval->lookup_func = services_lookup_func; - - TRACE_OUT(init_services_agent); - return ((struct agent *)retval); -} - -struct agent * -init_services_mp_agent() -{ - struct multipart_agent *retval; - - TRACE_IN(init_services_mp_agent); - retval = malloc(sizeof(struct multipart_agent)); - if (retval == NULL) { - TRACE_OUT(init_services_mp_agent); - return (NULL); - } - memset(retval, 0, sizeof(struct multipart_agent)); - - retval->parent.name = strdup("services"); - if (retval->parent.name == NULL) { - free(retval); - TRACE_OUT(init_services_mp_agent); - return (NULL); - } - retval->parent.type = MULTIPART_AGENT; retval->mp_init_func = services_mp_init_func; retval->mp_lookup_func = services_mp_lookup_func; retval->mp_keygen_func = services_mp_keygen_func; retval->mp_destroy_func = services_mp_destroy_func; - TRACE_OUT(init_services_mp_agent); - return ((struct agent *)retval); + TRACE_OUT(init_services_agent); + return (retval); } ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/agents/services.h#6 (text) ==== @@ -27,4 +27,3 @@ */ extern struct agent *init_services_agent(); -extern struct agent *init_services_mp_agent(); ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/cached.c#11 (text) ==== @@ -299,7 +299,7 @@ static void precache_entries(struct configuration *config) { - struct multipart_agent *mp_agent; + struct agent *mp_agent; struct configuration_entry *entry; size_t entries_size, i; int res; @@ -309,8 +309,7 @@ for (i = 0; i < entries_size; ++i) { entry = configuration_get_entry(config, i); if (entry->flags & CONFIG_ENTRY_PRECACHING_ENABLED_FLAG) { - mp_agent = (struct multipart_agent *)find_agent( - s_agent_table, entry->name, MULTIPART_AGENT); + mp_agent = find_agent(s_agent_table, entry->name); if (mp_agent == NULL) { LOG_ERR_1("precache_entries", @@ -909,17 +908,12 @@ } res = register_agent(s_agent_table, init_passwd_agent()); - res |= register_agent(s_agent_table, init_passwd_mp_agent()); res |= register_agent(s_agent_table, init_group_agent()); - res |= register_agent(s_agent_table, init_group_mp_agent()); res |= register_agent(s_agent_table, init_hosts_agent()); res |= register_agent(s_agent_table, init_networks_agent()); res |= register_agent(s_agent_table, init_services_agent()); - res |= register_agent(s_agent_table, init_services_mp_agent()); res |= register_agent(s_agent_table, init_protocols_agent()); - res |= register_agent(s_agent_table, init_protocols_mp_agent()); res |= register_agent(s_agent_table, init_rpc_agent()); - res |= register_agent(s_agent_table, init_rpc_mp_agent()); if (res != 0) { LOG_ERR_1("main", "request agetns registration failed: " "not enough memory"); ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/config.c#7 (text) ==== @@ -179,6 +179,18 @@ TRACE_OUT(create_configuration_entry); return (NULL); } + + res = pthread_mutex_init(&retval->changes_mdata_lock, NULL); + if (res != 0) { + pthread_mutex_destroy(&retval->positive_cache_lock); + pthread_mutex_destroy(&retval->negative_cache_lock); + pthread_mutex_destroy(&retval->mp_cache_lock); + free(retval); + LOG_ERR_2("create_configuration_entry", + "can't create changes mdata lock"); + TRACE_OUT(create_configuration_entry); + return (NULL); + } memcpy(&retval->positive_cache_params, positive_params, sizeof(struct common_cache_entry_params)); @@ -276,11 +288,13 @@ pthread_mutex_destroy(&entry->positive_cache_lock); pthread_mutex_destroy(&entry->negative_cache_lock); pthread_mutex_destroy(&entry->mp_cache_lock); + pthread_mutex_destroy(&entry->changes_mdata_lock); free(entry->name); free(entry->positive_cache_params.entry_name); free(entry->negative_cache_params.entry_name); free(entry->mp_cache_params.entry_name); free(entry->mp_cache_entries); + free(entry->changes_mdata); free(entry); TRACE_OUT(destroy_configuration_entry); } @@ -515,6 +529,8 @@ case CELT_MULTIPART: pthread_mutex_lock(&entry->mp_cache_lock); break; + case CELT_CHANGES_MDATA: + pthread_mutex_lock(&entry->changes_mdata_lock); default: /* should be unreachable */ break; @@ -539,6 +555,9 @@ case CELT_MULTIPART: pthread_mutex_unlock(&entry->mp_cache_lock); break; + case CELT_CHANGES_MDATA: + pthread_mutex_unlock(&entry->changes_mdata_lock); + break; default: /* should be unreachable */ break; ==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/config.h#7 (text) ==== @@ -76,6 +76,9 @@ struct common_cache_entry_params negative_cache_params; struct mp_cache_entry_params mp_cache_params; + struct timeval common_query_timeout; + struct timeval mp_query_timeout; + /* * configuration_entry holds pointers for all actual cache_entries, * which are used for it. There is one for positive caching, one for @@ -88,13 +91,14 @@ cache_entry *mp_cache_entries; size_t mp_cache_entries_size; - struct timeval common_query_timeout; - struct timeval mp_query_timeout; - char *name; pthread_mutex_t positive_cache_lock; pthread_mutex_t negative_cache_lock; pthread_mutex_t mp_cache_lock; + pthread_mutex_t changes_mdata_lock; + + struct agent *query_agent; + void *changes_mdata; int flags; }; @@ -122,7 +126,8 @@ enum config_entry_lock_type { >>> TRUNCATED FOR MAIL (1000 lines) <<<
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200611171626.kAHGQnL1071886>