From dca65c0d8c66fcfa54f6d8dfaeb2b6ef9bd74b0f Mon Sep 17 00:00:00 2001 From: fengweihao Date: Wed, 22 Aug 2018 14:03:27 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9Make=20tarball=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=AE=89=E8=A3=85=E5=8C=85=E6=96=87=E4=BB=B6=E9=97=AE?= =?UTF-8?q?=E9=A2=98=202.=E4=BF=AE=E6=94=B9=E5=87=BD=E6=95=B0=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Makefile | 4 ++-- src/cert_session.c | 47 ++++++++++++++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/Makefile b/src/Makefile index f093a1c..3757432 100644 --- a/src/Makefile +++ b/src/Makefile @@ -71,8 +71,8 @@ tarball: cert_store if [ ! -d "package/bin" ]; then mkdir -p "package/bin"; fi if [ ! -d "package/lib" ]; then mkdir -p "package/lib"; fi if [ ! -d "package/etc" ]; then mkdir -p "package/etc"; fi - cp cert_store package/bin/cert_store - #cp ../lib/*.a package/lib/ + cp cert_store package/bin/certstore + cp lib/*.a package/lib/ cp ../conf/cert_store.ini package/etc/ cd package && tar cpfz cert_store-$(BUILD_FINGERPRINT2).tar.gz bin etc lib Makefile cd .. diff --git a/src/cert_session.c b/src/cert_session.c index 0a2524e..709890b 100644 --- a/src/cert_session.c +++ b/src/cert_session.c @@ -1059,19 +1059,31 @@ finish: return; } -int redis_sync_int(struct redisContext **c) +int redis_sync_init(struct redisContext **c) { + int xret = -1; struct config_bucket_t *redis = cert_default_config(); struct timeval timeout = { 1, 500000 }; // 1.5 seconds *c = redisConnectWithTimeout(redis->r_ip, redis->r_port, timeout); - - return 0; + if (*c == NULL || (*c)->err) { + if (*c) { + mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Sync connection error: %s\n", (*c)->errstr); + redisFree(*c); + *c = NULL; + } else { + mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Connection error: can't allocate redis context\n"); + } + goto finish; + } + xret = 0; +finish: + return xret; } static int -task_int(struct event_base *base, libevent_thread *me) +cert_task_private_init(struct event_base *base, libevent_thread *me) { int xret = -1; @@ -1082,7 +1094,11 @@ task_int(struct event_base *base, libevent_thread *me) goto finish; } - xret = redis_sync_int(&me->sync); + xret = redis_sync_init(&me->sync); + if (xret < 0 || !me->sync){ + mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Initialize the sync redis connection is failure\n"); + goto finish; + } /* Initialize the X509 CA*/ xret = x509_privatekey_init(&me->key, &me->root); @@ -1101,28 +1117,28 @@ static void *pthread_worker_libevent(void *arg) struct event_base *base = NULL; struct evhttp_bound_socket *bound = NULL; - libevent_thread *t = (libevent_thread *)arg; + libevent_thread *thread = (libevent_thread *)arg; base = event_base_new(); if (! base) { - mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Can't allocate event base\n"); + mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "Can'thread allocate event base\n"); goto finish; } http = evhttp_new(base); if (!http) { - mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "couldn't create evhttp. Exiting.\n"); + mesa_runtime_log(RLOG_LV_FATAL, MODULE_NAME, "couldn'thread create evhttp. Exiting.\n"); goto error; } /* Context initialization */ - xret = task_int(base, t); + xret = cert_task_private_init(base, thread); if (xret < 0){ goto error; } - evhttp_set_cb(http, "/ca", pthread_work_proc, t); + evhttp_set_cb(http, "/ca", pthread_work_proc, thread); - bound = evhttp_accept_socket_with_handle(http, t->accept_fd); + bound = evhttp_accept_socket_with_handle(http, thread->accept_fd); if (bound != NULL) { mesa_runtime_log(RLOG_LV_INFO, MODULE_NAME, "Bound(%p) to port %d - Awaiting connections ... ", bound, cert_default_config()->e_port); @@ -1276,13 +1292,12 @@ void sigproc(int __attribute__((__unused__))sig) for (tid = 0; tid < rte->thread_nu; tid++) { thread = threads + tid; - + if (thread->sync){ + redisAsyncDisconnect(thread->cl_ctx); + redisFree(thread->sync); + } X509_free(thread->root); EVP_PKEY_free(thread->key); - if (thread->cl_ctx) - redisAsyncDisconnect(thread->cl_ctx); - if (thread->sync) - redisFree(thread->sync); } kfree(threads);