aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2009-03-14 13:27:20 -0400
committerMike Frysinger <vapier@gentoo.org>2009-03-18 01:06:20 -0400
commitf06150540e02b694ee87e89d61db8da95f42ed50 (patch)
tree3268a7cb4d1d31dd42d978c415ec677aa2017eba /libsandbox/eqawarn.c
parentbump to sandbox-1.7 (diff)
downloadsandbox-f06150540e02b694ee87e89d61db8da95f42ed50.tar.gz
sandbox-f06150540e02b694ee87e89d61db8da95f42ed50.tar.bz2
sandbox-f06150540e02b694ee87e89d61db8da95f42ed50.zip
libsandbox: add an eqawarn() func
Break out most of the QA static ELF warning code into a new eqawarn() func. This way we can handle dynamic stuff like calling portage's eqawarn func to handle dirty details like logging. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'libsandbox/eqawarn.c')
-rw-r--r--libsandbox/eqawarn.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/libsandbox/eqawarn.c b/libsandbox/eqawarn.c
new file mode 100644
index 0000000..e7b0a9c
--- /dev/null
+++ b/libsandbox/eqawarn.c
@@ -0,0 +1,49 @@
+/*
+ * Dump a QA warning
+ *
+ * Copyright 1999-2009 Gentoo Foundation
+ * Licensed under the GPL-2
+ */
+
+#include "headers.h"
+#include "libsandbox.h"
+#include "sbutil.h"
+#include "wrappers.h"
+
+/* First try to use the eqawarn program from portage. If that fails, fall
+ * back to writing to /dev/tty. While this might annoy some people, using
+ * stderr will break tests that try to validate output #261957.
+ */
+void sb_eqawarn(const char *format, ...)
+{
+ va_list args;
+ FILE *fp;
+ sighandler_t oldsig;
+ bool is_pipe;
+
+ /* If popen() fails, then writes to it will trigger SIGPIPE */
+ oldsig = signal(SIGPIPE, SIG_IGN);
+
+ fp = sb_unwrapped_popen("xargs eqawarn 2>/dev/null", "we");
+ is_pipe = true;
+ if (!fp) {
+ do_tty:
+ is_pipe = false;
+ fp = fopen("/dev/tty", "ae");
+ if (!fp)
+ fp = stderr;
+ }
+
+ sb_fprintf(fp, "QA Notice: ");
+ va_start(args, format);
+ sb_vfprintf(fp, format, args);
+ va_end(args);
+
+ if (is_pipe) {
+ int status = pclose(fp);
+ if (WEXITSTATUS(status))
+ goto do_tty;
+ }
+
+ signal(SIGPIPE, oldsig);
+}