From 92d75f0dc28707e2846570fd6aff424e09ad42aa Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Wed, 6 Mar 2019 14:37:23 +0800 Subject: [PATCH] dm: replace string function api for acrn-dm String function of strlen()/vsnprintf() shuould be replaced. This patch remove the strlen(). And vsnprintf() replaced by vasprintf(). Tracked-On: #2687 Signed-off-by: Wei Liu Reviewed-by: Yonghua Huang Reviewed-by: Tianhua Sun Acked-by: Yin Fengwei --- devicemodel/include/dm_kmsg.h | 1 - devicemodel/lib/dm_kmsg.c | 14 +++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/devicemodel/include/dm_kmsg.h b/devicemodel/include/dm_kmsg.h index 51357a0c4..9ccfff154 100644 --- a/devicemodel/include/dm_kmsg.h +++ b/devicemodel/include/dm_kmsg.h @@ -8,7 +8,6 @@ #ifndef _DM_KMSG_H_ #define _DM_KMSG_H_ -#define DM_BUF 4096 #define KERN_NODE "/dev/kmsg" #define KMSG_FMT "dm_run:" diff --git a/devicemodel/lib/dm_kmsg.c b/devicemodel/lib/dm_kmsg.c index e5647291a..d2549599a 100644 --- a/devicemodel/lib/dm_kmsg.c +++ b/devicemodel/lib/dm_kmsg.c @@ -6,14 +6,13 @@ */ #include -#include +#include #include #include #include #include "dm_kmsg.h" int fd_kmsg; -char dm_buf[DM_BUF]; static int open_kmsg(void); static int close_kmsg(void); @@ -49,21 +48,26 @@ static int close_kmsg(void) void write_kmsg(const char *fmt, ...) { - int write_cnt; + int write_cnt, len; va_list args; + char *dm_buf; va_start(args, fmt); - vsnprintf(dm_buf, DM_BUF, fmt, args); + len = vasprintf(&dm_buf, fmt, args); va_end(args); + if (len == -1) { + return; + } open_kmsg(); /* write the fmt to the /dev/kmsg */ - write_cnt = write(fd_kmsg, dm_buf, strlen(dm_buf)); + write_cnt = write(fd_kmsg, dm_buf, len); if (write_cnt < 0) { perror(KMSG_FMT"write_kmsg"); } close_kmsg(); + free(dm_buf); return; }