From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id B121C138202 for ; Mon, 24 Dec 2012 05:24:00 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C0DD321C03F; Mon, 24 Dec 2012 05:23:52 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 2B9A021C032 for ; Mon, 24 Dec 2012 05:23:52 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 1A79533DA2E for ; Mon, 24 Dec 2012 05:23:51 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 849A9E5444 for ; Mon, 24 Dec 2012 05:23:49 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1356326630.9adf0645e69835f1f39c8857939209b6842fa5ee.vapier@gentoo> Subject: [gentoo-commits] proj/sandbox:master commit in: libsbutil/ X-VCS-Repository: proj/sandbox X-VCS-Files: libsbutil/sb_efuncs.c X-VCS-Directories: libsbutil/ X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: 9adf0645e69835f1f39c8857939209b6842fa5ee X-VCS-Branch: master Date: Mon, 24 Dec 2012 05:23:49 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 2fee5ad3-9745-401c-b739-1087f00f1c5e X-Archives-Hash: efee369835ca9712ed9beb61b1447860 commit: 9adf0645e69835f1f39c8857939209b6842fa5ee Author: Mike Frysinger gentoo org> AuthorDate: Mon Dec 3 04:55:40 2012 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Mon Dec 24 05:23:50 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/sandbox.git;a=commit;h=9adf0645 sb_efuncs: fix usage of portage handlers The previous change forgot to actually enable the portage helpers. This meant violation output would always get sent to /dev/tty rather than to portage's logging facilities. Enable the helper logic while also fixing a logic error with va_args (you can't re-use the same va_args). Also, in order to use these with code that watches over SIGCHLD via sigaction, we need to use sigaction ourselves to ignore that signal. This might be racy with threaded apps that fork & watch SIGCHLD. Testing in the larger world will show whether we need to revisit how we communicate with the PM. URL: http://bugs.gentoo.org/431638 Reported-by: Michael Weiser weiser.dinsnail.net> Signed-off-by: Mike Frysinger gentoo.org> --- libsbutil/sb_efuncs.c | 24 +++++++++++++++++------- 1 files changed, 17 insertions(+), 7 deletions(-) diff --git a/libsbutil/sb_efuncs.c b/libsbutil/sb_efuncs.c index 6a7a09b..64ac82f 100644 --- a/libsbutil/sb_efuncs.c +++ b/libsbutil/sb_efuncs.c @@ -26,7 +26,7 @@ static void sbio_init(void) } } -static bool try_portage_helpers = false; +static bool try_portage_helpers = true; /* * First try to use the helper programs from portage so that it can sanely @@ -39,17 +39,20 @@ static void sb_vefunc(const char *prog, const char *color, const char *format, v { char shellcode[128]; FILE *fp; - sighandler_t oldsig; + struct sigaction sa, old_sa; bool is_pipe = false; + va_list retry_args; if (try_portage_helpers) { /* If popen() fails, then writes to it will trigger SIGPIPE */ - /* XXX: convert this to sigaction */ - oldsig = signal(SIGPIPE, SIG_IGN); + sa.sa_flags = SA_RESTART; + sa.sa_handler = SIG_IGN; + sigaction(SIGCHLD, &sa, &old_sa); sprintf(shellcode, "xargs %s 2>/dev/null", prog); fp = sbio_popen(shellcode, "we"); is_pipe = true; + va_copy(retry_args, args); } else fp = NULL; @@ -68,13 +71,20 @@ static void sb_vefunc(const char *prog, const char *color, const char *format, v if (is_pipe) { int status = pclose(fp); - if (WEXITSTATUS(status)) + if (WEXITSTATUS(status)) { + args = retry_args; goto do_tty; + } } else if (fp != stderr) fclose(fp); - if (try_portage_helpers) - signal(SIGPIPE, oldsig); + if (try_portage_helpers) { + sigaction(SIGCHLD, &old_sa, NULL); + va_end(retry_args); + if (!is_pipe) + /* If we failed once, we'll fail again */ + try_portage_helpers = false; + } } void sb_einfo(const char *format, ...)