commit dc8f337: [Minor] Add some more logs to the erros in the control path
Vsevolod Stakhov
vsevolod at rspamd.com
Sun Nov 20 20:49:03 UTC 2022
Author: Vsevolod Stakhov
Date: 2022-11-20 20:48:26 +0000
URL: https://github.com/rspamd/rspamd/commit/dc8f337a59f4b8ce07101259d9644771b738892e (HEAD -> master)
[Minor] Add some more logs to the erros in the control path
---
src/libserver/rspamd_control.c | 64 ++++++++++++++++++++++++++++++++++++------
src/libserver/rspamd_control.h | 2 ++
2 files changed, 57 insertions(+), 9 deletions(-)
diff --git a/src/libserver/rspamd_control.c b/src/libserver/rspamd_control.c
index 63999ab6f..21a8c495e 100644
--- a/src/libserver/rspamd_control.c
+++ b/src/libserver/rspamd_control.c
@@ -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;
+}
diff --git a/src/libserver/rspamd_control.h b/src/libserver/rspamd_control.h
index c175fcc3f..049c9b80c 100644
--- a/src/libserver/rspamd_control.h
+++ b/src/libserver/rspamd_control.h
@@ -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
More information about the Commits
mailing list