[Rpm-ecosystem] Fwd: [Rpm-maint] [RFC] Move all informative messages to stderr by default (ticket #31)

Panu Matilainen pmatilai at laiskiainen.org
Tue Oct 25 08:44:42 UTC 2016


Forwarding to rpm-ecosystem for a wider audience...

	- Panu -

-------- Forwarded Message --------
Subject: [Rpm-maint] [RFC] Move all informative messages to stderr by 
default (ticket #31)
Date: Thu, 13 Oct 2016 09:41:27 +0300
From: Panu Matilainen <pmatilai at redhat.com>
To: rpm-maint at lists.rpm.org

Rpm has always spewed all sorts of "informative" messages into stdout
where it gets mixed up with user requested information such as query
output, complicating scripts unnecessarily and also breaking unix
traditions.

Make the user-requested output (namely query and verify output) go to
stdout by explicitly fprintf()'ing it there, and all of rpmlog()
output goes to stderr (or other specified logfile).

Fixes rpm.org ticket #31, RhBug:1358861, RhBug:247239, RhBug:439290...
OTOH it *will* break scripts people use for querying etc. Making
scripts compatible with both old and new behavior shouldn't be hard, but
it does require changes and some *will* complain. So obviously not
4.13 material, target would be the next major release after that.

Comments, thoughts?
---
  lib/query.c        | 10 +++++-----
  lib/rpmchecksig.c  |  4 ++--
  lib/verify.c       |  4 ++--
  rpmio/rpmlog.c     | 15 ---------------
  tests/rpmdb.at     |  6 +++---
  tests/rpmverify.at |  6 +++---
  6 files changed, 15 insertions(+), 30 deletions(-)

diff --git a/lib/query.c b/lib/query.c
index 739a0de..f007d05 100644
--- a/lib/query.c
+++ b/lib/query.c
@@ -82,7 +82,7 @@ static void printFileInfo(const char * name,
  	(void)strftime(timefield, sizeof(timefield) - 1, fmt, tm);
      }
  -    rpmlog(RPMLOG_NOTICE, "%s %4d %-8s%-8s %10s %s %s\n", perms,
+    fprintf(stdout, "%s %4d %-8s%-8s %10s %s %s\n", perms,
  	(int)nlink, ownerfield, groupfield, sizefield, timefield,  	link ? 
link : name);
      free(perms);
@@ -101,7 +101,7 @@ int showQueryPackage(QVA_t qva, rpmts ts, Header h)
  	char *str = headerFormat(h, qva->qva_queryFormat, &errstr);
   	if ( str != NULL ) {
-	    rpmlog(RPMLOG_NOTICE, "%s", str);
+	    fprintf(stdout, "%s", str);
  	    free(str);
  	} else {
  	    rpmlog(RPMLOG_ERR, _("incorrect format: %s\n"), errstr);
@@ -199,11 +199,11 @@ int showQueryPackage(QVA_t qva, rpmts ts, Header h)
  				 fflags & RPMFILE_DOC ? "1" : "0",
  				 frdev,
  				 (flink && *flink ? flink : "X"));
-	    rpmlog(RPMLOG_NOTICE, "%s%s\n", buf, add);
+	    fprintf(stdout, "%s%s\n", buf, add);
  	    free(add);
  	} else
  	if (!rpmIsVerbose()) {
-	    rpmlog(RPMLOG_NOTICE, "%s%s\n", buf ? buf : "", fn);
+	    fprintf(stdout, "%s%s\n", buf ? buf : "", fn);
  	}
  	else {
  	    uint32_t fnlink = rpmfiFNlink(fi);
@@ -219,7 +219,7 @@ int showQueryPackage(QVA_t qva, rpmts ts, Header h)
  		if (now == 0)
  		    now = time(NULL);
  		if (buf) {
-		    rpmlog(RPMLOG_NOTICE, "%s", buf);
+		    fprintf(stdout, "%s", buf);
  		}
  		printFileInfo(fn, fsize, fmode, fmtime, frdev, fnlink,
  					fuser, fgroup, flink, now);
diff --git a/lib/rpmchecksig.c b/lib/rpmchecksig.c
index f17a18a..41be147 100644
--- a/lib/rpmchecksig.c
+++ b/lib/rpmchecksig.c
@@ -330,10 +330,10 @@ static int rpmpkgVerifySigs(rpmKeyring keyring, 
rpmQueryFlags flags,
      res = failed;
       if (rpmIsVerbose()) {
-	rpmlog(RPMLOG_NOTICE, "%s", buf);
+	fprintf(stdout, "%s", buf);
      } else {
  	const char *ok = (failed ? _("NOT OK") : _("OK"));
-	rpmlog(RPMLOG_NOTICE, "%s%s%s%s%s%s%s%s\n", buf, ok,
+	fprintf(stdout, "%s%s%s%s%s%s%s%s\n", buf, ok,
  	       missingKeys ? _(" (MISSING KEYS:") : "",
  	       missingKeys ? missingKeys : "",
  	       missingKeys ? _(") ") : "",
diff --git a/lib/verify.c b/lib/verify.c
index 2ac7c08..f6afa806 100644
--- a/lib/verify.c
+++ b/lib/verify.c
@@ -449,7 +449,7 @@ static int verifyHeader(rpmts ts, Header h, 
rpmVerifyAttrs omitMask, int ghosts)
  	if (buf) {
  	    if (fstate)
  		buf = rstrscat(&buf, " (", fstate, ")", NULL);
-	    rpmlog(RPMLOG_NOTICE, "%s\n", buf);
+	    fprintf(stdout, "%s\n", buf);
  	    buf = _free(buf);
  	}
      }
@@ -486,7 +486,7 @@ static int verifyDependencies(rpmts ts, Header h)
   	while ((p = rpmpsiNext(psi)) != NULL) {
  	    char * ps = rpmProblemString(p);
-	    rpmlog(RPMLOG_NOTICE, "\t%s\n", ps);
+	    fprintf(stdout, "\t%s\n", ps);
  	    free(ps);
  	}
  	rpmpsFreeIterator(psi);
diff --git a/rpmio/rpmlog.c b/rpmio/rpmlog.c
index 43ae36f..111c754 100644
--- a/rpmio/rpmlog.c
+++ b/rpmio/rpmlog.c
@@ -176,21 +176,6 @@ static int rpmlogDefault(FILE *stdlog, rpmlogRec rec)
  {
      FILE *msgout = (stdlog ? stdlog : stderr);
  -    switch (rec->pri) {
-    case RPMLOG_INFO:
-    case RPMLOG_NOTICE:
-        msgout = (stdlog ? stdlog : stdout);
-        break;
-    case RPMLOG_EMERG:
-    case RPMLOG_ALERT:
-    case RPMLOG_CRIT:
-    case RPMLOG_ERR:
-    case RPMLOG_WARNING:
-    case RPMLOG_DEBUG:
-    default:
-        break;
-    }
-
      if (fputs(rpmlogLevelPrefix(rec->pri), msgout) == EOF && errno != 
EPIPE)
  	perror("Error occurred during writing of a log message");
  diff --git a/tests/rpmdb.at b/tests/rpmdb.at
index 3fd2974..e746d33 100644
--- a/tests/rpmdb.at
+++ b/tests/rpmdb.at
@@ -79,9 +79,9 @@ runroot rpm -q foo-
   ],
  [1],
-[package foo- is not installed
-],
-[])
+[],
+[package foo- is not installed]
+)
  AT_CLEANUP
   # ------------------------------
diff --git a/tests/rpmverify.at b/tests/rpmverify.at
index cf7abc3..49358ef 100644
--- a/tests/rpmverify.at
+++ b/tests/rpmverify.at
@@ -20,10 +20,10 @@ runroot rpm -U --nodeps 
/build/RPMS/noarch/deptest-one-1.0-1.noarch.rpm
  runroot rpm -Va --nofiles
  ],
  [1],
-[Unsatisfied dependencies for deptest-one-1.0-1.noarch:
-	deptest-two is needed by (installed) deptest-one-1.0-1.noarch
+[	deptest-two is needed by (installed) deptest-one-1.0-1.noarch
  ],
-[])
+[Unsatisfied dependencies for deptest-one-1.0-1.noarch:
+])
  AT_CLEANUP
   # Test file verify when no errors expected.
-- 
2.7.4

_______________________________________________
Rpm-maint mailing list
Rpm-maint at lists.rpm.org
http://lists.rpm.org/mailman/listinfo/rpm-maint


More information about the Rpm-ecosystem mailing list