diff mbox series

[ndctl,6/7] ndctl/monitor: Drop vasprintf usage

Message ID 154596783052.164521.17128650712423131724.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive)
State New, archived
Headers show
Series ndctl/monitor: Cleanups and fixes | expand

Commit Message

Dan Williams Dec. 28, 2018, 3:30 a.m. UTC
Clean up some unnecessary buffer allocations for printing, when
vfprintf() and vsyslog() can be used directly.

Cc: QI Fuli <qi.fuli@jp.fujitsu.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 ndctl/monitor.c |   43 ++++++++-----------------------------------
 1 file changed, 8 insertions(+), 35 deletions(-)
diff mbox series

Patch

diff --git a/ndctl/monitor.c b/ndctl/monitor.c
index 8a16c9664e0a..e38a570fe960 100644
--- a/ndctl/monitor.c
+++ b/ndctl/monitor.c
@@ -49,60 +49,33 @@  do { \
 static void log_syslog(struct ndctl_ctx *ctx, int priority, const char *file,
 		int line, const char *fn, const char *format, va_list args)
 {
-	char *buf;
-
-	if (vasprintf(&buf, format, args) < 0) {
-		fail("vasprintf error\n");
-		return;
-	}
-	syslog(priority, "%s", buf);
-
-	free(buf);
-	return;
+	vsyslog(priority, format, args);
 }
 
 static void log_standard(struct ndctl_ctx *ctx, int priority, const char *file,
 		int line, const char *fn, const char *format, va_list args)
 {
-	char *buf;
-
-	if (vasprintf(&buf, format, args) < 0) {
-		fail("vasprintf error\n");
-		return;
-	}
-
 	if (priority == 6)
-		fprintf(stdout, "%s", buf);
+		vfprintf(stdout, format, args);
 	else
-		fprintf(stderr, "%s", buf);
-
-	free(buf);
-	return;
+		vfprintf(stderr, format, args);
 }
 
 static void log_file(struct ndctl_ctx *ctx, int priority, const char *file,
 		int line, const char *fn, const char *format, va_list args)
 {
 	FILE *f = monitor.log_file;
-	char *buf;
-	struct timespec ts;
-	char timestamp[32];
-
-	if (vasprintf(&buf, format, args) < 0) {
-		fail("vasprintf error\n");
-		return;
-	}
 
 	if (priority != LOG_NOTICE) {
+		struct timespec ts;
+
 		clock_gettime(CLOCK_REALTIME, &ts);
-		sprintf(timestamp, "%10ld.%09ld", ts.tv_sec, ts.tv_nsec);
-		fprintf(f, "[%s] [%d] %s", timestamp, getpid(), buf);
+		fprintf(f, "[%10ld.%09ld] [%d] ", ts.tv_sec, ts.tv_nsec, getpid());
+		vfprintf(f, format, args);
 	} else
-		fprintf(f, "%s", buf);
+		vfprintf(f, format, args);
 
 	fflush(f);
-	free(buf);
-	return;
 }
 
 static struct json_object *dimm_event_to_json(struct monitor_dimm *mdimm)