Author: dick
Date: 2005-07-05 08:17:46 -0400 (Tue, 05 Jul 2005)
New Revision: 46940

Modified:
   trunk/mono/mono/io-layer/ChangeLog
   trunk/mono/mono/io-layer/error.c
   trunk/mono/mono/io-layer/io.c
Log:

2005-07-05  Dick Porter  <[EMAIL PROTECTED]>

        * io.c: Make sure SIGPIPE is ignored when calling write(2).
        Prevents the runtime exiting when writing to a closed pipe,
        fixing bug 75468.



Modified: trunk/mono/mono/io-layer/ChangeLog
===================================================================
--- trunk/mono/mono/io-layer/ChangeLog  2005-07-05 12:05:00 UTC (rev 46939)
+++ trunk/mono/mono/io-layer/ChangeLog  2005-07-05 12:17:46 UTC (rev 46940)
@@ -1,3 +1,9 @@
+2005-07-05  Dick Porter  <[EMAIL PROTECTED]>
+
+       * io.c: Make sure SIGPIPE is ignored when calling write(2).
+       Prevents the runtime exiting when writing to a closed pipe,
+       fixing bug 75468.
+
 2005-06-30  Dick Porter  <[EMAIL PROTECTED]>
 
        * shared.c (_wapi_shm_semaphores_init): Add some helpful error

Modified: trunk/mono/mono/io-layer/error.c
===================================================================
--- trunk/mono/mono/io-layer/error.c    2005-07-05 12:05:00 UTC (rev 46939)
+++ trunk/mono/mono/io-layer/error.c    2005-07-05 12:17:46 UTC (rev 46940)
@@ -207,8 +207,12 @@
                ret = ERROR_IO_PENDING;         /* best match I could find */
                break;
                
+       case EPIPE:
+               ret = ERROR_WRITE_FAULT;
+               break;
+               
        default:
-               g_message ("Unknown errno: %s\n", strerror (err));
+               g_message ("Unknown errno: %s\n", g_strerror (err));
                ret = ERROR_GEN_FAILURE;
                break;
        }

Modified: trunk/mono/mono/io-layer/io.c
===================================================================
--- trunk/mono/mono/io-layer/io.c       2005-07-05 12:05:00 UTC (rev 46939)
+++ trunk/mono/mono/io-layer/io.c       2005-07-05 12:17:46 UTC (rev 46940)
@@ -193,6 +193,11 @@
         NULL, NULL, NULL, NULL, NULL, NULL},
 };
 
+#define NO_SIGPIPE(x) do {                     \
+               void (*old_sigpipe)(int) = signal (SIGPIPE, SIG_IGN);   \
+               x;                                                      \
+               signal (SIGPIPE, old_sigpipe);                          \
+       }  while (0)
 
 static mono_once_t io_ops_once=MONO_ONCE_INIT;
 
@@ -360,11 +365,13 @@
                return(FALSE);
        }
                
-       do {
-               ret = write (fd, buffer, numbytes);
-       } while (ret == -1 && errno == EINTR &&
-                !_wapi_thread_cur_apc_pending());
-
+       NO_SIGPIPE(
+               do {
+                       ret = write (fd, buffer, numbytes);
+               } while (ret == -1 && errno == EINTR &&
+                        !_wapi_thread_cur_apc_pending());
+               );
+       
        _wapi_unlock_file_region (fd, current_pos, numbytes);
 
        if (ret == -1) {
@@ -609,10 +616,12 @@
                 * every system we care about conforms, then we can
                 * drop this write.
                 */
-               do {
-                       ret=write(fd, "", 1);
-               } while (ret==-1 && errno==EINTR &&
-                        !_wapi_thread_cur_apc_pending());
+               NO_SIGPIPE(
+                       do {
+                               ret = write (fd, "", 1);
+                       } while (ret == -1 && errno == EINTR &&
+                                !_wapi_thread_cur_apc_pending());
+                       );
 
                if(ret==-1) {
 #ifdef DEBUG
@@ -1016,9 +1025,12 @@
                return(FALSE);
        }
        
-       do {
-               ret=write(fd, buffer, numbytes);
-       } while (ret==-1 && errno==EINTR && !_wapi_thread_cur_apc_pending());
+       NO_SIGPIPE(
+               do {
+                       ret = write(fd, buffer, numbytes);
+               } while (ret == -1 && errno == EINTR &&
+                        !_wapi_thread_cur_apc_pending());
+               );
 
        if (ret == -1) {
                if (errno == EINTR) {
@@ -1162,9 +1174,12 @@
                   handle);
 #endif
 
-       do {
-               ret=write(fd, buffer, numbytes);
-       } while (ret==-1 && errno==EINTR && !_wapi_thread_cur_apc_pending());
+       NO_SIGPIPE(
+               do {
+                       ret = write (fd, buffer, numbytes);
+               } while (ret == -1 && errno == EINTR &&
+                        !_wapi_thread_cur_apc_pending());
+               );
 
        if (ret == -1) {
                if (errno == EINTR) {

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to