From de4805a6c8aa80514c894776c74609224f681576 Mon Sep 17 00:00:00 2001 From: zsx Date: Mon, 17 Sep 2018 18:44:27 +0800 Subject: [PATCH] fixed one bug in acl_ifconf.c for checking the UNIX path for matching. --- app/master/daemon/master/master_ent.cpp | 7 +- lib_acl/include/net/acl_valid_hostname.h | 1 + lib_acl/samples/cache2/main.c | 74 ++-- lib_acl/samples/cache2/valgrind.sh | 2 +- lib_acl/src/net/acl_ifconf.c | 4 +- lib_acl/src/net/acl_sane_inet.c | 2 +- lib_acl/src/net/acl_valid_hostname.c | 5 + lib_acl/src/net/acl_vstream_net.c | 8 +- lib_acl/src/stdlib/common/acl_cache2.c | 409 +++++++++++------------ packaging/acl-libs.spec | 6 +- 10 files changed, 279 insertions(+), 239 deletions(-) mode change 100644 => 100755 lib_acl/samples/cache2/valgrind.sh diff --git a/app/master/daemon/master/master_ent.cpp b/app/master/daemon/master/master_ent.cpp index 59e29000a..f69c62d0e 100644 --- a/app/master/daemon/master/master_ent.cpp +++ b/app/master/daemon/master/master_ent.cpp @@ -340,7 +340,12 @@ static int service_sock(ACL_XINETD_CFG_PARSER *xcp, ACL_MASTER_SERV *serv) return -1; } - ifconf = acl_ifconf_search(name); + ifconf = acl_ifconf_search(name); + if (ifconf == NULL) { + acl_msg_error("%s(%d), %s: ifconf NULL, no match for name=%s", + __FILE__, __LINE__, __FUNCTION__, name); + return -1; + } serv->name = acl_mystrdup(name); serv->type = ACL_MASTER_SERV_TYPE_SOCK; serv->addrs = acl_array_create(1); diff --git a/lib_acl/include/net/acl_valid_hostname.h b/lib_acl/include/net/acl_valid_hostname.h index e66e94e78..892a9d43b 100644 --- a/lib_acl/include/net/acl_valid_hostname.h +++ b/lib_acl/include/net/acl_valid_hostname.h @@ -18,6 +18,7 @@ ACL_API int acl_valid_hostname(const char *, int); ACL_API int acl_valid_hostaddr(const char *, int); ACL_API int acl_valid_ipv4_hostaddr(const char *, int); ACL_API int acl_valid_ipv6_hostaddr(const char *, int); +ACL_API int acl_valid_unix(const char *); #ifdef __cplusplus } diff --git a/lib_acl/samples/cache2/main.c b/lib_acl/samples/cache2/main.c index 97994c1e7..7c5d1197e 100644 --- a/lib_acl/samples/cache2/main.c +++ b/lib_acl/samples/cache2/main.c @@ -35,7 +35,8 @@ static void walk_fn(ACL_CACHE2_INFO *info, void *arg acl_unused) { MYOBJ *o = (MYOBJ*) info->value; - printf("%s: size: %d; when_timeout: %ld\n", info->key, o->len, (long) info->when_timeout); + printf("%s: size: %d; when_timeout: %ld\n", + info->key, o->len, (long) info->when_timeout); } static void test1(int n, int timeout) @@ -58,9 +59,11 @@ static void test1(int n, int timeout) printf("\nfirst walk cache, cache size: %d\n", acl_cache2_size(cache)); acl_cache2_walk(cache, walk_fn, NULL); - printf("\nfirst call acl_cache2_timeout, size: %d\n", acl_cache2_size(cache)); + printf("\nfirst call acl_cache2_timeout, size: %d\n", + acl_cache2_size(cache)); acl_cache2_timeout(cache); - printf(">>>after first acl_cache2_timeout, second walk cache, cache's size: %d\n", acl_cache2_size(cache)); + printf(">>>after first acl_cache2_timeout, second walk cache, " + "cache's size: %d\n", acl_cache2_size(cache)); acl_cache2_walk(cache, walk_fn, NULL); printf("\n"); @@ -70,9 +73,11 @@ static void test1(int n, int timeout) sleep(1); } - printf("\nsecond call acl_cache_timeout, size: %d\n", acl_cache2_size(cache)); + printf("\nsecond call acl_cache_timeout, size: %d\n", + acl_cache2_size(cache)); acl_cache2_timeout(cache); - printf(">>>after second acl_cache_timeout, third walk_cache, cache's size: %d\n", acl_cache2_size(cache)); + printf(">>>after second acl_cache_timeout, third walk_cache, cache's " + "size: %d\n", acl_cache2_size(cache)); acl_cache2_walk(cache, walk_fn, NULL); o = (MYOBJ*) acl_cache2_find(cache, "key(5)"); @@ -85,7 +90,8 @@ static void test1(int n, int timeout) printf("\n>>>key(11) not exist\n"); else { o = (MYOBJ*) info->value; - printf("\n>>>key(11): len: %d, when_timeout: %ld\n", o->len, (long) info->when_timeout); + printf("\n>>>key(11): len: %d, when_timeout: %ld\n", + o->len, (long) info->when_timeout); } printf("\nfree cache, size: %d\n", acl_cache2_size(cache)); @@ -126,46 +132,68 @@ static void test3(int n, int timeout) int i; ACL_ITER iter; - printf(">>> total add: %d\n", n * 2); + printf(">>>total add: %d\r\n", n * 2); cache = acl_cache2_create(n * 2, free_fn); for (i = 0; i < n; i++) { - o = myobj_new(2 * i + 1); - snprintf(key, sizeof(key), "key(%d)", 2 * i + 1); + snprintf(key, sizeof(key), "key-%d", 2 * i + 1); info = (ACL_CACHE2_INFO*) acl_cache2_find(cache, key); - if (info != NULL) - printf("the key: %s exist\n", key); - printf("add one: %s, timeout: %d\n", key, timeout); - assert(acl_cache2_enter(cache, key, o, timeout)); + if (info != NULL) { + printf("ALREADY EXIST, key=%s\r\n", key); + exit (1); + } + + o = myobj_new(2 * i + 1); + if (acl_cache2_enter(cache, key, o, timeout) == NULL) { + printf("ADD ERROR, key=%s\r\n", key); + exit (1); + } else { + printf("add ok, key=%s, timeout=%d\r\n", key, timeout); + } + + info = (ACL_CACHE2_INFO *) acl_cache2_find(cache, key); + if (info == NULL) { + printf("NOT FOUND, key=%s\r\n", key); + exit (1); + } o = myobj_new(2 * i + 2); - snprintf(key, sizeof(key), "key(%d)", 2 * i + 2); + snprintf(key, sizeof(key), "key-%d", 2 * i + 2); info = (ACL_CACHE2_INFO*) acl_cache2_find(cache, key); - if (info != NULL) - printf("the key: %s exist\n", key); - printf("add one: %s, timeout: %d\n", key, timeout); - assert(acl_cache2_enter(cache, key, o, timeout)); + if (info != NULL) { + printf("ALREADY EXIST, the key: %s exist\r\n", key); + exit (1); + } + + if (acl_cache2_enter(cache, key, o, timeout) == NULL) { + printf("ADD ERROR, key=%s\r\n", key); + exit (1); + } + printf("add ok, key=%s, timeout: %d\r\n", key, timeout); } - printf(">>>>acl_foreach\n"); + printf("\r\n>>>>acl_foreach\r\n"); acl_foreach(iter, cache) { o = (MYOBJ*) iter.data; info = (ACL_CACHE2_INFO*) acl_iter_info(iter, cache); - printf(">>>len=%d, key=%s\n", o->len, info->key); + printf(">>>len=%d, key=%s\r\n", o->len, info->key); } + printf("\r\n>>>>free all cache nodes\r\n"); acl_cache2_free(cache); } - static void usage(const char *procname) { - printf("usage: %s -h [help] -n max_size -t timeout -c cmd[test1|test2|test3]\n", procname); + printf("usage: %s -h [help]\r\n" + " -n max_size\r\n" + " -t timeout\r\n" + " -c cmd[test1|test2|test3, default: test3]\n", procname); } int main(int argc, char *argv[]) { - int n = 100, ch, timeout = 1; + int n = 10, ch, timeout = 1; char cmd[256]; ACL_SAFE_STRNCPY(cmd, "test3", sizeof(cmd)); diff --git a/lib_acl/samples/cache2/valgrind.sh b/lib_acl/samples/cache2/valgrind.sh old mode 100644 new mode 100755 index 823d6a8a8..c39559b95 --- a/lib_acl/samples/cache2/valgrind.sh +++ b/lib_acl/samples/cache2/valgrind.sh @@ -1,2 +1,2 @@ #!/bin/sh -valgrind --tool=memcheck --leak-check=yes --show-reachable=yes -v ./cache -n 10 -t 10 +valgrind --tool=memcheck --leak-check=yes --show-reachable=yes -v ./cache2 -n 10 -t 10 diff --git a/lib_acl/src/net/acl_ifconf.c b/lib_acl/src/net/acl_ifconf.c index 243f77975..a961a42ed 100644 --- a/lib_acl/src/net/acl_ifconf.c +++ b/lib_acl/src/net/acl_ifconf.c @@ -633,11 +633,11 @@ ACL_IFCONF *acl_ifconf_search(const char *patterns) patterns_match_add(patterns_tokens, ifaddr, addrs); } -#ifdef ACL_UNIX +#ifdef AF_UNIX /* just for all unix domain path */ acl_foreach(iter, patterns_tokens) { const char *pattern = (const char *) iter.data; - if (*pattern == '/' || (*pattern == '.' && *pattern == '/')) { + if (acl_valid_unix(pattern)) { ACL_IFADDR *ifaddr = (ACL_IFADDR *) acl_mycalloc(1, sizeof(ACL_IFADDR)); diff --git a/lib_acl/src/net/acl_sane_inet.c b/lib_acl/src/net/acl_sane_inet.c index e47f26419..3baad5f50 100644 --- a/lib_acl/src/net/acl_sane_inet.c +++ b/lib_acl/src/net/acl_sane_inet.c @@ -297,7 +297,7 @@ size_t acl_sane_pton(const char *src, struct sockaddr *dst) af = AF_INET; else if (acl_valid_ipv6_hostaddr(src, 0)) af = AF_INET6; - else if (*src == '/') + else if (acl_valid_unix(src)) af = AF_UNIX; else return 0; diff --git a/lib_acl/src/net/acl_valid_hostname.c b/lib_acl/src/net/acl_valid_hostname.c index 44b56cf46..e067e37c1 100644 --- a/lib_acl/src/net/acl_valid_hostname.c +++ b/lib_acl/src/net/acl_valid_hostname.c @@ -101,6 +101,11 @@ int acl_valid_hostname(const char *name, int gripe) return 1; } +int acl_valid_unix(const char *addr) +{ + return !acl_valid_hostaddr(addr, 0); +} + /* acl_valid_hostaddr - verify numerical address syntax */ int acl_valid_hostaddr(const char *addr, int gripe) diff --git a/lib_acl/src/net/acl_vstream_net.c b/lib_acl/src/net/acl_vstream_net.c index e16723f22..3a9a0ac3a 100644 --- a/lib_acl/src/net/acl_vstream_net.c +++ b/lib_acl/src/net/acl_vstream_net.c @@ -43,9 +43,9 @@ ACL_VSTREAM *acl_vstream_listen_ex(const char *addr, int qlen, return NULL; } -#ifdef ACL_UNIX +#ifdef AF_UNIX /* this maybe unix addr, such as '/home/test/listen.sock' */ - if (*addr == '/' || (*addr == '.' && *(addr + 1) == '/')) { + if (acl_valid_unix(addr)) { listenfd = acl_unix_listen(addr, qlen, 0); if (listenfd == ACL_SOCKET_INVALID) return NULL; @@ -177,8 +177,8 @@ ACL_VSTREAM *acl_vstream_connect_ex(const char *addr, if (addr == NULL || *addr == 0) acl_msg_fatal("%s: addr null", myname); -#if defined(ACL_UNIX) - if (*addr == '/' || (*addr == '.' && *(addr + 1) == '/')) +#if defined(AF_UNIX) + if (acl_valid_unix(addr)) connfd = acl_unix_connect(addr, block_mode, connect_timeout); else #endif diff --git a/lib_acl/src/stdlib/common/acl_cache2.c b/lib_acl/src/stdlib/common/acl_cache2.c index 4c34659bb..cbad539e8 100644 --- a/lib_acl/src/stdlib/common/acl_cache2.c +++ b/lib_acl/src/stdlib/common/acl_cache2.c @@ -23,193 +23,193 @@ typedef struct CACHE_INFO CACHE_INFO; typedef struct TREE_NODE { CACHE_INFO *head; CACHE_INFO *tail; - avl_node_t node; + avl_node_t node; time_t when_timeout; } TREE_NODE; struct CACHE_INFO { ACL_CACHE2_INFO info; - TREE_NODE *tree_node; + TREE_NODE *tree_node; CACHE_INFO *prev; CACHE_INFO *next; }; +static void *cache_iter_head(ACL_ITER *iter, struct ACL_CACHE2 *cache2) +{ + CACHE *cache = (CACHE*) cache2; + CACHE_INFO *info; + TREE_NODE *pnode; + + iter->dlen = -1; + iter->i = 0; + iter->size = cache2->size; + + pnode = avl_first(&cache->avl); + if (pnode == NULL) { + iter->ptr = NULL; + iter->data = NULL; + iter->key = NULL; + return iter->ptr; + } + + iter->ptr = info = pnode->head; + acl_assert(info); + iter->data = ((ACL_CACHE2_INFO *) info)->value; + iter->key = ((ACL_CACHE2_INFO *) info)->key; + return iter->ptr; +} + +static void *cache_iter_next(ACL_ITER *iter, struct ACL_CACHE2 *cache2) +{ + CACHE *cache = (CACHE*) cache2; + CACHE_INFO *info = (CACHE_INFO*) iter->ptr; + TREE_NODE *pnode = info->tree_node; + + info = info->next; + if (info) { + iter->ptr = info; + iter->data = ((ACL_CACHE2_INFO *) info)->value; + iter->key = ((ACL_CACHE2_INFO *) info)->key; + iter->i++; + return iter->ptr; + } + + pnode = AVL_NEXT(&cache->avl, pnode); + if (pnode == NULL) { + iter->ptr = NULL; + iter->data = NULL; + iter->key = NULL; + return iter->ptr; + } + + iter->ptr = info = pnode->head; + acl_assert(info); + iter->data = ((ACL_CACHE2_INFO *) info)->value; + iter->key = ((ACL_CACHE2_INFO *) info)->key; + iter->i++; + return iter->ptr; +} + +static void *cache_iter_tail(ACL_ITER *iter, struct ACL_CACHE2 *cache2) +{ + CACHE *cache = (CACHE*) cache2; + CACHE_INFO *info; + TREE_NODE *pnode; + + iter->dlen = -1; + iter->i = cache2->size - 1; + iter->size = cache2->size; + + pnode = avl_last(&cache->avl); + if (pnode == NULL) { + iter->ptr = NULL; + iter->data = NULL; + iter->key = NULL; + return iter->ptr; + } + + iter->ptr = info = pnode->tail; + acl_assert(info); + iter->data = ((ACL_CACHE2_INFO *) info)->value; + iter->key = ((ACL_CACHE2_INFO *) info)->key; + return iter->ptr; +} + +static void *cache_iter_prev(ACL_ITER *iter, struct ACL_CACHE2 *cache2) +{ + CACHE *cache = (CACHE*) cache2; + CACHE_INFO *info = (CACHE_INFO*) iter->ptr; + TREE_NODE *pnode = info->tree_node; + + info = info->prev; + if (info) { + iter->ptr = info; + iter->data = ((ACL_CACHE2_INFO *) info)->value; + iter->key = ((ACL_CACHE2_INFO *) info)->key; + iter->i++; + return iter->ptr; + } + + pnode = AVL_PREV(&cache->avl, pnode); + if (pnode == NULL) { + iter->ptr = NULL; + iter->data = NULL; + iter->key = NULL; + return iter->ptr; + } + + iter->ptr = info = pnode->tail; + acl_assert(info); + iter->data = ((ACL_CACHE2_INFO *) info)->value; + iter->key = ((ACL_CACHE2_INFO *) info)->key; + iter->i++; + return iter->ptr; +} + +static ACL_CACHE2_INFO *cache_iter_info(ACL_ITER *iter, + struct ACL_CACHE2 *cache2 acl_unused) +{ + if (iter->ptr == NULL) + return NULL; + return (ACL_CACHE2_INFO*) iter->ptr; +} + /** * AVL 用的比较回调函数 */ -static int cmp_fn(const void *v1, const void *v2) +static int avl_cmp_fn(const void *v1, const void *v2) { const TREE_NODE *n1 = (const TREE_NODE*) v1; const TREE_NODE *n2 = (const TREE_NODE*) v2; time_t ret = n1->when_timeout - n2->when_timeout; if (ret < 0) - return (-1); + return -1; else if (ret > 0) - return (1); + return 1; else - return (0); -} - -static void *cache_iter_head(ACL_ITER *iter, struct ACL_CACHE2 *cache2) -{ - CACHE *cache = (CACHE*) cache2; - CACHE_INFO *info; - TREE_NODE *pnode; - - iter->dlen = -1; - iter->i = 0; - iter->size = cache2->size; - - pnode = avl_first(&cache->avl); - if (pnode == NULL) { - iter->ptr = NULL; - iter->data = NULL; - iter->key = NULL; - return (iter->ptr); - } - - iter->ptr = info = pnode->head; - acl_assert(info); - iter->data = ((ACL_CACHE2_INFO *) info)->value; - iter->key = ((ACL_CACHE2_INFO *) info)->key; - return (iter->ptr); -} - -static void *cache_iter_next(ACL_ITER *iter, struct ACL_CACHE2 *cache2) -{ - CACHE *cache = (CACHE*) cache2; - CACHE_INFO *info = (CACHE_INFO*) iter->ptr; - TREE_NODE *pnode = info->tree_node; - - info = info->next; - if (info) { - iter->ptr = info; - iter->data = ((ACL_CACHE2_INFO *) info)->value; - iter->key = ((ACL_CACHE2_INFO *) info)->key; - iter->i++; - return (iter->ptr); - } - - pnode = AVL_NEXT(&cache->avl, pnode); - if (pnode == NULL) { - iter->ptr = NULL; - iter->data = NULL; - iter->key = NULL; - return (iter->ptr); - } - - iter->ptr = info = pnode->head; - acl_assert(info); - iter->data = ((ACL_CACHE2_INFO *) info)->value; - iter->key = ((ACL_CACHE2_INFO *) info)->key; - iter->i++; - return (iter->ptr); -} - -static void *cache_iter_tail(ACL_ITER *iter, struct ACL_CACHE2 *cache2) -{ - CACHE *cache = (CACHE*) cache2; - CACHE_INFO *info; - TREE_NODE *pnode; - - iter->dlen = -1; - iter->i = cache2->size - 1; - iter->size = cache2->size; - - pnode = avl_last(&cache->avl); - if (pnode == NULL) { - iter->ptr = NULL; - iter->data = NULL; - iter->key = NULL; - return (iter->ptr); - } - - iter->ptr = info = pnode->tail; - acl_assert(info); - iter->data = ((ACL_CACHE2_INFO *) info)->value; - iter->key = ((ACL_CACHE2_INFO *) info)->key; - return (iter->ptr); -} - -static void *cache_iter_prev(ACL_ITER *iter, struct ACL_CACHE2 *cache2) -{ - CACHE *cache = (CACHE*) cache2; - CACHE_INFO *info = (CACHE_INFO*) iter->ptr; - TREE_NODE *pnode = info->tree_node; - - info = info->prev; - if (info) { - iter->ptr = info; - iter->data = ((ACL_CACHE2_INFO *) info)->value; - iter->key = ((ACL_CACHE2_INFO *) info)->key; - iter->i++; - return (iter->ptr); - } - - pnode = AVL_PREV(&cache->avl, pnode); - if (pnode == NULL) { - iter->ptr = NULL; - iter->data = NULL; - iter->key = NULL; - return (iter->ptr); - } - - iter->ptr = info = pnode->tail; - acl_assert(info); - iter->data = ((ACL_CACHE2_INFO *) info)->value; - iter->key = ((ACL_CACHE2_INFO *) info)->key; - iter->i++; - return (iter->ptr); -} - -static ACL_CACHE2_INFO *cache_iter_info(ACL_ITER *iter, struct ACL_CACHE2 *cache2 acl_unused) -{ - if (iter->ptr == NULL) - return (NULL); - return ((ACL_CACHE2_INFO*) iter->ptr); + return 0; } ACL_CACHE2 *acl_cache2_create(int max_size, void (*free_fn)(const ACL_CACHE2_INFO*, void*)) { - const char *myname = "acl_cache2_create"; ACL_CACHE2 *cache2; - CACHE *cache; + CACHE *cache; if (max_size <= 0) { acl_msg_info("%s(%d): max_size(%d), no need cache", - myname, __LINE__, max_size); - return (NULL); + __FUNCTION__, __LINE__, max_size); + return NULL; } if (free_fn == NULL) acl_msg_info("%s(%d), %s: free_fn null", - __FILE__, __LINE__, myname); + __FILE__, __LINE__, __FUNCTION__); cache = (CACHE *) acl_mycalloc(1, sizeof(CACHE)); - cache->table = acl_htable_create(100, 0); - avl_create(&cache->avl, cmp_fn, sizeof(TREE_NODE), offsetof(TREE_NODE, node)); + cache->table = acl_htable_create(max_size, 0); + avl_create(&cache->avl, avl_cmp_fn, sizeof(TREE_NODE), + offsetof(TREE_NODE, node)); acl_pthread_mutex_init(&cache->lock, NULL); cache2 = (ACL_CACHE2*) cache; - cache2->max_size = max_size < 1 ? 1 : max_size; - cache2->free_fn = free_fn; + cache2->max_size = max_size < 1 ? 1 : max_size; + cache2->free_fn = free_fn; cache2->iter_head = cache_iter_head; cache2->iter_next = cache_iter_next; cache2->iter_tail = cache_iter_tail; cache2->iter_prev = cache_iter_prev; cache2->iter_info = cache_iter_info; - return (cache2); + return cache2; } void acl_cache2_free(ACL_CACHE2 *cache2) { - const char *myname = "acl_cache2_free"; - CACHE *cache = (CACHE*) cache2; - TREE_NODE *pnode; + CACHE *cache = (CACHE*) cache2; + TREE_NODE *pnode; ACL_CACHE2_INFO *info2; - CACHE_INFO *info; + CACHE_INFO *info; if (cache == NULL) return; @@ -220,10 +220,11 @@ void acl_cache2_free(ACL_CACHE2 *cache2) pnode = AVL_NEXT(&cache->avl, pnode); while (info) { info2 = (ACL_CACHE2_INFO*) info; - info = info->next; + info = info->next; if (info2->nrefer > 0) { acl_msg_warn("%s(%d): key(%s)'s nrefer(%d) > 0", - myname, __LINE__, info2->key, info2->nrefer); + __FUNCTION__, __LINE__, + info2->key, info2->nrefer); info2->nrefer = 0; /* force to set 0 */ } (void) acl_cache2_delete(cache2, info2); @@ -239,34 +240,32 @@ void acl_cache2_free(ACL_CACHE2 *cache2) ACL_CACHE2_INFO *acl_cache2_enter(ACL_CACHE2 *cache2, const char *key, void *value, int timeout) { - const char *myname = "acl_cache2_enter"; - CACHE *cache = (CACHE *) cache2; + CACHE *cache = (CACHE *) cache2; ACL_CACHE2_INFO *info2; - CACHE_INFO *info; - TREE_NODE *pnode, node; + CACHE_INFO *info; + TREE_NODE *pnode, node; time_t when_timeout = time(NULL) + timeout; if (cache == NULL) - return (NULL); + return NULL; info2 = (ACL_CACHE2_INFO*) acl_htable_find(cache->table, key); if (info2 != NULL) { if (info2->nrefer > 0) { - acl_msg_warn("%s(%d): key(%s)'s old's" - " value's refer(%d) > 0", - myname, __LINE__, key, info2->nrefer); - return (NULL); + acl_msg_warn("%s(%d): key(%s)'s old's value's " + "refer(%d) > 0", __FUNCTION__, __LINE__, + key, info2->nrefer); + return NULL; } if (cache2->free_fn) cache2->free_fn(info2, info2->value); info2->value = value; - return (info2); + return info2; } /* 如果发现缓存池溢出,则优先采用过期策略 */ - if (cache2->size >= cache2->max_size) { + if (cache2->size >= cache2->max_size) (void) acl_cache2_timeout(cache2); - } /* 如果依然发现缓存池溢出,则采用删除最旧的数据策略 */ if (cache2->size >= cache2->max_size) { @@ -277,11 +276,11 @@ ACL_CACHE2_INFO *acl_cache2_enter(ACL_CACHE2 *cache2, pnode = AVL_NEXT(&cache->avl, pnode); continue; } - info = pnode->head; + info = pnode->head; pnode = AVL_NEXT(&cache->avl, pnode); while (info) { info2 = (ACL_CACHE2_INFO*) info; - info = info->next; + info = info->next; if (info2->nrefer == 0) { tmp = info2; break; @@ -297,9 +296,9 @@ ACL_CACHE2_INFO *acl_cache2_enter(ACL_CACHE2 *cache2, /* 如果缓存池还是处于溢出状态,则直接返回不进行任务添加 */ if (cache2->size >= cache2->max_size) { acl_msg_error("%s(%d): cache->size(%d) >= cache->max_size(%d)" - ", add key(%s) error", myname, __LINE__, + ", add key(%s) error", __FUNCTION__, __LINE__, cache2->size, cache2->max_size, key); - return (NULL); + return NULL; } node.when_timeout = timeout > 0 ? when_timeout : 0; @@ -310,18 +309,18 @@ ACL_CACHE2_INFO *acl_cache2_enter(ACL_CACHE2 *cache2, avl_add(&cache->avl, pnode); } - info = (CACHE_INFO*) acl_mycalloc(1, sizeof(CACHE_INFO)); + info = (CACHE_INFO*) acl_mycalloc(1, sizeof(CACHE_INFO)); info2 = (ACL_CACHE2_INFO*) info; info2->value = value; - info2->key = acl_mystrdup(key); + info2->key = acl_mystrdup(key); if (acl_htable_enter(cache->table, key, (char*) info2) == NULL) { acl_msg_fatal("%s(%d): add key(%s) to htable error(%s)", - myname, __LINE__, key, acl_last_serror()); + __FUNCTION__, __LINE__, key, acl_last_serror()); } if (pnode->tail == NULL) { - info->prev = info->next = NULL; + info->prev = info->next = NULL; pnode->head = pnode->tail = info; } else { pnode->tail->next = info; @@ -329,11 +328,11 @@ ACL_CACHE2_INFO *acl_cache2_enter(ACL_CACHE2 *cache2, info->next = NULL; pnode->tail = info; } - info->tree_node = pnode; + info->tree_node = pnode; info2->when_timeout = pnode->when_timeout; cache2->size++; - return (info2); + return info2; } void *acl_cache2_find(ACL_CACHE2 *cache2, const char *key) @@ -342,13 +341,13 @@ void *acl_cache2_find(ACL_CACHE2 *cache2, const char *key) ACL_CACHE2_INFO *info; if (cache2 == NULL || cache2->max_size <= 0) - return (NULL); + return NULL; info = (ACL_CACHE2_INFO*) acl_htable_find(cache->table, key); if (info != NULL) - return (info->value); + return info->value; else - return (NULL); + return NULL; } ACL_CACHE2_INFO *acl_cache2_locate(ACL_CACHE2 *cache2, const char *key) @@ -357,13 +356,13 @@ ACL_CACHE2_INFO *acl_cache2_locate(ACL_CACHE2 *cache2, const char *key) CACHE *cache = (CACHE*) cache2; if (cache2 == NULL || cache2->max_size <= 0) - return (NULL); + return NULL; info = (ACL_CACHE2_INFO*) acl_htable_find(cache->table, key); if (info != NULL) return (info); else - return (NULL); + return NULL; } int acl_cache2_delete(ACL_CACHE2 *cache2, ACL_CACHE2_INFO *info2) @@ -373,21 +372,21 @@ int acl_cache2_delete(ACL_CACHE2 *cache2, ACL_CACHE2_INFO *info2) CACHE *cache = (CACHE*) cache2; if (cache2 == NULL || cache2->max_size <= 0) - return (0); + return 0; if (info2->nrefer > 0) - return (-1); + return -1; if (acl_htable_delete(cache->table, info2->key, NULL) < 0) - return (-1); + return -1; if (info->prev) info->prev->next = info->next; else - pnode->head = info->next; + pnode->head = info->next; if (info->next) info->next->prev = info->prev; else - pnode->tail = info->prev; + pnode->tail = info->prev; if (cache2->free_fn) cache2->free_fn(info2, info2->value); @@ -399,36 +398,36 @@ int acl_cache2_delete(ACL_CACHE2 *cache2, ACL_CACHE2_INFO *info2) avl_remove(&cache->avl, pnode); acl_myfree(pnode); } - return (0); + return 0; } int acl_cache2_delete2(ACL_CACHE2 *cache2, const char *key) { - CACHE *cache = (CACHE*) cache2; + CACHE *cache = (CACHE*) cache2; ACL_CACHE2_INFO *info2; if (cache2 == NULL || cache2->max_size <= 0) - return (0); + return 0; info2 = (ACL_CACHE2_INFO*) acl_htable_find(cache->table, key); if (info2 == NULL) - return (-1); + return -1; if (info2->nrefer > 0) - return (-1); - return (acl_cache2_delete(cache2, info2)); + return -1; + return acl_cache2_delete(cache2, info2); } int acl_cache2_timeout(ACL_CACHE2 *cache2) { - CACHE *cache = (CACHE*) cache2; + CACHE *cache = (CACHE*) cache2; ACL_CACHE2_INFO *info2; - CACHE_INFO *info; - TREE_NODE *pnode, *pnode_next; + CACHE_INFO *info; + TREE_NODE *pnode, *pnode_next; time_t now = time(NULL); int n = 0; if (cache2 == NULL || cache2->max_size <= 0) - return (n); + return n; pnode = (TREE_NODE*) avl_first(&cache->avl); while (1) { @@ -439,10 +438,10 @@ int acl_cache2_timeout(ACL_CACHE2 *cache2) continue; } pnode_next = AVL_NEXT(&cache->avl, pnode); - info = pnode->head; + info = pnode->head; while (info) { info2 = (ACL_CACHE2_INFO*) info; - info = info->next; + info = info->next; if (info2->nrefer > 0) continue; if (acl_cache2_delete(cache2, info2) == 0) @@ -450,14 +449,14 @@ int acl_cache2_timeout(ACL_CACHE2 *cache2) } pnode = pnode_next; } - return (n); + return n; } void acl_cache2_update2(ACL_CACHE2 *cache2, ACL_CACHE2_INFO *info2, int timeout) { - CACHE *cache = (CACHE*) cache2; - CACHE_INFO *info = (CACHE_INFO*) info2; - TREE_NODE *pnode = info->tree_node, node; + CACHE *cache = (CACHE*) cache2; + CACHE_INFO *info = (CACHE_INFO*) info2; + TREE_NODE *pnode = info->tree_node, node; if (cache2 == NULL || cache2->max_size <= 0) return; @@ -465,11 +464,11 @@ void acl_cache2_update2(ACL_CACHE2 *cache2, ACL_CACHE2_INFO *info2, int timeout) if (info->prev) info->prev->next = info->next; else - pnode->head = info->next; + pnode->head = info->next; if (info->next) info->next->prev = info->prev; else - pnode->tail = info->prev; + pnode->tail = info->prev; if (pnode->head == NULL) { avl_remove(&cache->avl, pnode); @@ -485,15 +484,15 @@ void acl_cache2_update2(ACL_CACHE2 *cache2, ACL_CACHE2_INFO *info2, int timeout) } if (pnode->tail == NULL) { - info->prev = info->next = NULL; + info->prev = info->next = NULL; pnode->head = pnode->tail = info; } else { pnode->tail->next = info; - info->prev = pnode->tail; - info->next = NULL; - pnode->tail = info; + info->prev = pnode->tail; + info->next = NULL; + pnode->tail = info; } - info->tree_node = pnode; + info->tree_node = pnode; info2->when_timeout = pnode->when_timeout; } @@ -545,12 +544,10 @@ void acl_cache2_unrefer2(ACL_CACHE2 *cache2, const char *key) void acl_cache2_unrefer(ACL_CACHE2_INFO *info2) { - const char *myname = "acl_cache2_unrefer"; - info2->nrefer--; if (info2->nrefer < 0) acl_msg_warn("%s(%d): key(%s)'s nrefer(%d) invalid", - myname, __LINE__, info2->key, info2->nrefer); + __FUNCTION__, __LINE__, info2->key, info2->nrefer); } void acl_cache2_lock(ACL_CACHE2 *cache2) @@ -600,31 +597,31 @@ int acl_cache2_clean(ACL_CACHE2 *cache2, int force) CACHE *cache = (CACHE*) cache2; ACL_CACHE2_INFO *info2; CACHE_INFO *info; - TREE_NODE *pnode; + TREE_NODE *pnode; int n = 0; if (cache2 == NULL || cache2->max_size <= 0) - return (0); + return 0; pnode = (TREE_NODE*) avl_first(&cache->avl); while (pnode) { - info = pnode->head; + info = pnode->head; pnode = AVL_NEXT(&cache->avl, pnode); while (info) { info2 = (ACL_CACHE2_INFO*) info; - info = info->next; + info = info->next; if (info2->nrefer > 0 && force == 0) continue; if (acl_cache2_delete(cache2, info2) == 0) n++; } } - return (n); + return n; } int acl_cache2_size(ACL_CACHE2 *cache2) { if (cache2 == NULL || cache2->max_size <= 0) - return (0); - return (cache2->size); + return 0; + return cache2->size; } diff --git a/packaging/acl-libs.spec b/packaging/acl-libs.spec index f66df332e..37c540f39 100644 --- a/packaging/acl-libs.spec +++ b/packaging/acl-libs.spec @@ -1,4 +1,4 @@ -%define release_id 21 +%define release_id 22 Summary: The powerful c/c++ library and server framework Name: acl-libs @@ -133,6 +133,10 @@ fi %changelog +* Sun Sep 16 2018 zhengshuxin@qiyi.com 3.4.1-22-20180916.18 +- bugfix: acl_ifconf.c and some modules can't justify some UNIX path that + acl_master can't handle UNIX path like "master.sock" which hasn't '/' in it. + * Sun Sep 16 2018 zhengshuxin@qiyi.com 3.4.1-21-20180916.21 - feature: support IPV6 OK!