This is the mail archive of the cygwin-cvs@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[newlib-cygwin] Fix a bug of psiginfo() that changes the orientation of stderr.


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=1c1cec9cdff8e71deabb896081215b58ca8b16b6

commit 1c1cec9cdff8e71deabb896081215b58ca8b16b6
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
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 <cygtls.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/uio.h>
 
 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);
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]