All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@redhat.com>
To: Eric Sandeen <sandeen@redhat.com>, linux-xfs <linux-xfs@vger.kernel.org>
Subject: [PATCH 1/3] xfs_scrub: synchronize error levels & logging
Date: Tue, 27 Mar 2018 17:08:54 -0500	[thread overview]
Message-ID: <3b8c1fd3-46bb-39ea-fca9-63d308cbe6b4@redhat.com> (raw)
In-Reply-To: <f7ab3da2-618c-dc1c-6d95-3890cdac2b43@redhat.com>

Having only a subset of the five error_levels present in
the log_level[] array is asking for trouble when someone
tries to __str_log(S_PREEN ...) and overruns the array.

Tie it all together in a single structure that's
initialized together to make the mapping more obvious and
idiot-proof.

Fixes-coverity-id: 1433618
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

diff --git a/scrub/common.c b/scrub/common.c
index 5a37a98..02c6c9d 100644
--- a/scrub/common.c
+++ b/scrub/common.c
@@ -56,18 +56,15 @@ xfs_scrub_excessive_errors(
 	return ret;
 }
 
-static const char *err_str[] = {
-	[S_ERROR]	= "Error",
-	[S_WARN]	= "Warning",
-	[S_REPAIR]	= "Repaired",
-	[S_INFO]	= "Info",
-	[S_PREEN]	= "Optimized",
-};
-
-static int log_level[] = {
-	[S_ERROR]	= LOG_ERR,
-	[S_WARN]	= LOG_WARNING,
-	[S_INFO]	= LOG_INFO,
+static struct {
+	const char *string;
+	int loglevel;
+} err_levels[] = {
+	[S_ERROR]  = { .string = "Error",	.loglevel = LOG_ERR },
+	[S_WARN]   = { .string = "Warning",	.loglevel = LOG_WARNING },
+	[S_REPAIR] = { .string = "Repaired",	.loglevel = LOG_WARNING },
+	[S_INFO]   = { .string = "Info",	.loglevel = LOG_INFO },
+	[S_PREEN]  = { .string = "Optimized",	.loglevel = LOG_INFO }
 };
 
 /* If stream is a tty, clear to end of line to clean up progress bar. */
@@ -106,8 +103,8 @@ __str_out(
 	if (level == S_PREEN && !debug && !verbose)
 		goto out_record;
 
-	fprintf(stream, "%s%s: %s: ", stream_start(stream), _(err_str[level]),
-			descr);
+	fprintf(stream, "%s%s: %s: ", stream_start(stream),
+			err_levels[level].string, descr);
 	if (error) {
 		fprintf(stream, _("%s."), strerror_r(error, buf, DESCR_BUFSZ));
 	} else {
@@ -152,10 +149,6 @@ __str_log(
 	char			buf[LOG_BUFSZ];
 	int			sz;
 
-	/* We only want to hear about optimizing when in debug/verbose mode. */
-	if (level == S_PREEN && !debug && !verbose)
-		return;
-
 	/*
 	 * Skip logging if we're being run as a service (presumably the
 	 * service will log stdout/stderr); if we're being run in a non
@@ -168,11 +161,11 @@ __str_log(
 	snprintf(logname, LOGNAME_BUFSZ, "%s@%s", progname, ctx->mntpoint);
 	openlog(logname, LOG_PID, LOG_DAEMON);
 
-	sz = snprintf(buf, LOG_BUFSZ, "%s: ", _(err_str[level]));
+	sz = snprintf(buf, LOG_BUFSZ, "%s: ", _(err_levels[level].string));
 	va_start(args, format);
 	vsnprintf(buf + sz, LOG_BUFSZ - sz, format, args);
 	va_end(args);
-	syslog(log_level[level], "%s", buf);
+	syslog(err_levels[level].loglevel, "%s", buf);
 
 	closelog();
 }

  reply	other threads:[~2018-03-27 22:08 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-27 22:04 [PATCH 0/3] xfsprogs: misc coverity fixes Eric Sandeen
2018-03-27 22:08 ` Eric Sandeen [this message]
2018-03-27 22:14   ` [PATCH 1/3] xfs_scrub: synchronize error levels & logging Darrick J. Wong
2018-03-27 22:20     ` Eric Sandeen
2018-03-27 22:22       ` Darrick J. Wong
2018-03-27 22:27   ` [PATCH 1/3 V2] " Eric Sandeen
2018-03-27 22:31     ` Darrick J. Wong
2018-03-27 22:11 ` [PATCH 2/3] xfs_scrub: initialize movon in Eric Sandeen
2018-03-27 22:14   ` Darrick J. Wong
2018-03-27 22:14 ` [PATCH 3/3] libfrog: enforce dir XOR blkdev in __fs_table_lookup_mount Eric Sandeen
2018-03-27 22:19   ` Darrick J. Wong
2018-03-27 22:33   ` [PATCH 3/3 V2] libfrog: handle NULL dir && " Eric Sandeen
2018-03-27 22:37     ` Darrick J. Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3b8c1fd3-46bb-39ea-fca9-63d308cbe6b4@redhat.com \
    --to=sandeen@redhat.com \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.