[CRIU] [PATCH 07/24] compel cli: print usage to stderr in case of error

Kir Kolyshkin kir at openvz.org
Sat Dec 17 03:22:00 PST 2016


This is mainly dictated by the fact that we use stdout
from "compel *flags" in a special way, so it should not
be garbled by the usage info.

Otherwise, for example, the following code in Makefile

	CFLAGS += $(shell compel --badopt cflags)

will lead to the whole usage() output to be added to compiler flags,
which looks really really weird.

Signed-off-by: Kir Kolyshkin <kir at openvz.org>
---
 compel/src/main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/compel/src/main.c b/compel/src/main.c
index 9be3c8b..c943feb 100644
--- a/compel/src/main.c
+++ b/compel/src/main.c
@@ -110,7 +110,9 @@ static void cli_log(unsigned int lvl, const char *fmt, va_list parms)
 }
 
 static int usage(int rc) {
-	printf(
+	FILE *out = (rc == 0) ? stdout : stderr;
+
+	fprintf(out,
 "Usage:\n"
 "  compel [--compat] cflags | ldflags\n"
 "  compel -f FILE -o FILE -p NAME [-l N] hgen\n"
-- 
2.7.4



More information about the CRIU mailing list