I saw dtexec closing the pipe that it reads from to get stderr of the program it launched.
That caused the client to die when issuing error messages to stderr.
Dtterm would die on startup because of otherwise unimportant warnings about missing fonts. The root of the problem is an assumption in dtexec that fstat will report the number of readable characters in a pipe as the st_size. Recent linux kernels always return 0 for st_size of a pipe.

This patch changes dtexec Main.c to use select to check if the pipe is readable and uses a read of zero bytes to notice when the other side of the pipe is closed and
EOF is reached.
>From a127368f6b9e84ec03efa12316fc1149b8270629 Mon Sep 17 00:00:00 2001
From: Mike Stroyan <m...@stroyan.net>
Date: Sun, 9 Sep 2012 15:44:45 -0600
Subject: [PATCH] Don't use fstat for readable pipe chars in dtexec.

The dtexec code assumes that fstat reports pipe's readable chars.
Linux always reports 0 for st_size of a pipe.
Instead read one character when select reports readable.
Note EOF when select says readable but read returns 0.
---
 cde/programs/dtexec/Main.c |   24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/cde/programs/dtexec/Main.c b/cde/programs/dtexec/Main.c
index 3624588..60c6d22 100644
--- a/cde/programs/dtexec/Main.c
+++ b/cde/programs/dtexec/Main.c
@@ -1163,7 +1163,6 @@ main (
     int    junki,i;
     char  *tmpBuffer;
     int    errorBytes;
-    struct stat statBuffer;
     int    firstPass, tmpi;
     char  *tmpProgName = NULL;
 
@@ -1390,28 +1389,31 @@ main (
 		    firstPass = 1;
 
 		    while (1) {
-			if ( fstat(errorpipeG[0], &statBuffer) ) {
-			    break;
+			char buf;
+			nfound =select(MAXSOCKS, FD_SET_CAST(&readfds), FD_SET_CAST(NULL),
+			     FD_SET_CAST(NULL), &timeoutShort);
+			if (nfound > 0) {
+			    tmpi = read (errorpipeG[0], &buf, 1);
+			} else {
+			    tmpi = 0;
 			}
-			else if ( statBuffer.st_size > 0 ) {
+
+			if ( tmpi > 0 ) {
 			    /*
 			     * Grow buffer to hold entire error stream.
 			     */
 			    firstPass = 0;
 			    if (tmpBuffer == NULL)
 				tmpBuffer = (char *) malloc(
-						statBuffer.st_size + 1);
+						tmpi + 1);
 			    else
 				tmpBuffer = (char *) realloc( tmpBuffer,
-						errorBytes +
-						statBuffer.st_size + 1);
+						errorBytes + tmpi + 1);
 			    /*
 			     * Drain error pipe.
 			     */
-			    tmpi = read (errorpipeG[0], &tmpBuffer[errorBytes],
-						statBuffer.st_size);
-			    if (tmpi > 0)			/* else let fstat() redetect problem */
-				errorBytes += tmpi;
+			    tmpBuffer[errorBytes] = buf;
+			    errorBytes += tmpi;
 			    tmpBuffer[errorBytes] = '\0';
 
 			    if (errorBytes < 65535) {
-- 
1.7.9.5

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
cdesktopenv-devel mailing list
cdesktopenv-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cdesktopenv-devel

Reply via email to