send_common: Improve error diagnostics of generic_com_on().
authorAndre Noll <maan@tuebingen.mpg.de>
Sat, 17 Mar 2018 01:10:55 +0000 (02:10 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Tue, 17 Apr 2018 07:29:57 +0000 (09:29 +0200)
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.

dccp_send.c
http_send.c
send.h
send_common.c

index 6f9895410161e47133d65a4f0893bac14a0743b4..ac2da410b4249e6bdc9d182fcb92a04ff75c773d 100644 (file)
@@ -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);
 }
index dace5c23c6574527a6b8c26880eb63bd896b8aca..d692c2d2f3b741f093775bd983d84100bb741644 100644 (file)
@@ -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 9a6e5f745c406abe4a91f34da7a104946922c1d5..84f35f9228cd05c62f9430063123d3e49761a06c 100644 (file)
--- 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);
index 4bb50ce58d7198c4aaf6bdf456b2c5c04aaed442..5a9ddf641796931e70accd1fa1ae3a74bfbff57d 100644 (file)
@@ -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;
 }
 
 /**