aboutsummaryrefslogtreecommitdiff
blob: e7b0a9cf9f1a8277051ab3d2558a1ec22ea33556 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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);
}