From: Andre Noll Date: Sat, 17 Mar 2018 01:10:55 +0000 (+0100) Subject: send_common: Improve error diagnostics of generic_com_on(). X-Git-Tag: v0.6.2~17 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=2b004fc5dc0c652c6eb4daf84e5875f2c852ca72 send_common: Improve error diagnostics of generic_com_on(). Currently the function returns an error code but does not log a message on errors. The callers, http_send_init() and dccp_send_init(), print the strerror text with no indication that it is was generic_com_on() which caused the error. This commit moves the log messages from the callers to generic_com_on() and changes the return type of generic_com_on() to void because both callers now ignore the return value. The new log messages include a text which tells the user what went wrong. --- diff --git a/dccp_send.c b/dccp_send.c index 6f989541..ac2da410 100644 --- a/dccp_send.c +++ b/dccp_send.c @@ -161,7 +161,8 @@ static void dccp_post_select(fd_set *rfds, __a_unused fd_set *wfds) static int dccp_com_on(__a_unused struct sender_command_data *scd) { - return generic_com_on(dss, IPPROTO_DCCP); + generic_com_on(dss, IPPROTO_DCCP); + return 1; } static int dccp_com_off(__a_unused struct sender_command_data *scd) @@ -224,8 +225,6 @@ static char *dccp_status(void) */ void dccp_send_init(struct sender *s) { - int ret; - s->status = dccp_status; s->send = NULL; s->pre_select = dccp_pre_select; @@ -243,7 +242,5 @@ void dccp_send_init(struct sender *s) init_sender_status(dss, OPT_RESULT(DCCP_ACCESS), OPT_UINT32_VAL(DCCP_PORT), OPT_UINT32_VAL(DCCP_MAX_CLIENTS), OPT_GIVEN(DCCP_DEFAULT_DENY)); - ret = generic_com_on(dss, IPPROTO_DCCP); - if (ret < 0) - PARA_ERROR_LOG("%s\n", para_strerror(-ret)); + generic_com_on(dss, IPPROTO_DCCP); } diff --git a/http_send.c b/http_send.c index dace5c23..d692c2d2 100644 --- a/http_send.c +++ b/http_send.c @@ -209,7 +209,8 @@ static void http_pre_select(int *max_fileno, fd_set *rfds, fd_set *wfds) static int http_com_on(__a_unused struct sender_command_data *scd) { - return generic_com_on(hss, IPPROTO_TCP); + generic_com_on(hss, IPPROTO_TCP); + return 1; } static int http_com_off(__a_unused struct sender_command_data *scd) @@ -245,7 +246,6 @@ static char *http_status(void) */ void http_send_init(struct sender *s) { - int ret; s->status = http_status; s->send = http_send; s->pre_select = http_pre_select; @@ -265,7 +265,5 @@ void http_send_init(struct sender *s) OPT_GIVEN(HTTP_DEFAULT_DENY)); if (OPT_GIVEN(HTTP_NO_AUTOSTART)) return; - ret = generic_com_on(hss, IPPROTO_TCP); - if (ret < 0) - PARA_ERROR_LOG("%s\n", para_strerror(-ret)); + generic_com_on(hss, IPPROTO_TCP); } diff --git a/send.h b/send.h index 9a6e5f74..84f35f92 100644 --- a/send.h +++ b/send.h @@ -186,7 +186,7 @@ void generic_com_allow(struct sender_command_data *scd, struct sender_status *ss); void generic_com_deny(struct sender_command_data *scd, struct sender_status *ss); -int generic_com_on(struct sender_status *ss, unsigned protocol); +void generic_com_on(struct sender_status *ss, unsigned protocol); void generic_com_off(struct sender_status *ss); char *generic_sender_help(void); struct sender_client *accept_sender_client(struct sender_status *ss, fd_set *rfds); diff --git a/send_common.c b/send_common.c index 4bb50ce5..5a9ddf64 100644 --- a/send_common.c +++ b/send_common.c @@ -206,28 +206,38 @@ void generic_com_deny(struct sender_command_data *scd, * Activate a paraslash sender. * * \param ss The sender to activate. - * \param protocol The symbolic name of the transport-layer protocol. + * \param protocol layer4 type (IPPROTO_TCP or IPPROTO_DCCP). * - * \return Standard. + * This opens a passive socket of given layer4 type, sets the resulting file + * descriptor to nonblocking mode and adds it to the close on fork list. + * + * Errors are logged but otherwise ignored. */ -int generic_com_on(struct sender_status *ss, unsigned protocol) +void generic_com_on(struct sender_status *ss, unsigned protocol) { int fd, ret; if (ss->listen_fd >= 0) - return 1; + return; ret = para_listen_simple(protocol, ss->port); - if (ret < 0) - return ret; + if (ret < 0) { + PARA_ERROR_LOG("could not listen on port %d: %s\n", ss->port, + para_strerror(-ret)); + return; + } fd = ret; ret = mark_fd_nonblocking(fd); if (ret < 0) { + PARA_ERROR_LOG("could not set %s socket fd for port %d to " + "nonblocking mode: %s\n", + protocol == IPPROTO_TCP? "TCP" : "DCCP", ss->port, + para_strerror(-ret)); close(fd); - return ret; + return; } add_close_on_fork_list(fd); ss->listen_fd = ret; - return 1; + return; } /**