From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20503 invoked by alias); 4 Jul 2018 10:49:50 -0000 Mailing-List: contact cygwin-cvs-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: cygwin-cvs-owner@cygwin.com Received: (qmail 20447 invoked by uid 9078); 4 Jul 2018 10:49:49 -0000 Date: Wed, 04 Jul 2018 10:49:00 -0000 Message-ID: <20180704104949.20444.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Fix a bug of psiginfo() that changes the orientation of stderr. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 3127effc6710e6233cf5b533a38e129610143242 X-Git-Newrev: 1c1cec9cdff8e71deabb896081215b58ca8b16b6 X-SW-Source: 2018-q3/txt/msg00000.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=1c1cec9cdff8e71deabb896081215b58ca8b16b6 commit 1c1cec9cdff8e71deabb896081215b58ca8b16b6 Author: Takashi Yano Date: Tue Jul 3 19:09:48 2018 +0900 Fix a bug of psiginfo() that changes the orientation of stderr. * strsig.cc (psiginfo): Fix the problem that psiginfo() changes the orientation of stderr to byte-oriented mode if stderr is not oriented yet. Diff: --- winsup/cygwin/strsig.cc | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/winsup/cygwin/strsig.cc b/winsup/cygwin/strsig.cc index 6501c27..6c7bdd3 100644 --- a/winsup/cygwin/strsig.cc +++ b/winsup/cygwin/strsig.cc @@ -10,6 +10,7 @@ details. */ #include #include #include +#include struct sigdesc { @@ -149,13 +150,29 @@ strtosigno (const char *name) return 0; } +#define ADD(str) \ +{ \ + v->iov_base = (void *)(str); \ + v->iov_len = strlen ((char *)v->iov_base); \ + v ++; \ + iov_cnt ++; \ +} + extern "C" void psiginfo (const siginfo_t *info, const char *s) { + struct iovec iov[5]; + struct iovec *v = iov; + int iov_cnt = 0; + char buf[64]; + if (s != NULL && *s != '\0') - fprintf (stderr, "%s: ", s); + { + ADD (s); + ADD (": "); + } - fprintf (stderr, "%s", strsignal (info->si_signo)); + ADD (strsignal (info->si_signo)); if (info->si_signo > 0 && info->si_signo < NSIG) { @@ -165,10 +182,12 @@ psiginfo (const siginfo_t *info, const char *s) case SIGBUS: case SIGFPE: case SIGSEGV: - fprintf (stderr, " (%d [%p])", info->si_code, info->si_addr); + snprintf (buf, sizeof(buf), + " (%d [%p])", info->si_code, info->si_addr); break; case SIGCHLD: - fprintf (stderr, " (%d %d %d %u)", info->si_code, info->si_pid, + snprintf (buf, sizeof(buf), + " (%d %d %d %u)", info->si_code, info->si_pid, info->si_status, info->si_uid); break; /* FIXME: implement si_band @@ -177,9 +196,19 @@ psiginfo (const siginfo_t *info, const char *s) break; */ default: - fprintf (stderr, " (%d %d %u)", info->si_code, info->si_pid, info->si_uid); + snprintf (buf, sizeof(buf), + " (%d %d %u)", info->si_code, info->si_pid, + info->si_uid); } + ADD (buf); } - fprintf (stderr, "\n"); +#ifdef __SCLE + ADD ((stderr->_flags & __SCLE) ? "\r\n" : "\n"); +#else + ADD ("\n"); +#endif + + fflush (stderr); + writev (fileno (stderr), iov, iov_cnt); }