* Makefile (MCS) [PROFILE=default]: Force testing of 'mcs'.
[mono.git] / mono / io-layer / shared.c
index 3391d39719c262215b1d985f36a66e56432dce2d..b0e828a222107e17c6c5f2dbb2ccf9ed4dc79d7b 100644 (file)
@@ -103,6 +103,7 @@ guchar *_wapi_shm_file (_wapi_shm_t type, guint32 segment)
        g_free (name);
 
        g_snprintf (file, _POSIX_PATH_MAX, "%s", filename);
+       g_free (filename);
                
        /* No need to check if the dir already exists or check
         * mkdir() errors, because on any error the open() call will
@@ -122,6 +123,7 @@ gpointer _wapi_shm_file_expand (gpointer mem, _wapi_shm_t type,
        int fd;
        gpointer new_mem;
        guchar *filename=_wapi_shm_file (type, segment);
+       int ret;
 
        if(old_len>=new_len) {
                return(mem);
@@ -144,12 +146,18 @@ gpointer _wapi_shm_file_expand (gpointer mem, _wapi_shm_t type,
                return(NULL);
        }
        
-       if(write (fd, "", 1)==-1) {
+       do {
+               ret=write (fd, "", 1);
+       }
+       while (ret==-1 && errno==EINTR);
+
+       if(ret==-1) {
                g_critical (G_GNUC_PRETTY_FUNCTION
                            ": shared file [%s] write error: %s", filename,
                            g_strerror (errno));
                return(NULL);
        }
+
        close (fd);
        
        new_mem=_wapi_shm_file_map (type, segment, NULL, NULL);
@@ -163,6 +171,7 @@ static int _wapi_shm_file_open (const guchar *filename, _wapi_shm_t type,
        int fd;
        struct stat statbuf;
        guint32 wanted_size = 0;
+       int ret;
        
        if(created) {
                *created=FALSE;
@@ -215,7 +224,12 @@ try_again:
                                return(-1);
                        }
                        
-                       if(write (fd, "", 1)==-1) {
+                       do {
+                               ret=write (fd, "", 1);
+                       }
+                       while (ret==-1 && errno==EINTR);
+                               
+                       if(ret==-1) {
                                g_critical (G_GNUC_PRETTY_FUNCTION ": shared file [%s] write error: %s", filename, g_strerror (errno));
                                close (fd);
                                unlink (filename);
@@ -357,14 +371,16 @@ map_again:
                
                struct timespec sleepytime;
                        
+               /* Something must have gone wrong, so delete the
+                * shared segments and try again.
+                */
+               _wapi_shm_destroy ();
+               
                munmap (*data, data_size);
                munmap (*scratch, scratch_size);
                
                if(closing_tries++ == 5) {
-                       /* Something must have gone wrong, so bail
-                        * out.  This will let the calling code delete
-                        * the shared segments and try again.
-                        */
+                       /* Still can't get going, so bail out */
                        g_warning ("The handle daemon is stuck closing");
                        return(FALSE);
                }
@@ -441,9 +457,10 @@ map_again:
                /* Daemon didnt get going */
                struct timespec sleepytime;
                        
-               if(data_created==TRUE) {
-                       _wapi_shm_destroy ();
-               }
+               /* Something must have gone wrong, so delete the
+                * shared segments and try again.
+                */
+               _wapi_shm_destroy ();
 
                /* Daemon didn't get going, give it a few ms and try
                 * again.
@@ -453,10 +470,7 @@ map_again:
                munmap (*scratch, scratch_size);
                
                if(closing_tries++ == 5) {
-                       /* Something must have gone wrong, so bail
-                        * out.  This will let the calling code delete
-                        * the shared segments and try again.
-                        */
+                       /* Still can't get going, so bail out */
                        g_warning ("The handle daemon didnt start up properly");
                        return(FALSE);
                }