]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add some more logs to the erros in the control path
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sun, 20 Nov 2022 20:48:26 +0000 (20:48 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sun, 20 Nov 2022 20:48:26 +0000 (20:48 +0000)
src/libserver/rspamd_control.c
src/libserver/rspamd_control.h

index 63999ab6f611f264603091b304f9c3455f8f4153..21a8c495e8ede5058de7a84aa4ec035f8ff6125e 100644 (file)
@@ -928,8 +928,8 @@ rspamd_srv_handler (EV_P_ ev_io *w, int revents)
                        ev_io_stop (EV_A_ w);
                }
                else if (r != sizeof (cmd)) {
-                       msg_err ("cannot read from worker's srv pipe incomplete command: %d",
-                                       (gint) r);
+                       msg_err ("cannot read from worker's srv pipe incomplete command: %d != %d; command = %s",
+                                       (gint)r, sizeof(cmd), rspamd_srv_command_to_string(cmd.type));
                }
                else {
                        rdata = g_malloc0 (sizeof (*rdata));
@@ -1069,8 +1069,13 @@ rspamd_srv_handler (EV_P_ ev_io *w, int revents)
                r = sendmsg (w->fd, &msg, 0);
 
                if (r == -1) {
-                       msg_err ("cannot write to worker's srv pipe: %s",
-                                       strerror (errno));
+                       msg_err ("cannot write to worker's srv pipe when writing reply: %s; command = %s",
+                               strerror (errno), rspamd_srv_command_to_string(rdata->rep.type));
+               }
+               else if (r != sizeof (rdata->rep)) {
+                       msg_err ("cannot write to worker's srv pipe: %d != %d; command = %s",
+                               (int)r, (int)sizeof (rdata->rep),
+                               rspamd_srv_command_to_string(rdata->rep.type));
                }
 
                g_free (rdata);
@@ -1139,7 +1144,13 @@ rspamd_srv_request_handler (EV_P_ ev_io *w, int revents)
                r = sendmsg (w->fd, &msg, 0);
 
                if (r == -1) {
-                       msg_err ("cannot write to server pipe: %s", strerror (errno));
+                       msg_err ("cannot write to server pipe: %s; command = %s", strerror (errno),
+                               rspamd_srv_command_to_string(rd->cmd.type));
+                       goto cleanup;
+               }
+               else if (r != sizeof (rd->cmd)) {
+                       msg_err("incomplete write to the server pipe: %d != %d, command = %s",
+                               (int)r, (int)sizeof(rd->cmd), rspamd_srv_command_to_string(rd->cmd.type));
                        goto cleanup;
                }
 
@@ -1159,13 +1170,14 @@ rspamd_srv_request_handler (EV_P_ ev_io *w, int revents)
                r = recvmsg (w->fd, &msg, 0);
 
                if (r == -1) {
-                       msg_err ("cannot read from server pipe: %s", strerror (errno));
+                       msg_err ("cannot read from server pipe: %s; command = %s", strerror (errno),
+                               rspamd_srv_command_to_string(rd->cmd.type));
                        goto cleanup;
                }
 
-               if (r < (gint)sizeof (rd->rep)) {
-                       msg_err ("cannot read from server pipe, invalid length: %d",
-                                       (gint)r);
+               if (r != (gint)sizeof (rd->rep)) {
+                       msg_err ("cannot read from server pipe, invalid length: %d != %d; command = %s",
+                                       (gint)r, (int)sizeof (rd->rep), rspamd_srv_command_to_string(rd->cmd.type));
                        goto cleanup;
                }
 
@@ -1302,3 +1314,37 @@ rspamd_control_command_to_string (enum rspamd_control_type cmd)
 
        return reply;
 }
+
+const gchar *rspamd_srv_command_to_string (enum rspamd_srv_type cmd)
+{
+       const gchar *reply = "unknown";
+
+       switch (cmd) {
+       case RSPAMD_SRV_SOCKETPAIR:
+               reply = "socketpair";
+               break;
+       case RSPAMD_SRV_HYPERSCAN_LOADED:
+               reply = "hyperscan_loaded";
+               break;
+       case RSPAMD_SRV_MONITORED_CHANGE:
+               reply = "monitored_change";
+               break;
+       case RSPAMD_SRV_LOG_PIPE:
+               reply = "log_pipe";
+               break;
+       case RSPAMD_SRV_ON_FORK:
+               reply = "on_fork";
+               break;
+       case RSPAMD_SRV_HEARTBEAT:
+               reply = "heartbeat";
+               break;
+       case RSPAMD_SRV_HEALTH:
+               reply = "health";
+               break;
+       case RSPAMD_NOTICE_HYPERSCAN_CACHE:
+               reply = "notice_hyperscan_cache";
+               break;
+       }
+
+       return reply;
+}
index c175fcc3fe1f7a2a4a61d37a359b39521ab4e93a..049c9b80c37f10d4a94cf5b7ba043c2ba9786ad0 100644 (file)
@@ -290,6 +290,8 @@ enum rspamd_control_type rspamd_control_command_from_string (const gchar *str);
  */
 const gchar *rspamd_control_command_to_string (enum rspamd_control_type cmd);
 
+const gchar *rspamd_srv_command_to_string (enum rspamd_srv_type cmd);
+
 /**
  * Used to cleanup pending events
  * @param p