From 1968f11cdf71eafe15c0b786b7faf1009af5d22c Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sat, 17 Mar 2018 11:57:02 +0000 Subject: [PATCH] fixed a logmask handling issue --- lib/hcl-s.c | 38 ++++++++++++++++++++------------------ lib/main.c | 44 ++++++++++++++++++++++++-------------------- lib/main2.c | 7 ++++--- 3 files changed, 48 insertions(+), 41 deletions(-) diff --git a/lib/hcl-s.c b/lib/hcl-s.c index a0b4aff..827aa43 100644 --- a/lib/hcl-s.c +++ b/lib/hcl-s.c @@ -128,7 +128,16 @@ # endif #endif -typedef struct bb_t bb_t; + +union sockaddr_t +{ + struct sockaddr_in in4; +#if (HCL_SIZEOF_STRUCT_SOCKADDR_IN6 > 0) + struct sockaddr_in6 in6; +#endif +}; +typedef union sockaddr_t sockaddr_t; + struct bb_t { char buf[1024]; @@ -137,19 +146,20 @@ struct bb_t int fd; hcl_bch_t* fn; }; +typedef struct bb_t bb_t; -typedef struct worker_hcl_xtn_t worker_hcl_xtn_t; struct worker_hcl_xtn_t { hcl_server_proto_t* proto; int vm_running; }; +typedef struct worker_hcl_xtn_t worker_hcl_xtn_t; -typedef struct dummy_hcl_xtn_t dummy_hcl_xtn_t; struct dummy_hcl_xtn_t { hcl_server_t* server; }; +typedef struct dummy_hcl_xtn_t dummy_hcl_xtn_t; enum hcl_server_proto_token_type_t @@ -242,11 +252,11 @@ struct hcl_server_worker_t hcl_oow_t wid; int sck; - /* TODO: peer address */ + sockaddr_t peeraddr; int claimed; - hcl_ntime_t time_created; + hcl_ntime_t alloc_time; hcl_server_worker_state_t state; hcl_server_worker_opstate_t opstate; hcl_server_proto_t* proto; @@ -321,8 +331,6 @@ int hcl_server_proto_feed_reply (hcl_server_proto_t* proto, const hcl_ooch_t* pt /* ========================================================================= */ - - #if defined(_WIN32) || defined(__OS2__) || defined(__DOS__) # define IS_PATH_SEP(c) ((c) == '/' || (c) == '\\') # define PATH_SEP_CHAR ('\\') @@ -986,15 +994,6 @@ static void fini_hcl (hcl_t* hcl) /* ========================================================================= */ -union sockaddr_t -{ - struct sockaddr_in in4; -#if (HCL_SIZEOF_STRUCT_SOCKADDR_IN6 > 0) - struct sockaddr_in6 in6; -#endif -}; -typedef union sockaddr_t sockaddr_t; - #undef char_t #undef oocs_t #undef str_to_ipv4 @@ -2036,7 +2035,7 @@ static HCL_INLINE void release_wid (hcl_server_t* server, hcl_server_worker_t* w worker->wid = HCL_SERVER_WID_INVALID; } -static hcl_server_worker_t* alloc_worker (hcl_server_t* server, int cli_sck) +static hcl_server_worker_t* alloc_worker (hcl_server_t* server, int cli_sck, const sockaddr_t* peeraddr) { hcl_server_worker_t* worker; @@ -2047,7 +2046,10 @@ static hcl_server_worker_t* alloc_worker (hcl_server_t* server, int cli_sck) worker->state = HCL_SERVER_WORKER_STATE_ZOMBIE; worker->opstate = HCL_SERVER_WORKER_OPSTATE_IDLE; worker->sck = cli_sck; + worker->peeraddr = *peeraddr; worker->server = server; + + server->dummy_hcl->vmprim.vm_gettime (server->dummy_hcl, &worker->alloc_time); /* TODO: the callback may return monotonic time. find a way to guarantee it is realtime??? */ if (server->wid_map.free_first == HCL_SERVER_WID_INVALID && prepare_to_acquire_wid(server) <= -1) { @@ -2393,7 +2395,7 @@ int hcl_server_start (hcl_server_t* server, const hcl_bch_t* addrs) if (flood) goto unable_to_accomodate; } - worker = alloc_worker(server, cli_fd); + worker = alloc_worker(server, cli_fd, &cli_addr); if (!worker) { unable_to_accomodate: diff --git a/lib/main.c b/lib/main.c index 623a2ff..5055141 100644 --- a/lib/main.c +++ b/lib/main.c @@ -1313,6 +1313,7 @@ static int handle_logopt (hcl_t* hcl, const hcl_bch_t* str) xtn_t* xtn = (xtn_t*)hcl_getxtn (hcl); hcl_bch_t* xstr = (hcl_bch_t*)str; hcl_bch_t* cm, * flt; + unsigned int logmask; cm = hcl_findbcharinbcstr (xstr, ','); if (cm) @@ -1329,6 +1330,7 @@ static int handle_logopt (hcl_t* hcl, const hcl_bch_t* str) cm = hcl_findbcharinbcstr(xstr, ','); *cm = '\0'; + logmask = xtn->logmask; do { flt = cm + 1; @@ -1336,25 +1338,25 @@ static int handle_logopt (hcl_t* hcl, const hcl_bch_t* str) cm = hcl_findbcharinbcstr(flt, ','); if (cm) *cm = '\0'; - if (hcl_compbcstr(flt, "app") == 0) xtn->logmask |= HCL_LOG_APP; - else if (hcl_compbcstr(flt, "compiler") == 0) xtn->logmask |= HCL_LOG_COMPILER; - else if (hcl_compbcstr(flt, "vm") == 0) xtn->logmask |= HCL_LOG_VM; - else if (hcl_compbcstr(flt, "mnemonic") == 0) xtn->logmask |= HCL_LOG_MNEMONIC; - else if (hcl_compbcstr(flt, "gc") == 0) xtn->logmask |= HCL_LOG_GC; - else if (hcl_compbcstr(flt, "ic") == 0) xtn->logmask |= HCL_LOG_IC; - else if (hcl_compbcstr(flt, "primitive") == 0) xtn->logmask |= HCL_LOG_PRIMITIVE; + if (hcl_compbcstr(flt, "app") == 0) logmask |= HCL_LOG_APP; + else if (hcl_compbcstr(flt, "compiler") == 0) logmask |= HCL_LOG_COMPILER; + else if (hcl_compbcstr(flt, "vm") == 0) logmask |= HCL_LOG_VM; + else if (hcl_compbcstr(flt, "mnemonic") == 0) logmask |= HCL_LOG_MNEMONIC; + else if (hcl_compbcstr(flt, "gc") == 0) logmask |= HCL_LOG_GC; + else if (hcl_compbcstr(flt, "ic") == 0) logmask |= HCL_LOG_IC; + else if (hcl_compbcstr(flt, "primitive") == 0) logmask |= HCL_LOG_PRIMITIVE; - else if (hcl_compbcstr(flt, "fatal") == 0) xtn->logmask |= HCL_LOG_FATAL; - else if (hcl_compbcstr(flt, "error") == 0) xtn->logmask |= HCL_LOG_ERROR; - else if (hcl_compbcstr(flt, "warn") == 0) xtn->logmask |= HCL_LOG_WARN; - else if (hcl_compbcstr(flt, "info") == 0) xtn->logmask |= HCL_LOG_INFO; - else if (hcl_compbcstr(flt, "debug") == 0) xtn->logmask |= HCL_LOG_DEBUG; + else if (hcl_compbcstr(flt, "fatal") == 0) logmask |= HCL_LOG_FATAL; + else if (hcl_compbcstr(flt, "error") == 0) logmask |= HCL_LOG_ERROR; + else if (hcl_compbcstr(flt, "warn") == 0) logmask |= HCL_LOG_WARN; + else if (hcl_compbcstr(flt, "info") == 0) logmask |= HCL_LOG_INFO; + else if (hcl_compbcstr(flt, "debug") == 0) logmask |= HCL_LOG_DEBUG; - else if (hcl_compbcstr(flt, "fatal+") == 0) xtn->logmask |= HCL_LOG_FATAL; - else if (hcl_compbcstr(flt, "error+") == 0) xtn->logmask |= HCL_LOG_FATAL | HCL_LOG_ERROR; - else if (hcl_compbcstr(flt, "warn+") == 0) xtn->logmask |= HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN; - else if (hcl_compbcstr(flt, "info+") == 0) xtn->logmask |= HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN | HCL_LOG_INFO; - else if (hcl_compbcstr(flt, "debug+") == 0) xtn->logmask |= HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN | HCL_LOG_INFO | HCL_LOG_DEBUG; + else if (hcl_compbcstr(flt, "fatal+") == 0) logmask |= HCL_LOG_FATAL; + else if (hcl_compbcstr(flt, "error+") == 0) logmask |= HCL_LOG_FATAL | HCL_LOG_ERROR; + else if (hcl_compbcstr(flt, "warn+") == 0) logmask |= HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN; + else if (hcl_compbcstr(flt, "info+") == 0) logmask |= HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN | HCL_LOG_INFO; + else if (hcl_compbcstr(flt, "debug+") == 0) logmask |= HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN | HCL_LOG_INFO | HCL_LOG_DEBUG; else { @@ -1366,14 +1368,15 @@ static int handle_logopt (hcl_t* hcl, const hcl_bch_t* str) while (cm); - if (!(xtn->logmask & HCL_LOG_ALL_TYPES)) xtn->logmask |= HCL_LOG_ALL_TYPES; /* no types specified. force to all types */ - if (!(xtn->logmask & HCL_LOG_ALL_LEVELS)) xtn->logmask |= HCL_LOG_ALL_LEVELS; /* no levels specified. force to all levels */ + if (!(logmask & HCL_LOG_ALL_TYPES)) logmask |= HCL_LOG_ALL_TYPES; /* no types specified. force to all types */ + if (!(logmask & HCL_LOG_ALL_LEVELS)) logmask |= HCL_LOG_ALL_LEVELS; /* no levels specified. force to all levels */ } else { - xtn->logmask = HCL_LOG_ALL_LEVELS | HCL_LOG_ALL_TYPES; + logmask = HCL_LOG_ALL_LEVELS | HCL_LOG_ALL_TYPES; } + xtn->logfd = open (xstr, O_CREAT | O_WRONLY | O_APPEND , 0644); if (xtn->logfd == -1) { @@ -1382,6 +1385,7 @@ static int handle_logopt (hcl_t* hcl, const hcl_bch_t* str) return -1; } + xtn->logmask = logmask; #if defined(HAVE_ISATTY) xtn->logfd_istty = isatty(xtn->logfd); #endif diff --git a/lib/main2.c b/lib/main2.c index 98ebf5b..1909e6a 100644 --- a/lib/main2.c +++ b/lib/main2.c @@ -366,7 +366,6 @@ static int handle_logopt (hcl_server_t* server, const hcl_bch_t* str) server_xtn_t* xtn; xtn = (server_xtn_t*)hcl_server_getxtn(server); - hcl_server_getoption (server, HCL_SERVER_LOG_MASK, &logmask); cm = hcl_findbcharinbcstr(xstr, ','); if (cm) @@ -383,6 +382,7 @@ static int handle_logopt (hcl_server_t* server, const hcl_bch_t* str) cm = hcl_findbcharinbcstr(xstr, ','); *cm = '\0'; + logmask = xtn->logmask; do { flt = cm + 1; @@ -427,7 +427,6 @@ static int handle_logopt (hcl_server_t* server, const hcl_bch_t* str) logmask = HCL_LOG_ALL_LEVELS | HCL_LOG_ALL_TYPES; } - xtn->logmask = logmask; xtn->logfd = open(xstr, O_CREAT | O_WRONLY | O_APPEND , 0644); if (xtn->logfd == -1) { @@ -436,6 +435,7 @@ static int handle_logopt (hcl_server_t* server, const hcl_bch_t* str) return -1; } + xtn->logmask = logmask; #if defined(HAVE_ISATTY) xtn->logfd_istty = isatty(xtn->logfd); #endif @@ -626,7 +626,8 @@ int main (int argc, char* argv[]) } else { - /*xtn->logmask = HCL_LOG_ALL_TYPES | HCL_LOG_ERROR | HCL_LOG_FATAL;*/ + /* default logging mask when no logging option is set */ + xtn->logmask = HCL_LOG_ALL_TYPES | HCL_LOG_ERROR | HCL_LOG_FATAL; } #if defined(HCL_BUILD_DEBUG)