diff --git a/VERSION b/VERSION index 0b1f1ed..fd9d1a5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.2.13 +1.2.14 diff --git a/include/common/debug.h b/include/common/debug.h index 2f6390f..7650e48 100644 --- a/include/common/debug.h +++ b/include/common/debug.h @@ -40,6 +40,7 @@ enum DBG_LEVEL_enum { }; # define IFDEF_DBG(a, b) a +# define DBG_INDENT_STEP 2 # define DBG_PARM(a, ...) a, ##__VA_ARGS__ # define C_DBG(l,C,f, ...) \ do { \ @@ -56,11 +57,27 @@ enum DBG_LEVEL_enum { if (cfg.debug_level & (1 << DBG_LEVEL_##l)) \ w_log((W), f, ##__VA_ARGS__); \ } while (0) -# define DBG_FUNC(W,f, ...) \ - do { \ - if (cfg.debug_level & (1 << DBG_LEVEL_ENABLED)) \ - W_DBG(FUNC, (W), "%s(" f ")", __func__, ##__VA_ARGS__); \ +# define DBG_FUNC(W,f, ...) \ + do { \ + if (cfg.debug_level & (1 << DBG_LEVEL_ENABLED)) \ + W_DBG(FUNC, (W), "%s(" f ") {", __func__, ##__VA_ARGS__); \ + dbg_w_ptr = (W); \ + dbg_indent += DBG_INDENT_STEP; \ } while (0) +# define DBG_FUNC_END(f, ...) \ + do { \ + dbg_indent -= DBG_INDENT_STEP; \ + if (cfg.debug_level & (1 << DBG_LEVEL_ENABLED)) \ + W_DBG(FUNC, dbg_w_ptr, f, ##__VA_ARGS__); \ + } while (0) +# define DBG_RETURN() do { DBG_FUNC_END("}"); return; } while (0) +# define DBG_RETURN_EX(a,t,f) do { t _r = (a); DBG_FUNC_END("} = " f, _r); return _r; } while (0) +# define DBG_RETURN_INT(a) DBG_RETURN_EX((a), int, "%d") +# define DBG_RETURN_U64(a) DBG_RETURN_EX((a), uint64_t, "%lu") +# define DBG_RETURN_SIZE(a) DBG_RETURN_EX((a), size_t, "%ld") +# define DBG_RETURN_SSIZE(a) DBG_RETURN_EX((a), ssize_t, "%lu") +# define DBG_RETURN_PTR(a) DBG_RETURN_EX((a), void *, "%p") +# define DBG_RETURN_CPTR(a) DBG_RETURN_EX((a), const void *, "%p") #else # define IFDEF_DBG(a, b) b # define DBG_PARM(...) @@ -68,6 +85,14 @@ enum DBG_LEVEL_enum { # define F_DBG(...) while (0) # define W_DBG(...) while (0) # define DBG_FUNC(...) while (0) +# define DBG_RETURN() return +# define DBG_RETURN_EX(a,t,f) return a +# define DBG_RETURN_INT(a) return a +# define DBG_RETURN_U64(a) return a +# define DBG_RETURN_SIZE(a) return a +# define DBG_RETURN_SSIZE(a) return a +# define DBG_RETURN_PTR(a) return a +# define DBG_RETURN_CPTR(a) return a #endif /* DEBUG */ #endif /* _COMMON_DEBUG_H */ diff --git a/include/types/curl.h b/include/types/curl.h index a149fb0..8b563b7 100644 --- a/include/types/curl.h +++ b/include/types/curl.h @@ -23,7 +23,7 @@ #define CURL_STR "cURL: " #define CURL_ERR_EASY(a,b) w_log(NULL, _E(CURL_STR a ": %s (%u)"), curl_easy_strerror(b), (b)) #define CURL_ERR_MULTI(a,b) w_log(NULL, _E(CURL_STR a ": %s (%d)"), curl_multi_strerror(b), (b)) -#define CURL_DBG(a, ...) W_DBG(CURL, NULL, " " CURL_STR a, ##__VA_ARGS__) +#define CURL_DBG(a, ...) W_DBG(CURL, NULL, CURL_STR a, ##__VA_ARGS__) /* Time-out connect operations after this amount of milliseconds. */ #define CURL_CON_TMOUT 20000 diff --git a/include/types/main.h b/include/types/main.h index 5ab393e..914e07b 100644 --- a/include/types/main.h +++ b/include/types/main.h @@ -92,6 +92,11 @@ struct program_data { extern struct config_data cfg; extern struct program_data prg; +#ifdef DEBUG +extern __THR const void *dbg_w_ptr; +extern __THR int dbg_indent; +#endif + #endif /* _TYPES_MAIN_H */ /* diff --git a/include/types/util.h b/include/types/util.h index c699e4c..b956791 100644 --- a/include/types/util.h +++ b/include/types/util.h @@ -31,6 +31,14 @@ # define LOG_RUNTIME(a,b) ((b) / 1000000.0) #endif +#ifdef DEBUG +# define LOG_FMT_INDENT "%.*s" +# define LOG_INDENT dbg_indent, " >>>", +#else +# define LOG_FMT_INDENT +# define LOG_INDENT +#endif + #define _F(s) "(F) " s #define _E(s) "(E) " s #define _W(s) "(W) " s diff --git a/src/.build-counter b/src/.build-counter index 2e5d6e7..951ba79 100644 --- a/src/.build-counter +++ b/src/.build-counter @@ -1 +1 @@ -2439 +2491 diff --git a/src/curl.c b/src/curl.c index b06ee94..722322c 100644 --- a/src/curl.c +++ b/src/curl.c @@ -45,7 +45,7 @@ static int mir_curl_debug_cb(CURL *handle, curl_infotype type, char *data, size_ CURL_DBG("[%p]: %u <%s>", handle, type, str_ctrl(data, size)); - return CURLE_OK; + DBG_RETURN_INT(CURLE_OK); } #endif /* DEBUG */ @@ -69,7 +69,7 @@ static void mir_curl_handle_close(struct curl_con *con) DBG_FUNC(NULL, "%p", con); if (_NULL(con)) - return; + DBG_RETURN(); CURL_DBG("Closing handle { %p %p \"%s\" %p }", con->easy, con->hdrs, con->error, con->curl); @@ -85,6 +85,8 @@ static void mir_curl_handle_close(struct curl_con *con) mir_ptr_free(&(con->mir)); PTR_FREE(con); + + DBG_RETURN(); } @@ -123,7 +125,7 @@ static const char *mir_curl_get_http_version(long version) if (http_version[i].value == version) break; - return http_version[i].str; + DBG_RETURN_CPTR(http_version[i].str); } @@ -191,6 +193,8 @@ static void mir_curl_check_multi_info(struct curl_data *curl) mir_curl_handle_close(con); } } + + DBG_RETURN(); } @@ -231,6 +235,8 @@ static void mir_curl_ev_socket_cb(struct ev_loop *loop __maybe_unused, struct ev ev_async_send(curl->ev_base, curl->ev_async); } } + + DBG_RETURN(); } @@ -273,7 +279,7 @@ static int mir_curl_socket_set(struct curl_sock *socket, CURL *easy, curl_socket ev_io_start(curl->ev_base, &(socket->ev_io)); ev_async_send(curl->ev_base, curl->ev_async); - return 0; + DBG_RETURN_INT(0); } @@ -313,7 +319,7 @@ static struct curl_sock *mir_curl_socket_add(CURL *easy, curl_socket_t s, int wh PTR_FREE(retptr); } - return retptr; + DBG_RETURN_PTR(retptr); } @@ -336,7 +342,7 @@ static int mir_curl_socket_remove(struct curl_sock *socket, struct curl_data *cu DBG_FUNC(NULL, "%p, %p", socket, curl); if (_NULL(socket)) - return 0; + DBG_RETURN_INT(0); if (ev_is_active(&(socket->ev_io)) || ev_is_pending(&(socket->ev_io))) ev_io_stop(curl->ev_base, &(socket->ev_io)); @@ -344,7 +350,7 @@ static int mir_curl_socket_remove(struct curl_sock *socket, struct curl_data *cu PTR_FREE(socket); - return 0; + DBG_RETURN_INT(0); } @@ -380,7 +386,7 @@ static int mir_curl_socket_cb(CURL *easy, curl_socket_t s, int what, void *userp else if (_NULL(socket = mir_curl_socket_add(easy, s, what, curl))) retval = -1; - return retval; + DBG_RETURN_INT(retval); } @@ -410,6 +416,8 @@ static void mir_curl_ev_timer_cb(struct ev_loop *loop __maybe_unused, struct ev_ CURL_ERR_MULTI("Failed data transfer", rcm); mir_curl_check_multi_info(curl); + + DBG_RETURN(); } @@ -446,7 +454,7 @@ static int mir_curl_timer_cb(CURLM *multi __maybe_unused, long timeout_ms, void ev_async_send(curl->ev_base, curl->ev_async); - return CURLM_OK; + DBG_RETURN_INT(CURLM_OK); } @@ -473,12 +481,12 @@ static CURLcode mir_curl_set_headers(struct curl_con *con, const struct mirror * DBG_FUNC(NULL, "%p, %p", con, mir); if (_NULL(con) || _NULL(mir)) - return retval; + DBG_RETURN_INT(retval); list_for_each_entry_safe(hdr, hdr_back, &(mir->hdrs), list) { slist = curl_slist_append(con->hdrs, (const char *)hdr->ptr); if (_NULL(slist)) { - retval = CURLE_OUT_OF_MEMORY; + DBG_RETURN_INT(CURLE_OUT_OF_MEMORY); break; } @@ -493,7 +501,7 @@ static CURLcode mir_curl_set_headers(struct curl_con *con, const struct mirror * if ((retval = curl_easy_setopt(con->easy, CURLOPT_HTTPHEADER, con->hdrs)) != CURLE_OK) CURL_ERR_EASY("Failed to set HTTP headers", retval); - return retval; + DBG_RETURN_INT(retval); } @@ -523,7 +531,7 @@ int mir_curl_init(struct ev_loop *loop, struct ev_async *ev, struct curl_data *c DBG_FUNC(NULL, "%p, %p", loop, curl); if (_NULL(loop) || _NULL(curl)) - return retval; + DBG_RETURN_INT(retval); (void)memset(curl, 0, sizeof(*curl)); @@ -549,12 +557,12 @@ int mir_curl_init(struct ev_loop *loop, struct ev_async *ev, struct curl_data *c else if ((rcm = curl_multi_setopt(curl->multi, CURLMOPT_TIMERDATA, curl)) != CURLM_OK) CURL_ERR_MULTI("Failed to set timer callback function data", rcm); else - retval = FUNC_RET_OK; + DBG_RETURN_INT(FUNC_RET_OK); if (_ERROR(retval)) mir_curl_close(curl); - return retval; + DBG_RETURN_INT(retval); } @@ -576,7 +584,7 @@ void mir_curl_close(struct curl_data *curl) DBG_FUNC(NULL, "%p", curl); if (_NULL(curl)) - return; + DBG_RETURN(); if (_nNULL(curl->multi)) (void)curl_multi_cleanup(curl->multi); @@ -590,6 +598,8 @@ void mir_curl_close(struct curl_data *curl) #endif (void)memset(curl, 0, sizeof(*curl)); + + DBG_RETURN(); } @@ -617,7 +627,7 @@ static size_t mir_curl_read_cb(void *buffer __maybe_unused, size_t size, size_t DBG_FUNC(NULL, "%p, %zu, %zu, %p", buffer, size, nitems, instream); if (_NULL(con) || _NULL(con->mir) || _NULL(con->mir->body)) { - return retval; + DBG_RETURN_SIZE(retval); } else if (con->mir->body_head < con->mir->body_size) { retval = MIN(size * nitems, con->mir->body_size - con->mir->body_head); @@ -628,7 +638,7 @@ static size_t mir_curl_read_cb(void *buffer __maybe_unused, size_t size, size_t con->mir->body_head += retval; } - return retval; + DBG_RETURN_SIZE(retval); } @@ -654,7 +664,7 @@ static size_t mir_curl_write_cb(void *buffer __maybe_unused, size_t size, size_t DBG_FUNC(NULL, "%p, %zu, %zu, %p", buffer, size, nitems, outstream); - return retval; + DBG_RETURN_SIZE(retval); } @@ -685,7 +695,7 @@ static int mir_curl_xferinfo_cb(void *clientp, curl_off_t dltotal __maybe_unused CURL_DBG("Progress: %s (%"PRId64"/%"PRId64" %"PRId64"/%"PRId64")", con->mir->url, dlnow, dltotal, ulnow, ultotal); - return 0; + DBG_RETURN_INT(0); } #else @@ -698,7 +708,7 @@ static int mir_curl_xferinfo_cb(void *clientp, double dltotal __maybe_unused, do CURL_DBG("Progress: %s (%.0f/%.0f %.0f/%.0f)", con->mir->url, dlnow, dltotal, ulnow, ultotal); - return 0; + DBG_RETURN_INT(0); } #endif /* CURL_AT_LEAST_VERSION(7, 32, 0) */ @@ -727,7 +737,7 @@ static CURLcode mir_curl_add_keepalive(struct curl_con *con, bool_t flag_alive, DBG_FUNC(NULL, "%p, %hhu, %ld, %ld", con, flag_alive, idle, intvl); if (_NULL(con)) - return retval; + DBG_RETURN_INT(retval); if ((retval = curl_easy_setopt(con->easy, CURLOPT_TCP_KEEPALIVE, (long)flag_alive)) != CURLE_OK) CURL_ERR_EASY("Failed to set TCP keepalive", retval); @@ -738,7 +748,7 @@ static CURLcode mir_curl_add_keepalive(struct curl_con *con, bool_t flag_alive, else if ((intvl >= 0) && (retval = curl_easy_setopt(con->easy, CURLOPT_TCP_KEEPINTVL, intvl)) != CURLE_OK) CURL_ERR_EASY("Failed to set TCP keepintvl", retval); - return retval; + DBG_RETURN_INT(retval); } @@ -763,7 +773,7 @@ static CURLcode mir_curl_add_post(struct curl_con *con, const struct mirror *mir DBG_FUNC(NULL, "%p, %p", con, mir); if (_NULL(con) || _NULL(mir)) - return retval; + DBG_RETURN_INT(retval); if (mir->request_method != CURL_HTTP_METHOD_POST) retval = CURLE_OK; @@ -780,7 +790,7 @@ static CURLcode mir_curl_add_post(struct curl_con *con, const struct mirror *mir else if ((retval = curl_easy_setopt(con->easy, CURLOPT_READDATA, con)) != CURLE_OK) CURL_ERR_EASY("Failed to set read callback function data", retval); - return retval; + DBG_RETURN_INT(retval); } @@ -805,7 +815,7 @@ static CURLcode mir_curl_add_put(struct curl_con *con, const struct mirror *mir) DBG_FUNC(NULL, "%p, %p", con, mir); if (_NULL(con) || _NULL(mir)) - return retval; + DBG_RETURN_INT(retval); if (mir->request_method != CURL_HTTP_METHOD_PUT) retval = CURLE_OK; @@ -824,7 +834,7 @@ static CURLcode mir_curl_add_put(struct curl_con *con, const struct mirror *mir) else if ((retval = curl_easy_setopt(con->easy, CURLOPT_INFILESIZE_LARGE, (curl_off_t)mir->body_size)) != CURLE_OK) CURL_ERR_EASY("Failed to set HTTP PUT data size", retval); - return retval; + DBG_RETURN_INT(retval); } @@ -849,7 +859,7 @@ static CURLcode mir_curl_add_out(struct curl_con *con, const struct mirror *mir) DBG_FUNC(NULL, "%p, %p", con, mir); if (_NULL(con) || _NULL(mir)) - return retval; + DBG_RETURN_INT(retval); if (_nNULL(mir->out_address)) if ((retval = curl_easy_setopt(con->easy, CURLOPT_INTERFACE, mir->out_address)) != CURLE_OK) @@ -864,7 +874,7 @@ static CURLcode mir_curl_add_out(struct curl_con *con, const struct mirror *mir) else if ((retval = curl_easy_setopt(con->easy, CURLOPT_LOCALPORTRANGE, (long)mir->out_port[1])) != CURLE_OK) CURL_ERR_EASY("Failed to set outgoing connections port range", retval); - return retval; + DBG_RETURN_INT(retval); } @@ -889,7 +899,7 @@ static CURLcode mir_curl_add_cert(struct curl_con *con, const struct mirror *mir DBG_FUNC(NULL, "%p, %p", con, mir); if (_NULL(con) || _NULL(mir)) - return retval; + DBG_RETURN_INT(retval); if (strncasecmp(mir->url, STR_ADDRSIZE(STR_HTTPS_PFX)) != 0) { retval = CURLE_OK; @@ -902,7 +912,7 @@ static CURLcode mir_curl_add_cert(struct curl_con *con, const struct mirror *mir CURL_ERR_EASY("Failed to disable SSL host verification", retval); } - return retval; + DBG_RETURN_INT(retval); } @@ -927,7 +937,7 @@ static CURLcode mir_curl_add_url(struct curl_con *con, const struct mirror *mir) DBG_FUNC(NULL, "%p, %p", con, mir); if (_NULL(con) || _NULL(mir)) - return retval; + DBG_RETURN_INT(retval); #if CURL_AT_LEAST_VERSION(7, 33, 0) if (_NULL(mir->version) || (strcasecmp(mir->version, "2.0") != 0)) @@ -943,7 +953,7 @@ static CURLcode mir_curl_add_url(struct curl_con *con, const struct mirror *mir) else if ((retval = curl_easy_setopt(con->easy, CURLOPT_URL, mir->url)) != CURLE_OK) CURL_ERR_EASY("Failed to set URL", retval); - return retval; + DBG_RETURN_INT(retval); } @@ -972,7 +982,7 @@ int mir_curl_add(struct curl_data *curl, struct mirror *mir) DBG_FUNC(NULL, "%p, %p", curl, mir); if (_NULL(curl) || _NULL(mir)) - return retval; + DBG_RETURN_INT(retval); CURL_DBG("Adding mirror { \"%s\" \"%s\" \"%s\" %d \"%s\" { %p %p } %p %zu/%zu }", mir->url, mir->path, mir->method, mir->request_method, mir->version, mir->hdrs.p, mir->hdrs.n, mir->body, mir->body_head, mir->body_size); @@ -1040,7 +1050,7 @@ int mir_curl_add(struct curl_data *curl, struct mirror *mir) if (_ERROR(retval)) mir_curl_handle_close(con); - return retval; + DBG_RETURN_INT(retval); } /* diff --git a/src/libev.c b/src/libev.c index 1f7c6c5..09c55ca 100644 --- a/src/libev.c +++ b/src/libev.c @@ -53,7 +53,7 @@ const char *ev_backend_name(uint type) break; } - return retptr; + DBG_RETURN_CPTR(retptr); } @@ -79,7 +79,7 @@ const char *ev_backend_type(struct ev_loop *loop) if (_nNULL(loop)) retptr = ev_backend_name(ev_backend(loop)); - return retptr; + DBG_RETURN_CPTR(retptr); } @@ -115,7 +115,7 @@ const char *ev_backends_supported(void) (void)strncat(retbuf, ev_backend_name(i), SIZEOF_1(retbuf)); } - return retbuf; + DBG_RETURN_CPTR(retbuf); } /* diff --git a/src/main.c b/src/main.c index dabc1b4..33e10a6 100644 --- a/src/main.c +++ b/src/main.c @@ -37,6 +37,11 @@ struct config_data cfg = { }; struct program_data prg; +#ifdef DEBUG +__THR const void *dbg_w_ptr = NULL; +__THR int dbg_indent = 0; +#endif + /*** * NAME @@ -136,7 +141,7 @@ static int getopt_set_capability(const char *name) retval = FUNC_RET_ERROR; } - return retval; + DBG_RETURN_INT(retval); } @@ -177,7 +182,7 @@ static int getopt_set_ev_backend(const char *type) retval = FUNC_RET_ERROR; } - return retval; + DBG_RETURN_INT(retval); } @@ -207,7 +212,7 @@ static int getopt_set_debug_level(const char *value, uint32_t *debug_level, int DBG_FUNC(NULL, "\"%s\", %p, %d, %d", value, debug_level, val_min, val_max); if (TEST_OR2(NULL, value, debug_level)) - return retval; + DBG_RETURN_INT(retval); if (*value == '\0') { (void)fprintf(stderr, "ERROR: debug level not defined\n"); @@ -221,7 +226,7 @@ static int getopt_set_debug_level(const char *value, uint32_t *debug_level, int (void)fprintf(stderr, "ERROR: invalid debug level (allowed range [%d, %d]): '%s'\n", val_min, val_max, value); } - return retval; + DBG_RETURN_INT(retval); } #endif /* DEBUG */ @@ -251,7 +256,7 @@ static int getopt_set_time(const char *delay, uint64_t *time_us, uint64_t val_mi DBG_FUNC(NULL, "\"%s\", %p, %"PRIu64", %"PRIu64, delay, time_us, val_min, val_max); if (TEST_OR2(NULL, delay, time_us)) - return retval; + DBG_RETURN_INT(retval); if (*delay != '\0') { delay_us = parse_delay_us(delay, val_min, val_max); @@ -268,7 +273,7 @@ static int getopt_set_time(const char *delay, uint64_t *time_us, uint64_t val_mi (void)fprintf(stderr, "ERROR: time not defined\n"); } - return retval; + DBG_RETURN_INT(retval); } @@ -295,7 +300,7 @@ static int getopt_set_ports(const char *ports, int *range) DBG_FUNC(NULL, "\"%s\", %p", ports, range); if (TEST_OR2(NULL, ports, range)) - return retval; + DBG_RETURN_INT(retval); if (*ports != '\0') { if (!str_toll(ports, &endptr, 0, 10, value, 0, 65535)) @@ -319,10 +324,10 @@ static int getopt_set_ports(const char *ports, int *range) range[0] = value[0]; range[1] = (value[1] > 0) ? (value[1] - value[0] + 1) : 1; - W_DBG(NOTICE, NULL, " port range set to { %d, %d }", range[0], range[1]); + W_DBG(NOTICE, NULL, "port range set to { %d, %d }", range[0], range[1]); } - return retval; + DBG_RETURN_INT(retval); } @@ -462,7 +467,7 @@ int main(int argc, char **argv, char **envp __maybe_unused) } if (flag_error || (cfg.opt_flags & (FLAG_OPT_HELP | FLAG_OPT_VERSION))) - return flag_error ? EX_USAGE : EX_OK; + DBG_RETURN_INT(flag_error ? EX_USAGE : EX_OK); #ifdef HAVE_LIBCURL if (_nNULL(mir_url) && _NULL(cfg.mir_url = parse_url(mir_url))) { @@ -516,7 +521,7 @@ int main(int argc, char **argv, char **envp __maybe_unused) if (cfg.logfile_in_use) logfile_mark("stop "); - return flag_error ? EX_USAGE : retval; + DBG_RETURN_INT(flag_error ? EX_USAGE : retval); } /* diff --git a/src/spoa-message.c b/src/spoa-message.c index aae191c..60c9bfe 100644 --- a/src/spoa-message.c +++ b/src/spoa-message.c @@ -51,7 +51,7 @@ static void *spoa_msg_arg_dup(const struct spoe_frame *frame, int i, const char else if (_nNULL(len)) *len = data->chk.len; - return *ptr; + DBG_RETURN_PTR(*ptr); } @@ -91,7 +91,7 @@ int spoa_msg_iprep(struct spoe_frame *frame, const char **buf, const char *end, retval = FUNC_RET_ERROR; } else if (nbargs != 1) { - return 0; + DBG_RETURN_INT(0); } else if (type == SPOE_DATA_T_IPV4) { if (_nNULL(inet_ntop(AF_INET, &(data.ipv4), addr, INET_ADDRSTRLEN))) @@ -106,14 +106,14 @@ int spoa_msg_iprep(struct spoe_frame *frame, const char **buf, const char *end, F_DBG(SPOA, frame, "IPv6 score for %.*s is %d", INET6_ADDRSTRLEN, addr, retval); } else { - return 0; + DBG_RETURN_INT(0); } *ip_score = retval; SPOE_BUFFER_ADVANCE(retval); - return retval; + DBG_RETURN_INT(retval); } @@ -146,6 +146,8 @@ void spoa_msg_iprep_action(struct spoe_frame *frame, char **buf, int ip_score) SPOE_ENC_UINT8, SPOE_DATA_T_UINT32, /* Arg 3: variable type */ SPOE_ENC_VARINT, ip_score, /* variable value */ SPOE_ENC_END); + + DBG_RETURN(); } @@ -233,7 +235,7 @@ int spoa_msg_test(struct spoe_frame *frame, const char **buf, const char *end) SPOE_BUFFER_ADVANCE(retval); - return retval; + DBG_RETURN_INT(retval); } @@ -310,7 +312,7 @@ static int spoa_msg_arg_hdrs(struct spoe_frame *frame, const char *buf, const ch retval = FUNC_RET_ERROR; } - return retval; + DBG_RETURN_INT(retval); } @@ -344,7 +346,7 @@ int spoa_msg_mirror(struct spoe_frame *frame, const char **buf, const char *end) if (_NULL(mir = calloc(1, sizeof(*mir)))) { f_log(frame, _E("Failed to allocate memory")); - return retval; + DBG_RETURN_INT(retval); } LIST_INIT(&(mir->hdrs)); @@ -460,7 +462,7 @@ int spoa_msg_mirror(struct spoe_frame *frame, const char **buf, const char *end) SPOE_BUFFER_ADVANCE(retval); - return retval; + DBG_RETURN_INT(retval); } @@ -484,9 +486,9 @@ void mir_ptr_free(struct mirror **data) DBG_FUNC(NULL, "%p:%p", DPTR_ARGS(data)); if (_NULL(data) || _NULL(*data)) - return; + DBG_RETURN(); - W_DBG(NOTICE, NULL, " freeing mirror { \"%s\" \"%s\" \"%s\" %d \"%s\" { %p %p } %p %zu/%zu }", (*data)->url, (*data)->path, (*data)->method, (*data)->request_method, (*data)->version, (*data)->hdrs.p, (*data)->hdrs.n, (*data)->body, (*data)->body_head, (*data)->body_size); + W_DBG(NOTICE, NULL, "freeing mirror { \"%s\" \"%s\" \"%s\" %d \"%s\" { %p %p } %p %zu/%zu }", (*data)->url, (*data)->path, (*data)->method, (*data)->request_method, (*data)->version, (*data)->hdrs.p, (*data)->hdrs.n, (*data)->body, (*data)->body_head, (*data)->body_size); PTR_FREE((*data)->out_address); PTR_FREE((*data)->url); @@ -501,6 +503,8 @@ void mir_ptr_free(struct mirror **data) PTR_FREE((*data)->body); PTR_FREE(*data); + + DBG_RETURN(); } /* diff --git a/src/spoa.c b/src/spoa.c index 59e1d75..dc8773d 100644 --- a/src/spoa.c +++ b/src/spoa.c @@ -58,7 +58,7 @@ int acc_payload(struct spoe_frame *frame) retval = 1; } - return retval; + DBG_RETURN_INT(retval); } @@ -82,7 +82,7 @@ static void release_frame(struct spoe_frame *frame) DBG_FUNC(STRUCT_ELEM_SAFE(frame, worker, NULL), "%p", frame); if (_NULL(frame)) - return; + DBG_RETURN(); if (ev_is_active(&(frame->ev_process_frame)) || ev_is_pending(&(frame->ev_process_frame))) { ev_timer_stop(FW_PTR->ev_base, &(frame->ev_process_frame)); @@ -94,6 +94,8 @@ static void release_frame(struct spoe_frame *frame) buffer_free(&(frame->frag)); (void)memset(frame, 0, sizeof(*frame) + cfg.max_frame_size + SPOA_FRM_LEN); LIST_ADDQ(&(w->frames), &(frame->list)); + + DBG_RETURN(); } @@ -118,13 +120,13 @@ static void unuse_spoe_engine(struct client *client) DBG_FUNC(CW_PTR, "%p", client); if (_NULL(client) || _NULL(client->engine)) - return; + DBG_RETURN(); engine = client->engine; client->engine = NULL; LIST_DEL(&(client->by_engine)); if (!LIST_ISEMPTY(&(engine->clients))) - return; + DBG_RETURN(); C_DBG(SPOA, client, "Remove SPOE engine '%s'", engine->id); LIST_DEL(&(engine->list)); @@ -135,6 +137,8 @@ static void unuse_spoe_engine(struct client *client) release_frame(f); PTR_FREE(engine->id); PTR_FREE(engine); + + DBG_RETURN(); } @@ -159,7 +163,7 @@ void release_client(struct client *client) DBG_FUNC(CW_PTR, "%p", client); if (_NULL(client)) - return; + DBG_RETURN(); C_DBG(SPOA, client, "Release client"); @@ -189,6 +193,8 @@ void release_client(struct client *client) FD_CLOSE(client->fd); PTR_FREE(client); + + DBG_RETURN(); } @@ -210,7 +216,7 @@ static void reset_frame(struct spoe_frame *frame) DBG_FUNC(FW_PTR, "%p", frame); if (_NULL(frame)) - return; + DBG_RETURN(); buffer_free(&(frame->frag)); @@ -221,6 +227,8 @@ static void reset_frame(struct spoe_frame *frame) frame->fragmented = false; SPOE_FRAME_BUFFER_SET(frame, frame->data, 0, 0, 0); LIST_INIT(&(frame->list)); + + DBG_RETURN(); } @@ -294,6 +302,8 @@ static void write_frame(struct client *client, struct spoe_frame *frame) if (flag_ev_async_send) ev_async_send(FW_PTR->ev_base, &(FW_PTR->ev_async)); + + DBG_RETURN(); } @@ -361,6 +371,8 @@ static void process_frame_cb(struct ev_loop *loop __maybe_unused, struct ev_time spoa_msg_iprep_action(frame, &buf, ip_score); write_frame(NULL, frame); + + DBG_RETURN(); } @@ -384,13 +396,13 @@ static struct spoe_frame *acquire_incoming_frame(struct client *client) DBG_FUNC(CW_PTR, "%p", client); if (_nNULL(client->incoming_frame)) - return client->incoming_frame; + DBG_RETURN_PTR(client->incoming_frame); if (LIST_ISEMPTY(&(CW_PTR->frames))) { if (_NULL(frame = calloc(1, sizeof(*frame) + cfg.max_frame_size + SPOA_FRM_LEN))) { c_log(client, _E("Failed to allocate new frame: %m")); - return NULL; + DBG_RETURN_PTR(NULL); } } else { frame = LIST_NEXT(&(CW_PTR->frames), typeof(frame), list); @@ -406,7 +418,7 @@ static struct spoe_frame *acquire_incoming_frame(struct client *client) client->incoming_frame = frame; - return frame; + DBG_RETURN_PTR(frame); } @@ -443,7 +455,7 @@ static struct spoe_frame *acquire_outgoing_frame(struct client *client) client->outgoing_frame = frame; } - return frame; + DBG_RETURN_PTR(frame); } @@ -478,6 +490,8 @@ static void process_incoming_frame(struct spoe_frame *frame) } ev_async_send(FW_PTR->ev_base, &(FW_PTR->ev_async)); + + DBG_RETURN(); } @@ -501,7 +515,7 @@ static ssize_t frame_recv(struct spoe_frame *frame) DBG_FUNC(FW_PTR, "%p", frame); if (_NULL(frame)) - return retval; + DBG_RETURN_SSIZE(retval); C_DBG(SPOA, FC_PTR, "--> Receiving data"); @@ -517,7 +531,7 @@ static ssize_t frame_recv(struct spoe_frame *frame) frame->len = ntohl(*(uint32_t *)frame->buf); frame->buf += SPOA_FRM_LEN; } else { - return (retval > 0) ? 0 : retval; + DBG_RETURN_SSIZE((retval > 0) ? 0 : retval); } } @@ -532,7 +546,7 @@ static ssize_t frame_recv(struct spoe_frame *frame) else retval = (retval > 0) ? 0 : retval; - return retval; + DBG_RETURN_SSIZE(retval); } @@ -565,7 +579,7 @@ void read_frame_cb(struct ev_loop *loop __maybe_unused, ev_io *ev, int revents _ if (_ERROR(n)) release_client(client); - return; + DBG_RETURN(); } if (client->state == SPOA_ST_CONNECTING) { @@ -602,17 +616,17 @@ void read_frame_cb(struct ev_loop *loop __maybe_unused, ev_io *ev, int revents _ reset_frame(f); - return; + DBG_RETURN(); } else if (n == 1) { - return; + DBG_RETURN(); } else { /* Process frame. */ process_incoming_frame(f); client->incoming_frame = NULL; - return; + DBG_RETURN(); } } else if (client->state == SPOA_ST_DISCONNECTING) { @@ -632,12 +646,14 @@ void read_frame_cb(struct ev_loop *loop __maybe_unused, ev_io *ev, int revents _ release_client(client); - return; + DBG_RETURN(); } write_frame: write_frame(client, f); client->incoming_frame = NULL; + + DBG_RETURN(); } @@ -672,7 +688,7 @@ static ssize_t frame_send(const struct client *client, struct spoe_frame *frame) if (retval == SPOA_FRM_LEN) frame->buf += SPOA_FRM_LEN; else - return (retval > 0) ? 0 : retval; + DBG_RETURN_SSIZE((retval > 0) ? 0 : retval); } /* @@ -686,7 +702,7 @@ static ssize_t frame_send(const struct client *client, struct spoe_frame *frame) else retval = (retval > 0) ? 0 : retval; - return retval; + DBG_RETURN_SSIZE(retval); } @@ -717,7 +733,7 @@ void write_frame_cb(struct ev_loop *loop __maybe_unused, ev_io *ev, int revents ev_io_stop(CW_PTR->ev_base, &(client->ev_frame_wr)); ev_async_send(CW_PTR->ev_base, &(CW_PTR->ev_async)); - return; + DBG_RETURN(); } n = frame_send(client, f); @@ -725,7 +741,7 @@ void write_frame_cb(struct ev_loop *loop __maybe_unused, ev_io *ev, int revents if (_ERROR(n)) release_client(client); - return; + DBG_RETURN(); } if (client->state == SPOA_ST_CONNECTING) { @@ -734,7 +750,7 @@ void write_frame_cb(struct ev_loop *loop __maybe_unused, ev_io *ev, int revents release_client(client); - return; + DBG_RETURN(); } client->state = SPOA_ST_PROCESSING; @@ -745,7 +761,7 @@ void write_frame_cb(struct ev_loop *loop __maybe_unused, ev_io *ev, int revents else if (client->state == SPOA_ST_DISCONNECTING) { release_client(client); - return; + DBG_RETURN(); } release_frame(f); @@ -756,6 +772,8 @@ void write_frame_cb(struct ev_loop *loop __maybe_unused, ev_io *ev, int revents ev_io_start(CW_PTR->ev_base, &(client->ev_frame_rd)); ev_async_send(CW_PTR->ev_base, &(CW_PTR->ev_async)); } + + DBG_RETURN(); } /* diff --git a/src/spoe-decode.c b/src/spoe-decode.c index 33e92c8..65684d4 100644 --- a/src/spoe-decode.c +++ b/src/spoe-decode.c @@ -342,7 +342,7 @@ static int spoe_vdecode(struct spoe_frame *frame, const char **buf, const char * if (_ERROR(retval) && _nNULL(FC_PTR) && (FC_PTR->status_code == SPOE_FRM_ERR_NONE)) FC_PTR->status_code = SPOE_FRM_ERR_INVALID; - return retval; + DBG_RETURN_INT(retval); } @@ -458,7 +458,7 @@ static int spoe_decode_kv_item(struct spoe_frame *frame, const char **buf, const if (_ERROR(retval)) f_log(frame, _E("Failed to decode K/V item")); - return retval; + DBG_RETURN_INT(retval); } @@ -493,7 +493,7 @@ int spoe_decode_kv(struct spoe_frame *frame, const char **buf, const char *end, if (_ERROR(retval) || _NULL(str)) { FC_PTR->status_code = SPOE_FRM_ERR_INVALID; - return FUNC_RET_ERROR; + DBG_RETURN_INT(FUNC_RET_ERROR); } F_DBG(SPOA, frame, "K/V item: key=%.*s", (int)len, str); @@ -520,14 +520,14 @@ int spoe_decode_kv(struct spoe_frame *frame, const char **buf, const char *end, if (_ERROR(spoe_skip_data(&ptr, end))) { FC_PTR->status_code = SPOE_FRM_ERR_INVALID; - return FUNC_RET_ERROR; + DBG_RETURN_INT(FUNC_RET_ERROR); } } } SPOE_BUFFER_ADVANCE(retval); - return retval; + DBG_RETURN_INT(retval); } @@ -571,7 +571,7 @@ int spoe_decode_skip_msg(struct spoe_frame *frame, const char **buf, const char SPOE_BUFFER_ADVANCE(retval); - return retval; + DBG_RETURN_INT(retval); } @@ -618,9 +618,9 @@ int spoe_decode_frame(const char *msg, struct spoe_frame *frame, uint8_t spoe_ty msg, stype, flags, stream_id, frame_id); if (_ERROR(retval)) - return retval; + DBG_RETURN_INT(retval); else if (stype != spoe_type) - return spoe_retval; + DBG_RETURN_INT(spoe_retval); frame->flags = ntohl(flags); frame->offset = retval; @@ -640,7 +640,7 @@ int spoe_decode_frame(const char *msg, struct spoe_frame *frame, uint8_t spoe_ty || (frame->frame_id != frame_id)) { FC_PTR->status_code = SPOE_FRM_ERR_INTERLACED_FRAMES; - return FUNC_RET_ERROR; + DBG_RETURN_INT(FUNC_RET_ERROR); } } else if (TEST_OR2(stype, SPOE_FRM_T_HAPROXY_DISCON, SPOE_FRM_T_HAPROXY_HELLO)) { @@ -648,14 +648,14 @@ int spoe_decode_frame(const char *msg, struct spoe_frame *frame, uint8_t spoe_ty if (!(frame->flags & SPOE_FRM_FL_FIN)) { FC_PTR->status_code = SPOE_FRM_ERR_FRAG_NOT_SUPPORTED; - return FUNC_RET_ERROR; + DBG_RETURN_INT(FUNC_RET_ERROR); } /* stream-id and frame-id must be cleared. */ if ((stream_id != 0) || (frame_id != 0)) { FC_PTR->status_code = SPOE_FRM_ERR_INVALID; - return FUNC_RET_ERROR; + DBG_RETURN_INT(FUNC_RET_ERROR); } } @@ -675,7 +675,7 @@ int spoe_decode_frame(const char *msg, struct spoe_frame *frame, uint8_t spoe_ty else f_log(frame, _E("--> %s Failed to decode frame"), msg); - return retval; + DBG_RETURN_INT(retval); } /* diff --git a/src/spoe-encode.c b/src/spoe-encode.c index 092b0bc..abb1c15 100644 --- a/src/spoe-encode.c +++ b/src/spoe-encode.c @@ -193,7 +193,7 @@ static int spoe_vencode(struct spoe_frame *frame, char **buf, int type, va_list SPOE_BUFFER_ADVANCE(retval); - return retval; + DBG_RETURN_INT(retval); } @@ -278,7 +278,7 @@ int spoe_encode_frame(const char *msg, struct spoe_frame *frame, uint8_t spoa_ty else f_log(frame, _E("<-- %s Failed to encode frame"), msg); - return retval; + DBG_RETURN_INT(retval); } /* diff --git a/src/spop-ack.c b/src/spop-ack.c index 8f8dfd2..a129200 100644 --- a/src/spop-ack.c +++ b/src/spop-ack.c @@ -49,7 +49,7 @@ int prepare_agentack(struct spoe_frame *frame) SPOE_ENC_VARINT, frame->frame_id, SPOE_ENC_END); - return retval; + DBG_RETURN_INT(retval); } /* diff --git a/src/spop-disconnect.c b/src/spop-disconnect.c index 20e7e49..e592221 100644 --- a/src/spop-disconnect.c +++ b/src/spop-disconnect.c @@ -47,7 +47,7 @@ static int check_discon_status_code_cb(struct spoe_frame *frame __maybe_unused, F_DBG(SPOA, frame, "--> HAPROXY-DISCONNECT status code: %d (%s)", (int)status, spoe_frm_err_reasons(status)); #endif - return FUNC_RET_OK; + DBG_RETURN_INT(FUNC_RET_OK); } @@ -79,7 +79,7 @@ static int check_discon_message_cb(struct spoe_frame *frame __maybe_unused, void F_DBG(SPOA, frame, "--> HAPROXY-DISCONNECT message: %.*s", (int)len, str); #endif - return FUNC_RET_OK; + DBG_RETURN_INT(FUNC_RET_OK); } @@ -108,7 +108,7 @@ int handle_hadiscon(struct spoe_frame *frame) /* Check frame type: we really want a DISCONNECT frame */ retval = spoe_decode_frame("HAPROXY-DISCONNECT", frame, SPOE_FRM_T_HAPROXY_DISCON, FUNC_RET_ERROR, SPOE_DEC_END); if (_ERROR(retval)) - return retval; + DBG_RETURN_INT(retval); buf = frame->buf + frame->offset; end = frame->buf + frame->len; @@ -121,7 +121,7 @@ int handle_hadiscon(struct spoe_frame *frame) if (_nERROR(retval)) retval = buf - frame->buf; - return retval; + DBG_RETURN_INT(retval); } @@ -165,7 +165,7 @@ int prepare_agentdicon(struct spoe_frame *frame) F_DBG(SPOA, frame, "<-- AGENT-DISCONNECT status code: %u", FC_PTR->status_code); F_DBG(SPOA, frame, "<-- AGENT-DISCONNECT message: %s", reason); - return retval; + DBG_RETURN_INT(retval); } /* diff --git a/src/spop-hello.c b/src/spop-hello.c index ba492b5..77896ba 100644 --- a/src/spop-hello.c +++ b/src/spop-hello.c @@ -49,7 +49,7 @@ static int check_proto_version_cb(struct spoe_frame *frame __maybe_unused, void if (_nNULL(str)) F_DBG(SPOA, frame, "--> HAPROXY-HELLO supported versions: %.*s", len, str); - return retval; + DBG_RETURN_INT(retval); } @@ -81,7 +81,7 @@ static int check_max_frame_size_cb(struct spoe_frame *frame, void *arg1, void *a F_DBG(SPOA, frame, "--> HAPROXY-HELLO maximum frame size: %"PRIu64, size); - return FUNC_RET_OK; + DBG_RETURN_INT(FUNC_RET_OK); } @@ -112,7 +112,7 @@ static int check_healthcheck_cb(struct spoe_frame *frame, void *arg1, void *arg2 F_DBG(SPOA, frame, "--> HAPROXY-HELLO healthcheck: %s", STR_BOOL(frame->hcheck)); - return FUNC_RET_OK; + DBG_RETURN_INT(FUNC_RET_OK); } @@ -149,7 +149,7 @@ static int check_capabilities_cb(struct spoe_frame *frame, void *arg1, void *arg * argument arg1 which is a NULL pointer. */ if (_NULL(str)) - return retval; + DBG_RETURN_INT(retval); while (len > 0) { /* Skip leading spaces. */ @@ -196,7 +196,7 @@ static int check_capabilities_cb(struct spoe_frame *frame, void *arg1, void *arg FC_PTR->async ? STR_CAP_ASYNC : "", FC_PTR->fragmentation ? STR_CAP_FRAGMENTATION : ""); - return retval; + DBG_RETURN_INT(retval); } @@ -232,7 +232,7 @@ static int check_engine_id_cb(struct spoe_frame *frame, void *arg1, void *arg2) F_DBG(SPOA, frame, "--> HAPROXY-HELLO engine id: %.*s", len, str); - return retval; + DBG_RETURN_INT(retval); } @@ -256,7 +256,7 @@ static void use_spoe_engine(struct client *client) DBG_FUNC(CW_PTR, "%p", client); if (_NULL(client->engine_id)) - return; + DBG_RETURN(); list_for_each_entry(e, &(CW_PTR->engines), list) if (strcmp(e->id, client->engine_id) == 0) @@ -267,7 +267,7 @@ static void use_spoe_engine(struct client *client) c_log(client, _E("--> HAPROXY-HELLO Failed to allocate memory: %m")); - return; + DBG_RETURN(); } e->id = strdup(client->engine_id); @@ -281,6 +281,8 @@ static void use_spoe_engine(struct client *client) end: client->engine = e; LIST_ADDQ(&(e->clients), &(client->by_engine)); + + DBG_RETURN(); } @@ -309,7 +311,7 @@ int handle_hahello(struct spoe_frame *frame) /* Check frame type: we really want a HELLO frame. */ retval = spoe_decode_frame("HAPROXY-HELLO", frame, SPOE_FRM_T_HAPROXY_HELLO, FUNC_RET_ERROR, SPOE_DEC_END); if (_ERROR(retval)) - return retval; + DBG_RETURN_INT(retval); buf = frame->buf + retval; end = frame->buf + frame->len; @@ -323,7 +325,7 @@ int handle_hahello(struct spoe_frame *frame) SPOE_DEC_STR, "engine-id", 9, check_engine_id_cb, SPOE_DEC_END); if (_ERROR(retval)) - return retval; + DBG_RETURN_INT(retval); retval = buf - frame->buf; @@ -334,7 +336,7 @@ int handle_hahello(struct spoe_frame *frame) if (FC_PTR->async) use_spoe_engine(FC_PTR); - return retval; + DBG_RETURN_INT(retval); } @@ -394,7 +396,7 @@ int prepare_agenthello(struct spoe_frame *frame) F_DBG(SPOA, frame, "<-- AGENT-HELLO maximum frame size: %u", FC_PTR->max_frame_size); F_DBG(SPOA, frame, "<-- AGENT-HELLO capabilities: %.*s", (int)(ptr - cap), cap); - return retval; + DBG_RETURN_INT(retval); } /* diff --git a/src/spop-notify.c b/src/spop-notify.c index 97e1dec..646930f 100644 --- a/src/spop-notify.c +++ b/src/spop-notify.c @@ -43,13 +43,13 @@ int handle_hanotify(struct spoe_frame *frame) /* Check frame type. Retrieve flags, stream-id and frame-id. */ rc = spoe_decode_frame("HAPROXY-NOTIFY", frame, SPOE_FRM_T_HAPROXY_NOTIFY, 0, SPOE_DEC_END); if (_ERROR(rc) || (rc == 0)) - return rc; + DBG_RETURN_INT(rc); /* Check if fragmentation is supported. */ if (!(frame->flags & SPOE_FRM_FL_FIN) && !(cfg.cap_flags & FLAG_CAP_FRAGMENTATION)) { FC_PTR->status_code = SPOE_FRM_ERR_FRAG_NOT_SUPPORTED; - return FUNC_RET_ERROR; + DBG_RETURN_INT(FUNC_RET_ERROR); } F_DBG(SPOA, frame, "--> HAPROXY-NOTIFY - %sfragmented frame received" @@ -57,7 +57,7 @@ int handle_hanotify(struct spoe_frame *frame) (frame->flags & SPOE_FRM_FL_FIN) ? "un" : "", frame->frag.len, frame->len, frame->offset); - return acc_payload(frame); + DBG_RETURN_INT(acc_payload(frame)); } /* diff --git a/src/spop-unset.c b/src/spop-unset.c index 73855ce..3f0d6e6 100644 --- a/src/spop-unset.c +++ b/src/spop-unset.c @@ -43,13 +43,13 @@ int handle_hafrag(struct spoe_frame *frame) /* Check frame type, stream-id and frame-id. Retrieve flags. */ rc = spoe_decode_frame("UNSET", frame, SPOE_FRM_T_UNSET, 0, SPOE_DEC_END); if (_ERROR(rc) || (rc == 0)) - return rc; + DBG_RETURN_INT(rc); /* Check if fragmentation is supported. */ if (!(cfg.cap_flags & FLAG_CAP_FRAGMENTATION)) { FC_PTR->status_code = SPOE_FRM_ERR_FRAG_NOT_SUPPORTED; - return FUNC_RET_ERROR; + DBG_RETURN_INT(FUNC_RET_ERROR); } if (frame->flags & SPOE_FRM_FL_ABRT) { @@ -57,7 +57,7 @@ int handle_hafrag(struct spoe_frame *frame) " - frag_len=%zu - len=%zu - offset=%zu", frame->frag.len, frame->len, frame->offset); - return 0; + DBG_RETURN_INT(0); } F_DBG(SPOA, frame, "--> UNSET - %s fragment of a fragmented frame received" @@ -65,7 +65,7 @@ int handle_hafrag(struct spoe_frame *frame) (frame->flags & SPOE_FRM_FL_FIN) ? "last" : "next", frame->frag.len, frame->len, frame->offset); - return acc_payload(frame); + DBG_RETURN_INT(acc_payload(frame)); } /* diff --git a/src/tcp.c b/src/tcp.c index c7fbb9d..f27f8d9 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -72,7 +72,7 @@ ssize_t tcp_recv(struct spoe_frame *frame, size_t len, const char *msg) if (_ERROR(retval)) c_log(FC_PTR, _E("Failed to receive frame%s: %m"), msg); - return retval; + DBG_RETURN_SSIZE(retval); } @@ -129,7 +129,7 @@ ssize_t tcp_send(const struct client *client, struct spoe_frame *frame, size_t l if (_ERROR(retval)) c_log(client, _E("Failed to send frame%s: %m"), msg); - return retval; + DBG_RETURN_SSIZE(retval); } /* diff --git a/src/util.c b/src/util.c index 4b138c3..d7311e1 100644 --- a/src/util.c +++ b/src/util.c @@ -41,12 +41,12 @@ void *mem_dup(const void *s, size_t size) DBG_FUNC(NULL, "%p, %zu", s, size); if (_NULL(retptr = malloc(size + 1))) - return retptr; + DBG_RETURN_PTR(retptr); (void)memcpy(retptr, s, size); ((uint8_t *)retptr)[size] = '\0'; - return retptr; + DBG_RETURN_PTR(retptr); } @@ -68,12 +68,14 @@ void buffer_init(struct buffer *data) DBG_FUNC(NULL, "%p", data); if (_NULL(data)) - return; + DBG_RETURN(); - W_DBG(NOTICE, NULL, " initializing buffer { { %p %p } %p %zu/%zu }", data->list.p, data->list.n, data->ptr, data->len, data->size); + W_DBG(NOTICE, NULL, "initializing buffer { { %p %p } %p %zu/%zu }", data->list.p, data->list.n, data->ptr, data->len, data->size); (void)memset(data, 0, sizeof(*data)); LIST_INIT(&(data->list)); + + DBG_RETURN(); } @@ -95,9 +97,9 @@ void buffer_free(struct buffer *data) DBG_FUNC(NULL, "%p", data); if (_NULL(data)) - return; + DBG_RETURN(); - W_DBG(NOTICE, NULL, " freeing buffer { { %p %p } %p %zu/%zu }", data->list.p, data->list.n, data->ptr, data->len, data->size); + W_DBG(NOTICE, NULL, "freeing buffer { { %p %p } %p %zu/%zu }", data->list.p, data->list.n, data->ptr, data->len, data->size); if (_nNULL(data->list.p) && _nNULL(data->list.n)) LIST_DEL(&(data->list)); @@ -105,6 +107,8 @@ void buffer_free(struct buffer *data) PTR_FREE(data->ptr); (void)memset(data, 0, sizeof(*data)); LIST_INIT(&(data->list)); + + DBG_RETURN(); } @@ -152,7 +156,7 @@ struct buffer *buffer_alloc(size_t size, const void *src, ...) va_end(ap); } - return retptr; + DBG_RETURN_PTR(retptr); } @@ -174,10 +178,12 @@ void buffer_ptr_free(struct buffer **data) DBG_FUNC(NULL, "%p:%p", DPTR_ARGS(data)); if (_NULL(data) || _NULL(*data)) - return; + DBG_RETURN(); buffer_free(*data); PTR_FREE(*data); + + DBG_RETURN(); } @@ -205,7 +211,7 @@ ssize_t buffer_grow(struct buffer *data, const void *src, size_t n) DBG_FUNC(NULL, "%p, %p, %zu", data, src, n); if (_NULL(data)) - return retval; + DBG_RETURN_SSIZE(retval); if (_NULL(data->ptr)) buffer_init(data); @@ -227,7 +233,7 @@ ssize_t buffer_grow(struct buffer *data, const void *src, size_t n) w_log(NULL, _E("Failed to allocate data: %m")); } else { - W_DBG(NOTICE, NULL, " reallocating buffer { %p %zu/%zu } -> { %p %zu/%zu }", + W_DBG(NOTICE, NULL, "reallocating buffer { %p %zu/%zu } -> { %p %zu/%zu }", data->ptr, data->len, data->size, ptr, data->len + (_NULL(src) ? 0 : n), data->size + size); if (_NULL(src)) { @@ -247,7 +253,7 @@ ssize_t buffer_grow(struct buffer *data, const void *src, size_t n) retval = data->len; } - return retval; + DBG_RETURN_SSIZE(retval); } @@ -274,7 +280,7 @@ ssize_t buffer_grow_va(struct buffer *data, const void *src, size_t n, ...) DBG_FUNC(NULL, "%p, %p, %zu, ...", data, src, n); if (_NULL(data)) - return retval; + DBG_RETURN_SSIZE(retval); va_start(ap, n); while (_nNULL(src) && (n > 0)) { @@ -286,7 +292,7 @@ ssize_t buffer_grow_va(struct buffer *data, const void *src, size_t n, ...) } va_end(ap); - return retval; + DBG_RETURN_SSIZE(retval); } @@ -476,9 +482,9 @@ const char *str_delay(uint64_t delay_us) else if (delay_us > 0) (void)snprintf(BUFFER_ADDRSIZE(retbuf), "%"PRIu64"us", delay_us); else - return "0"; + DBG_RETURN_CPTR("0"); - return BUFFER(retbuf); + DBG_RETURN_CPTR(BUFFER(retbuf)); } @@ -536,7 +542,7 @@ int getopt_shortopts(const struct option *longopts, char *shortopts, size_t size errno = EINVAL; } - return retval; + DBG_RETURN_INT(retval); } @@ -587,7 +593,7 @@ uint64_t parse_delay_us(const char *delay, uint64_t val_min, uint64_t val_max) retval = ULLONG_MAX; } - return retval; + DBG_RETURN_U64(retval); } @@ -626,7 +632,7 @@ int parse_hostname(const char *hostname) freeaddrinfo(res); - return retval; + DBG_RETURN_INT(retval); } @@ -653,7 +659,7 @@ char *parse_url(const char *url) DBG_FUNC(NULL, "\"%s\"", url); if (_NULL(url)) - return retptr; + DBG_RETURN_PTR(retptr); len = strlen(url); @@ -666,13 +672,13 @@ char *parse_url(const char *url) else { w_log(NULL, _E("Invalid URL scheme '%s'"), url); - return retptr; + DBG_RETURN_PTR(retptr); } if (_NULL(retptr = mem_dup(url, len))) { w_log(NULL, _E("Failed to allocate data: %m")); - return retptr; + DBG_RETURN_PTR(retptr); } /* @@ -711,7 +717,7 @@ char *parse_url(const char *url) path = *ptr; *ptr = '\0'; - W_DBG(UTIL, NULL, " host: \"%s\", port: \"%s\", path: '%c'", host, port, path); + W_DBG(UTIL, NULL, "host: \"%s\", port: \"%s\", path: '%c'", host, port, path); if (_ERROR(parse_hostname(host))) { w_log(NULL, _E("Invalid hostname '%s'"), host); @@ -733,10 +739,10 @@ char *parse_url(const char *url) /* Return the first character of the . */ *ptr = path; - W_DBG(UTIL, NULL, " URL: \"%s\"", retptr); + W_DBG(UTIL, NULL, "URL: \"%s\"", retptr); } - return retptr; + DBG_RETURN_PTR(retptr); } @@ -817,10 +823,11 @@ void c_log(const struct client *client, const char *format, ...) runtime = LOG_RUNTIME(time_elapsed(&(prg.start_time)), time_elapsed(NULL)); if (_NULL(client) || _NULL(CW_PTR)) - (void)snprintf(fmt, sizeof(fmt), LOG_FMT "%s\n", thread_id(), runtime, format); + (void)snprintf(fmt, sizeof(fmt), LOG_FMT LOG_FMT_INDENT "%s\n", + thread_id(), runtime, LOG_INDENT format); else - (void)snprintf(fmt, sizeof(fmt), LOG_FMT " <%lu:%d> %s\n", CW_PTR->id, - runtime, client->id, client->fd, format); + (void)snprintf(fmt, sizeof(fmt), LOG_FMT LOG_FMT_INDENT "<%lu:%d> %s\n", + CW_PTR->id, runtime, LOG_INDENT client->id, client->fd, format); va_start(ap, format); (void)vfprintf(stdout, fmt, ap); @@ -851,11 +858,12 @@ void f_log(const struct spoe_frame *frame, const char *format, ...) runtime = LOG_RUNTIME(time_elapsed(&(prg.start_time)), time_elapsed(NULL)); if (_NULL(frame) || _NULL(FC_PTR)) - (void)snprintf(fmt, sizeof(fmt), LOG_FMT "%s\n", thread_id(), runtime, format); + (void)snprintf(fmt, sizeof(fmt), LOG_FMT LOG_FMT_INDENT "%s\n", + thread_id(), runtime, LOG_INDENT format); else - (void)snprintf(fmt, sizeof(fmt), LOG_FMT " <%lu> %s\n", + (void)snprintf(fmt, sizeof(fmt), LOG_FMT LOG_FMT_INDENT "<%lu> %s\n", STRUCT_ELEM(FW_PTR, id, thread_id()), - runtime, FC_PTR->id, format); + runtime, LOG_INDENT FC_PTR->id, format); va_start(ap, format); (void)vfprintf(stdout, fmt, ap); @@ -882,10 +890,10 @@ void w_log(const struct worker *worker, const char *format, ...) va_list ap; char fmt[BUFSIZ]; - (void)snprintf(fmt, sizeof(fmt), LOG_FMT "%s\n", + (void)snprintf(fmt, sizeof(fmt), LOG_FMT LOG_FMT_INDENT "%s\n", STRUCT_ELEM(worker, id, thread_id()), LOG_RUNTIME(time_elapsed(&(prg.start_time)), time_elapsed(NULL)), - format); + LOG_INDENT format); va_start(ap, format); (void)vfprintf(stdout, fmt, ap); @@ -920,7 +928,7 @@ int socket_set_nonblocking(int fd) else retval = FUNC_RET_OK; - return retval; + DBG_RETURN_INT(retval); } @@ -983,7 +991,7 @@ int socket_set_keepalive(int socket_fd, int alive, int idle, int intvl, int cnt) if (_nERROR(retval) && IN_RANGE(alive, 0, 1)) retval = setsockopt(socket_fd, SOL_SOCKET, SO_KEEPALIVE, &alive, sizeof(alive)); - return retval; + DBG_RETURN_INT(retval); } @@ -1008,15 +1016,15 @@ int rlimit_setnofile(void) DBG_FUNC(NULL, ""); if (_ERROR(retval = getrlimit(RLIMIT_NOFILE, &nofile))) - return retval; + DBG_RETURN_INT(retval); nofile.rlim_cur = nofile.rlim_max; - W_DBG(UTIL, NULL, " setting RLIMIT_NOFILE to %lu", nofile.rlim_cur); + W_DBG(UTIL, NULL, "setting RLIMIT_NOFILE to %lu", nofile.rlim_cur); retval = setrlimit(RLIMIT_NOFILE, &nofile); - return retval; + DBG_RETURN_INT(retval); } @@ -1077,7 +1085,7 @@ int logfile(const char *filename) else { (void)fprintf(stderr, "ERROR: invalid logfile mode '%c'\n", filename[0]); - return retval; + DBG_RETURN_INT(retval); } filename += 2; @@ -1108,7 +1116,7 @@ int logfile(const char *filename) logfile_mark("start"); } - return retval; + DBG_RETURN_INT(retval); } @@ -1135,7 +1143,7 @@ int pidfile(const char *filename, int *fd) if (_NULL(filename)) { if (*fd < 0) - return retval; + DBG_RETURN_INT(retval); n = snprintf(buffer, sizeof(buffer), "%"PRI_PIDT"\n", getpid()); if (IN_RANGE(n, 0, (int)SIZEOF_N(buffer, 1))) { @@ -1163,7 +1171,7 @@ int pidfile(const char *filename, int *fd) } } - return retval; + DBG_RETURN_INT(retval); } @@ -1200,13 +1208,13 @@ int daemonize(bool_t flag_chdir, bool_t flag_fdclose, int *fd, size_t n) /* Fork, parent terminates, child-1 continues. */ if (_ERROR(pidf = fork())) - return FUNC_RET_ERROR; + DBG_RETURN_INT(FUNC_RET_ERROR); else if (pidf > 0) _exit(0); /* Become session leader. */ if (_ERROR(setsid())) - return FUNC_RET_ERROR; + DBG_RETURN_INT(FUNC_RET_ERROR); #ifdef DEBUG pid[1] = getpid(); @@ -1216,7 +1224,7 @@ int daemonize(bool_t flag_chdir, bool_t flag_fdclose, int *fd, size_t n) (void)signal(SIGCHLD, SIG_IGN); (void)signal(SIGHUP, SIG_IGN); if (_ERROR(pidf = fork())) - return FUNC_RET_ERROR; + DBG_RETURN_INT(FUNC_RET_ERROR); else if (pidf > 0) _exit(0); @@ -1240,34 +1248,34 @@ int daemonize(bool_t flag_chdir, bool_t flag_fdclose, int *fd, size_t n) else if (_nNULL(fd) && (n > 0)) { for (j = 0; (j < n) && (fd[j] != i); j++); if (j < n) { - W_DBG(UTIL, NULL, " fd %d skipped", i); + W_DBG(UTIL, NULL, "fd %d skipped", i); continue; } } if (_OK(close(i))) - W_DBG(UTIL, NULL, " fd %d closed", i); + W_DBG(UTIL, NULL, "fd %d closed", i); } if (flag_fdclose) { /* Close off stdin, stdout and stderr. */ if (_ERROR(close(STDIN_FILENO))) - W_DBG(UTIL, NULL, " cannot close fd %d: %m", STDIN_FILENO); + W_DBG(UTIL, NULL, "cannot close fd %d: %m", STDIN_FILENO); if (_ERROR(close(STDERR_FILENO))) - W_DBG(UTIL, NULL, " cannot close fd %d: %m", STDERR_FILENO); + W_DBG(UTIL, NULL, "cannot close fd %d: %m", STDERR_FILENO); if (_ERROR(close(STDOUT_FILENO))) - W_DBG(UTIL, NULL, " cannot close fd %d: %m", STDOUT_FILENO); + W_DBG(UTIL, NULL, "cannot close fd %d: %m", STDOUT_FILENO); /* Redirect stdin, stdout and stderr to /dev/null. */ (void)open("/dev/null", O_RDONLY); (void)open("/dev/null", O_RDWR); (void)open("/dev/null", O_RDWR); } else { - W_DBG(UTIL, NULL, " pids: %"PRI_PIDT" -> %"PRI_PIDT" -> %"PRI_PIDT, VAL_ARRAY3(pid)); + W_DBG(UTIL, NULL, "pids: %"PRI_PIDT" -> %"PRI_PIDT" -> %"PRI_PIDT, VAL_ARRAY3(pid)); } - return FUNC_RET_OK; + DBG_RETURN_INT(FUNC_RET_OK); } /* diff --git a/src/worker.c b/src/worker.c index ae16757..2e978c1 100644 --- a/src/worker.c +++ b/src/worker.c @@ -42,6 +42,8 @@ static void worker_async_cb(struct ev_loop *loop __maybe_unused, struct ev_async DBG_FUNC(w, "%p, %p, 0x%08x", loop, ev, revents); #endif + + DBG_RETURN(); } @@ -64,6 +66,8 @@ static void worker_async_init(struct worker *worker) ev_async_init(&(worker->ev_async), worker_async_cb); ev_async_start(worker->ev_base, &(worker->ev_async)); + + DBG_RETURN(); } @@ -104,11 +108,11 @@ static int bind_server_socket(struct addrinfo *ai) flag_ok = 1; if (flag_ok) - W_DBG(WORKER, NULL, " Server socket created: %d", retval); + W_DBG(WORKER, NULL, "Server socket created: %d", retval); else FD_CLOSE(retval); - return retval; + DBG_RETURN_INT(retval); } @@ -146,15 +150,15 @@ static int create_server_socket(void) w_log(NULL, _E("Failed to get address info for '%s': %s"), cfg.server_address, gai_strerror(rc)); } else { for (ai = res; _nNULL(ai); ai = ai->ai_next) { - W_DBG(INFO, NULL, (ai == res) ? " --- addrinfo: %p" : " ---", ai); - W_DBG(INFO, NULL, " ai_flags: %d", ai->ai_flags); - W_DBG(INFO, NULL, " ai_family: %d", ai->ai_family); - W_DBG(INFO, NULL, " ai_socktype: %d", ai->ai_socktype); - W_DBG(INFO, NULL, " ai_protocol: %d", ai->ai_protocol); - W_DBG(INFO, NULL, " ai_addrlen: %d", ai->ai_addrlen); - W_DBG(INFO, NULL, " ai_canonname: \"%s\"", ai->ai_canonname); - W_DBG(INFO, NULL, " ai_addr: %p", ai->ai_addr); - W_DBG(INFO, NULL, " ai_next: %p", ai->ai_next); + W_DBG(INFO, NULL, (ai == res) ? "--- addrinfo: %p" : "---", ai); + W_DBG(INFO, NULL, " ai_flags: %d", ai->ai_flags); + W_DBG(INFO, NULL, " ai_family: %d", ai->ai_family); + W_DBG(INFO, NULL, " ai_socktype: %d", ai->ai_socktype); + W_DBG(INFO, NULL, " ai_protocol: %d", ai->ai_protocol); + W_DBG(INFO, NULL, " ai_addrlen: %d", ai->ai_addrlen); + W_DBG(INFO, NULL, " ai_canonname: \"%s\"", ai->ai_canonname); + W_DBG(INFO, NULL, " ai_addr: %p", ai->ai_addr); + W_DBG(INFO, NULL, " ai_next: %p", ai->ai_next); /* * getaddrinfo() returns a list of address structures. @@ -171,7 +175,7 @@ static int create_server_socket(void) if (_ERROR(retval)) w_log(NULL, _E("Failed to create server socket: %m")); - return retval; + DBG_RETURN_INT(retval); } @@ -198,9 +202,11 @@ static void worker_thread_monitor_cb(struct ev_loop *loop __maybe_unused, struct DBG_FUNC(w, "%p, %p, 0x%08x", loop, ev, revents); if (w->nbclients || ev_async_pending(&(w->ev_async))) - W_DBG(WORKER, w, " %u clients connected (%u frames), async event %spending", + W_DBG(WORKER, w, "%u clients connected (%u frames), async event %spending", w->nbclients, w->nbframes, ev_async_pending(&(w->ev_async)) ? "" : "not "); #endif + + DBG_RETURN(); } @@ -230,7 +236,9 @@ __noreturn static void *worker_thread_exit(struct worker *worker) worker->ev_base = NULL; } - W_DBG(WORKER, worker, " Worker is stopped"); + W_DBG(WORKER, worker, "Worker is stopped"); + + DBG_FUNC_END("} = %p", NULL); pthread_exit(NULL); } @@ -259,9 +267,9 @@ static void *worker_thread(void *data) DBG_FUNC(w, "%p", data); #ifdef __linux__ - W_DBG(WORKER, w, " Worker started, thread id: %"PRI_PTHREADT, syscall(SYS_gettid)); + W_DBG(WORKER, w, "Worker started, thread id: %"PRI_PTHREADT, syscall(SYS_gettid)); #else - W_DBG(WORKER, w, " Worker started, thread id: %"PRI_PTHREADT, pthread_self()); + W_DBG(WORKER, w, "Worker started, thread id: %"PRI_PTHREADT, pthread_self()); #endif /* Can w->thread be used instead of the function pthread_self()? */ @@ -277,10 +285,10 @@ static void *worker_thread(void *data) if (_NULL(w->ev_base)) { w_log(w, _F("Failed to initialize libev for worker %02d: %m"), w->id); - return worker_thread_exit(w); + DBG_RETURN_PTR(worker_thread_exit(w)); } - W_DBG(WORKER, w, " libev: using backend '%s'", ev_backend_type(w->ev_base)); + W_DBG(WORKER, w, "libev: using backend '%s'", ev_backend_type(w->ev_base)); worker_async_init(w); @@ -288,14 +296,14 @@ static void *worker_thread(void *data) if (_nNULL(cfg.mir_url) && _ERROR(mir_curl_init(w->ev_base, &(w->ev_async), &(w->curl)))) { w_log(w, _E("Failed to initialize cURL mirroring")); - return worker_thread_exit(w); + DBG_RETURN_PTR(worker_thread_exit(w)); } #endif ev_timer_init(&(w->ev_monitor), worker_thread_monitor_cb, cfg.monitor_interval_us / 1e6, cfg.monitor_interval_us / 1e6); ev_timer_start(w->ev_base, &(w->ev_monitor)); - W_DBG(WORKER, w, " Worker ready to process client messages"); + W_DBG(WORKER, w, "Worker ready to process client messages"); (void)ev_run(w->ev_base, 0); @@ -307,7 +315,7 @@ static void *worker_thread(void *data) free(f); } - return worker_thread_exit(w); + DBG_RETURN_PTR(worker_thread_exit(w)); } @@ -330,6 +338,8 @@ static void worker_stop_ev(int revents __maybe_unused, void *base) DBG_FUNC(NULL, "0x%08x, %p", revents, base); ev_break(base, EVBREAK_ONE); + + DBG_RETURN(); } @@ -362,25 +372,27 @@ static void worker_stop(struct ev_loop *loop, const char *msg __maybe_unused) * variable flag_stop is used. */ if (flag_stop) { - W_DBG(WORKER, NULL, " Server stopping already in progress, canceled: %s", msg); + W_DBG(WORKER, NULL, "Server stopping already in progress, canceled: %s", msg); - return; + DBG_RETURN(); } flag_stop = 1; - W_DBG(WORKER, NULL, " Stopping the server, %s", msg); + W_DBG(WORKER, NULL, "Stopping the server, %s", msg); ev_once(loop, -1, 0, 0, worker_stop_ev, loop); - W_DBG(WORKER, NULL, " Main event loop stopped"); + W_DBG(WORKER, NULL, "Main event loop stopped"); for (i = 0; i < cfg.num_workers; i++) { ev_once(prg.workers[i].ev_base, -1, 0, 0, worker_stop_ev, prg.workers[i].ev_base); ev_async_send(prg.workers[i].ev_base, &(prg.workers[i].ev_async)); - W_DBG(WORKER, NULL, " Worker %02d: event loop stopped", prg.workers[i].id); + W_DBG(WORKER, NULL, "Worker %02d: event loop stopped", prg.workers[i].id); } + + DBG_RETURN(); } @@ -411,6 +423,8 @@ static void worker_signal_stop_cb(struct ev_loop *loop, struct ev_signal *ev, in (void)snprintf(buffer, sizeof(buffer), "signal received - %s (%d)", sig_name, ev->signum); worker_stop(loop, buffer); + + DBG_RETURN(); } @@ -439,6 +453,8 @@ static void worker_signal_ignore_cb(struct ev_loop *loop __maybe_unused, struct sig_name = "Unknown signal"; W_DBG(WORKER, NULL, "signal ignored - %s received (%d)", sig_name, ev->signum); + + DBG_RETURN(); } @@ -464,6 +480,8 @@ static void worker_runtime_cb(struct ev_loop *loop __maybe_unused, struct ev_tim DBG_FUNC(NULL, "%p, %p, 0x%08x", loop, ev, revents); worker_stop(loop, "runtime exceeded"); + + DBG_RETURN(); } @@ -497,24 +515,24 @@ static void worker_accept_cb(struct ev_loop *loop __maybe_unused, struct ev_io * if ((errno != EAGAIN) && (errno != EWOULDBLOCK)) w_log(w, _E("Failed to accept client connection: %m")); - return; + DBG_RETURN(); } W_DBG(WORKER, NULL, - " <%lu> New client connection accepted and assigned to worker %02d", + "<%lu> New client connection accepted and assigned to worker %02d", prg.clicount, w->id); if (_ERROR(socket_set_nonblocking(fd))) { w_log(NULL, _E("Failed to set client socket to non-blocking: %m")); (void)close(fd); - return; + DBG_RETURN(); } else if (_ERROR(socket_set_keepalive(fd, 1, -1, -1, -1))) { w_log(NULL, _E("Failed to set KEEPALIVE on server socket: %m")); (void)close(fd); - return; + DBG_RETURN(); } c = calloc(1, sizeof(*c)); @@ -522,7 +540,7 @@ static void worker_accept_cb(struct ev_loop *loop __maybe_unused, struct ev_io * w_log(w, _E("Failed to allocate memory for client state: %m")); (void)close(fd); - return; + DBG_RETURN(); } c->fd = fd; @@ -543,7 +561,9 @@ static void worker_accept_cb(struct ev_loop *loop __maybe_unused, struct ev_io * ev_io_start(w->ev_base, &(c->ev_frame_rd)); ev_async_send(w->ev_base, &(w->ev_async)); - W_DBG(WORKER, NULL, " <%lu> New read event added to worker %02d", prg.clicount, w->id); + W_DBG(WORKER, NULL, "<%lu> New read event added to worker %02d", prg.clicount, w->id); + + DBG_RETURN(); } @@ -584,7 +604,7 @@ static int worker_run_exit(int fd, struct ev_loop *ev_base, struct worker_signal FD_CLOSE(fd); PTR_FREE(prg.workers); - return retval; + DBG_RETURN_INT(retval); } @@ -621,7 +641,7 @@ int worker_run(void) if (_ERROR(rlimit_setnofile())) { w_log(NULL, _F("Failed to set file descriptors limit: %m")); - return EX_SOFTWARE; + DBG_RETURN_INT(EX_SOFTWARE); } for (i = 0; i < TABLESIZE(ev_signals); i++) @@ -632,29 +652,29 @@ int worker_run(void) if (_NULL(ev_base)) { w_log(NULL, _F("Failed to initialize libev: %m")); - return EX_SOFTWARE; + DBG_RETURN_INT(EX_SOFTWARE); } - W_DBG(WORKER, NULL, " libev: using backend '%s'", ev_backend_type(ev_base)); + W_DBG(WORKER, NULL, "libev: using backend '%s'", ev_backend_type(ev_base)); fd = create_server_socket(); if (_ERROR(fd)) { w_log(NULL, _F("Failed to create server socket")); - return worker_run_exit(fd, ev_base, ev_signals, TABLESIZE(ev_signals), &ev_accept, EX_SOFTWARE); + DBG_RETURN_INT(worker_run_exit(fd, ev_base, ev_signals, TABLESIZE(ev_signals), &ev_accept, EX_SOFTWARE)); } if (_ERROR(socket_set_nonblocking(fd))) { w_log(NULL, _F("Failed to set client socket to non-blocking: %m")); - return worker_run_exit(fd, ev_base, ev_signals, TABLESIZE(ev_signals), &ev_accept, EX_SOFTWARE); + DBG_RETURN_INT(worker_run_exit(fd, ev_base, ev_signals, TABLESIZE(ev_signals), &ev_accept, EX_SOFTWARE)); } prg.workers = calloc(cfg.num_workers, sizeof(*(prg.workers))); if (_NULL(prg.workers)) { w_log(NULL, _F("Failed to allocate memory for workers: %m")); - return worker_run_exit(fd, ev_base, ev_signals, TABLESIZE(ev_signals), &ev_accept, EX_SOFTWARE); + DBG_RETURN_INT(worker_run_exit(fd, ev_base, ev_signals, TABLESIZE(ev_signals), &ev_accept, EX_SOFTWARE)); } for (i = 0; i < cfg.num_workers; i++) { @@ -681,7 +701,7 @@ int worker_run(void) } W_DBG(WORKER, NULL, - " Server is ready" + "Server is ready" " [" STR_CAP_FRAGMENTATION "=%s - " STR_CAP_PIPELINING "=%s - " STR_CAP_ASYNC "=%s - debug=%s - max-frame-size=%u]", STR_BOOL(cfg.cap_flags & FLAG_CAP_FRAGMENTATION), STR_BOOL(cfg.cap_flags & FLAG_CAP_PIPELINING), @@ -698,10 +718,10 @@ int worker_run(void) if (rc != 0) w_log(w, _E("Failed to join worker thread %02d: %s"), w->id, strerror(rc)); - W_DBG(WORKER, NULL, " Worker %02d: terminated (%d)", w->id, rc); + W_DBG(WORKER, NULL, "Worker %02d: terminated (%d)", w->id, rc); } - return worker_run_exit(fd, ev_base, ev_signals, TABLESIZE(ev_signals), &ev_accept, EX_OK); + DBG_RETURN_INT(worker_run_exit(fd, ev_base, ev_signals, TABLESIZE(ev_signals), &ev_accept, EX_OK)); } /*