fixed a logmask handling issue

This commit is contained in:
hyung-hwan 2018-03-17 11:57:02 +00:00
parent b011505e08
commit 1968f11cdf
3 changed files with 48 additions and 41 deletions

View File

@ -128,7 +128,16 @@
# endif # endif
#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 struct bb_t
{ {
char buf[1024]; char buf[1024];
@ -137,19 +146,20 @@ struct bb_t
int fd; int fd;
hcl_bch_t* fn; 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 struct worker_hcl_xtn_t
{ {
hcl_server_proto_t* proto; hcl_server_proto_t* proto;
int vm_running; 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 struct dummy_hcl_xtn_t
{ {
hcl_server_t* server; hcl_server_t* server;
}; };
typedef struct dummy_hcl_xtn_t dummy_hcl_xtn_t;
enum hcl_server_proto_token_type_t enum hcl_server_proto_token_type_t
@ -242,11 +252,11 @@ struct hcl_server_worker_t
hcl_oow_t wid; hcl_oow_t wid;
int sck; int sck;
/* TODO: peer address */ sockaddr_t peeraddr;
int claimed; int claimed;
hcl_ntime_t time_created; hcl_ntime_t alloc_time;
hcl_server_worker_state_t state; hcl_server_worker_state_t state;
hcl_server_worker_opstate_t opstate; hcl_server_worker_opstate_t opstate;
hcl_server_proto_t* proto; 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__) #if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
# define IS_PATH_SEP(c) ((c) == '/' || (c) == '\\') # define IS_PATH_SEP(c) ((c) == '/' || (c) == '\\')
# define PATH_SEP_CHAR ('\\') # 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 char_t
#undef oocs_t #undef oocs_t
#undef str_to_ipv4 #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; 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; 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->state = HCL_SERVER_WORKER_STATE_ZOMBIE;
worker->opstate = HCL_SERVER_WORKER_OPSTATE_IDLE; worker->opstate = HCL_SERVER_WORKER_OPSTATE_IDLE;
worker->sck = cli_sck; worker->sck = cli_sck;
worker->peeraddr = *peeraddr;
worker->server = server; 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) 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; if (flood) goto unable_to_accomodate;
} }
worker = alloc_worker(server, cli_fd); worker = alloc_worker(server, cli_fd, &cli_addr);
if (!worker) if (!worker)
{ {
unable_to_accomodate: unable_to_accomodate:

View File

@ -1313,6 +1313,7 @@ static int handle_logopt (hcl_t* hcl, const hcl_bch_t* str)
xtn_t* xtn = (xtn_t*)hcl_getxtn (hcl); xtn_t* xtn = (xtn_t*)hcl_getxtn (hcl);
hcl_bch_t* xstr = (hcl_bch_t*)str; hcl_bch_t* xstr = (hcl_bch_t*)str;
hcl_bch_t* cm, * flt; hcl_bch_t* cm, * flt;
unsigned int logmask;
cm = hcl_findbcharinbcstr (xstr, ','); cm = hcl_findbcharinbcstr (xstr, ',');
if (cm) if (cm)
@ -1329,6 +1330,7 @@ static int handle_logopt (hcl_t* hcl, const hcl_bch_t* str)
cm = hcl_findbcharinbcstr(xstr, ','); cm = hcl_findbcharinbcstr(xstr, ',');
*cm = '\0'; *cm = '\0';
logmask = xtn->logmask;
do do
{ {
flt = cm + 1; flt = cm + 1;
@ -1336,25 +1338,25 @@ static int handle_logopt (hcl_t* hcl, const hcl_bch_t* str)
cm = hcl_findbcharinbcstr(flt, ','); cm = hcl_findbcharinbcstr(flt, ',');
if (cm) *cm = '\0'; if (cm) *cm = '\0';
if (hcl_compbcstr(flt, "app") == 0) xtn->logmask |= HCL_LOG_APP; if (hcl_compbcstr(flt, "app") == 0) logmask |= HCL_LOG_APP;
else if (hcl_compbcstr(flt, "compiler") == 0) xtn->logmask |= HCL_LOG_COMPILER; else if (hcl_compbcstr(flt, "compiler") == 0) logmask |= HCL_LOG_COMPILER;
else if (hcl_compbcstr(flt, "vm") == 0) xtn->logmask |= HCL_LOG_VM; else if (hcl_compbcstr(flt, "vm") == 0) logmask |= HCL_LOG_VM;
else if (hcl_compbcstr(flt, "mnemonic") == 0) xtn->logmask |= HCL_LOG_MNEMONIC; else if (hcl_compbcstr(flt, "mnemonic") == 0) logmask |= HCL_LOG_MNEMONIC;
else if (hcl_compbcstr(flt, "gc") == 0) xtn->logmask |= HCL_LOG_GC; else if (hcl_compbcstr(flt, "gc") == 0) logmask |= HCL_LOG_GC;
else if (hcl_compbcstr(flt, "ic") == 0) xtn->logmask |= HCL_LOG_IC; else if (hcl_compbcstr(flt, "ic") == 0) logmask |= HCL_LOG_IC;
else if (hcl_compbcstr(flt, "primitive") == 0) xtn->logmask |= HCL_LOG_PRIMITIVE; 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, "fatal") == 0) logmask |= HCL_LOG_FATAL;
else if (hcl_compbcstr(flt, "error") == 0) xtn->logmask |= HCL_LOG_ERROR; else if (hcl_compbcstr(flt, "error") == 0) logmask |= HCL_LOG_ERROR;
else if (hcl_compbcstr(flt, "warn") == 0) xtn->logmask |= HCL_LOG_WARN; else if (hcl_compbcstr(flt, "warn") == 0) logmask |= HCL_LOG_WARN;
else if (hcl_compbcstr(flt, "info") == 0) xtn->logmask |= HCL_LOG_INFO; else if (hcl_compbcstr(flt, "info") == 0) logmask |= HCL_LOG_INFO;
else if (hcl_compbcstr(flt, "debug") == 0) xtn->logmask |= HCL_LOG_DEBUG; 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, "fatal+") == 0) logmask |= HCL_LOG_FATAL;
else if (hcl_compbcstr(flt, "error+") == 0) xtn->logmask |= HCL_LOG_FATAL | HCL_LOG_ERROR; else if (hcl_compbcstr(flt, "error+") == 0) 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, "warn+") == 0) 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, "info+") == 0) 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, "debug+") == 0) logmask |= HCL_LOG_FATAL | HCL_LOG_ERROR | HCL_LOG_WARN | HCL_LOG_INFO | HCL_LOG_DEBUG;
else else
{ {
@ -1366,14 +1368,15 @@ static int handle_logopt (hcl_t* hcl, const hcl_bch_t* str)
while (cm); while (cm);
if (!(xtn->logmask & HCL_LOG_ALL_TYPES)) xtn->logmask |= HCL_LOG_ALL_TYPES; /* no types specified. force to all types */ if (!(logmask & HCL_LOG_ALL_TYPES)) 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_LEVELS)) logmask |= HCL_LOG_ALL_LEVELS; /* no levels specified. force to all levels */
} }
else 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); xtn->logfd = open (xstr, O_CREAT | O_WRONLY | O_APPEND , 0644);
if (xtn->logfd == -1) if (xtn->logfd == -1)
{ {
@ -1382,6 +1385,7 @@ static int handle_logopt (hcl_t* hcl, const hcl_bch_t* str)
return -1; return -1;
} }
xtn->logmask = logmask;
#if defined(HAVE_ISATTY) #if defined(HAVE_ISATTY)
xtn->logfd_istty = isatty(xtn->logfd); xtn->logfd_istty = isatty(xtn->logfd);
#endif #endif

View File

@ -366,7 +366,6 @@ static int handle_logopt (hcl_server_t* server, const hcl_bch_t* str)
server_xtn_t* xtn; server_xtn_t* xtn;
xtn = (server_xtn_t*)hcl_server_getxtn(server); xtn = (server_xtn_t*)hcl_server_getxtn(server);
hcl_server_getoption (server, HCL_SERVER_LOG_MASK, &logmask);
cm = hcl_findbcharinbcstr(xstr, ','); cm = hcl_findbcharinbcstr(xstr, ',');
if (cm) if (cm)
@ -383,6 +382,7 @@ static int handle_logopt (hcl_server_t* server, const hcl_bch_t* str)
cm = hcl_findbcharinbcstr(xstr, ','); cm = hcl_findbcharinbcstr(xstr, ',');
*cm = '\0'; *cm = '\0';
logmask = xtn->logmask;
do do
{ {
flt = cm + 1; 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; logmask = HCL_LOG_ALL_LEVELS | HCL_LOG_ALL_TYPES;
} }
xtn->logmask = logmask;
xtn->logfd = open(xstr, O_CREAT | O_WRONLY | O_APPEND , 0644); xtn->logfd = open(xstr, O_CREAT | O_WRONLY | O_APPEND , 0644);
if (xtn->logfd == -1) if (xtn->logfd == -1)
{ {
@ -436,6 +435,7 @@ static int handle_logopt (hcl_server_t* server, const hcl_bch_t* str)
return -1; return -1;
} }
xtn->logmask = logmask;
#if defined(HAVE_ISATTY) #if defined(HAVE_ISATTY)
xtn->logfd_istty = isatty(xtn->logfd); xtn->logfd_istty = isatty(xtn->logfd);
#endif #endif
@ -626,7 +626,8 @@ int main (int argc, char* argv[])
} }
else 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) #if defined(HCL_BUILD_DEBUG)