aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJing Peng <pj.hades@gmail.com>2022-03-04 17:43:50 -0500
committerDamjan Marion <dmarion@me.com>2022-03-23 18:52:50 +0000
commit4859d8d8e8a4bbaac0117db827001fae6c9062b9 (patch)
treea65a02f3e4fd3c3ccc8fab58d464ee946a367272
parent9deb2ec335925e02c4e98065b374144b9acda11a (diff)
vlib: send full error message to syslog
Currently the last character of the error message string is temporarily changed to a null byte '\0' before the string is sent to syslog(3), resulting in confusingly incomplete log entries. This patch changes the syslog format to "%.*s" so that the maximum number of characters to be printed could be controlled. Type: improvement Signed-off-by: Jing Peng <pj.hades@gmail.com> Change-Id: I1bd6295c19b51b962a3d8ee3016cd91ffb2a4eaf
-rw-r--r--src/vlib/unix/main.c28
1 files changed, 6 insertions, 22 deletions
diff --git a/src/vlib/unix/main.c b/src/vlib/unix/main.c
index 8e06bfa334b..ba1c9d1bd63 100644
--- a/src/vlib/unix/main.c
+++ b/src/vlib/unix/main.c
@@ -40,6 +40,7 @@
#include <vlib/unix/unix.h>
#include <vlib/unix/plugin.h>
+#include <limits.h>
#include <signal.h>
#include <sys/ucontext.h>
#include <syslog.h>
@@ -247,14 +248,7 @@ unix_error_handler (void *arg, u8 * msg, int msg_len)
}
else
{
- char save = msg[msg_len - 1];
-
- /* Null Terminate. */
- msg[msg_len - 1] = 0;
-
- syslog (LOG_ERR | LOG_DAEMON, "%s", msg);
-
- msg[msg_len - 1] = save;
+ syslog (LOG_ERR | LOG_DAEMON, "%.*s", msg_len, msg);
}
}
@@ -267,20 +261,10 @@ vlib_unix_error_report (vlib_main_t * vm, clib_error_t * error)
return;
{
- char save;
- u8 *msg;
- u32 msg_len;
-
- msg = error->what;
- msg_len = vec_len (msg);
-
- /* Null Terminate. */
- save = msg[msg_len - 1];
- msg[msg_len - 1] = 0;
-
- syslog (LOG_ERR | LOG_DAEMON, "%s", msg);
-
- msg[msg_len - 1] = save;
+ u8 *msg = error->what;
+ u32 len = vec_len (msg);
+ int msg_len = (len > INT_MAX) ? INT_MAX : len;
+ syslog (LOG_ERR | LOG_DAEMON, "%.*s", msg_len, msg);
}
}