2009-01-29 Zoltan Varga <vargaz@gmail.com>
authorZoltan Varga <vargaz@gmail.com>
Thu, 29 Jan 2009 15:26:33 +0000 (15:26 -0000)
committerZoltan Varga <vargaz@gmail.com>
Thu, 29 Jan 2009 15:26:33 +0000 (15:26 -0000)
* shared.c: Fall back to file based shared storage if shm_open () fails
because /dev/shm is not mounted.

svn path=/trunk/mono/; revision=124929

mono/io-layer/ChangeLog
mono/io-layer/shared.c

index d2f4beb0735f7fbec510342efb8ca73e594c2c69..298afded2638349918ce32af99d5fca01fe3a97d 100644 (file)
@@ -1,5 +1,8 @@
 2009-01-29  Zoltan Varga  <vargaz@gmail.com>
 
+       * shared.c: Fall back to file based shared storage if shm_open () fails
+       because /dev/shm is not mounted.
+       
        * shared.c: Add an alternative implementation using shared memory instead of
        files. This fixes problems where the mono process would spin up the disk
        every x secs on laptops. Fixes #434566, #415373 and #321949.
index 7b29b1f566008a7ebee132a0f9ff200541f58fec..21867ab02cee99ced56c61dc5810bf6929a302b9 100644 (file)
@@ -99,7 +99,7 @@ _wapi_shm_base_name (_wapi_shm_t type)
 
 #ifdef USE_SHM
 
-static gchar *_wapi_shm_file (_wapi_shm_t type)
+static gchar *_wapi_shm_shm_name (_wapi_shm_t type)
 {
        char *base_name = _wapi_shm_base_name (type);
 
@@ -113,10 +113,9 @@ _wapi_shm_open (const char *filename, int size)
        int fd;
 
        fd = shm_open (filename, O_CREAT|O_RDWR, S_IRUSR|S_IWUSR|S_IRGRP);
-       if (fd == -1) {
-               perror ("_wapi_shm_open (): shm_open ()");
-               g_assert_not_reached ();
-       }
+       if (fd == -1)
+               /* Maybe /dev/shm is not mounted */
+               return -1;
        if (ftruncate (fd, size) != 0) {
                perror ("_wapi_shm_open (): ftruncate ()");
                g_assert_not_reached ();
@@ -125,7 +124,7 @@ _wapi_shm_open (const char *filename, int size)
        return fd;
 }
 
-#else
+#endif
 
 static gchar *_wapi_shm_file (_wapi_shm_t type)
 {
@@ -276,8 +275,6 @@ try_again:
        return(fd);
 }
 
-#endif /* USE_SHM */
-
 static gboolean check_disabled (void)
 {
        if (_wapi_shm_disabled || g_getenv ("MONO_DISABLE_SHM")) {
@@ -323,10 +320,14 @@ gpointer _wapi_shm_attach (_wapi_shm_t type)
        }
 
 #ifdef USE_SHM
-       fd = _wapi_shm_open (filename, size);
+       fd = _wapi_shm_open (_wapi_shm_shm_name (type), size);
 #else
-       fd = _wapi_shm_file_open (filename, size);
+       fd = -1;
 #endif
+
+       /* Fall back to files if POSIX shm fails (for example, because /dev/shm is not mounted */
+       if (fd == -1)
+               fd = _wapi_shm_file_open (filename, size);
        if (fd == -1) {
                g_critical ("%s: shared file [%s] open error", __func__,
                            filename);
@@ -551,12 +552,11 @@ static void shm_semaphores_remove (void)
 
                semctl (_wapi_sem_id, 0, IPC_RMID);
 #ifdef USE_SHM
-               shm_unlink (_wapi_shm_file (WAPI_SHM_DATA));
-               shm_unlink (_wapi_shm_file (WAPI_SHM_FILESHARE));
-#else
+               shm_unlink (_wapi_shm_shm_name (WAPI_SHM_DATA));
+               shm_unlink (_wapi_shm_shm_name (WAPI_SHM_FILESHARE));
+#endif
                unlink (_wapi_shm_file (WAPI_SHM_DATA));
                unlink (_wapi_shm_file (WAPI_SHM_FILESHARE));
-#endif
        } else {
                /* "else" clause, because there's no point unlocking
                 * the semaphore if we've just blown it away...