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
int fd;
gpointer new_mem;
guchar *filename=_wapi_shm_file (type, segment);
+ int ret;
if(old_len>=new_len) {
return(mem);
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);
int fd;
struct stat statbuf;
guint32 wanted_size = 0;
+ int ret;
if(created) {
*created=FALSE;
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);
}
if(statbuf.st_size < wanted_size) {
+ close (fd);
+ if(created && *created==TRUE) {
#ifdef HAVE_LARGE_FILE_SUPPORT
- /* Keep gcc quiet... */
- g_critical (G_GNUC_PRETTY_FUNCTION ": shared file [%s] is not big enough! (found %lld, need %d bytes)", filename, statbuf.st_size, wanted_size);
+ /* Keep gcc quiet... */
+ g_critical (G_GNUC_PRETTY_FUNCTION ": shared file [%s] is not big enough! (found %lld, need %d bytes)", filename, statbuf.st_size, wanted_size);
#else
- g_critical (G_GNUC_PRETTY_FUNCTION ": shared file [%s] is not big enough! (found %ld, need %d bytes)", filename, statbuf.st_size, wanted_size);
+ g_critical (G_GNUC_PRETTY_FUNCTION ": shared file [%s] is not big enough! (found %ld, need %d bytes)", filename, statbuf.st_size, wanted_size);
#endif
- if(created && *created==TRUE) {
unlink (filename);
+ return(-1);
+ } else {
+ /* We didn't create it, so just try opening it again */
+ goto try_again;
}
- close (fd);
- return(-1);
}
return(fd);
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);
}
g_message (G_GNUC_PRETTY_FUNCTION ": Daemon pid %d", pid);
#endif
#endif /* !VALGRINDING */
- } else {
- /* Do some sanity checking on the shared memory we
- * attached
- */
- if(!((*data)->daemon_running==DAEMON_STARTING ||
- (*data)->daemon_running==DAEMON_RUNNING ||
- (*data)->daemon_running==DAEMON_DIED_AT_STARTUP) ||
-#ifdef NEED_LINK_UNLINK
- (strncmp ((*data)->daemon, "/tmp/mono-handle-daemon-",
- 24)!=0)) {
-#else
- (strncmp ((*data)->daemon+1, "mono-handle-daemon-", 19)!=0)) {
-#endif
- g_warning ("Shared memory sanity check failed.");
- return(FALSE);
- }
}
for(tries=0; (*data)->daemon_running==DAEMON_STARTING && tries < 100;
}
if(tries==100 && (*data)->daemon_running==DAEMON_STARTING) {
/* Daemon didnt get going */
- if(data_created==TRUE) {
- _wapi_shm_destroy ();
+ struct timespec sleepytime;
+
+ /* 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.
+ */
+
+ munmap (*data, data_size);
+ munmap (*scratch, scratch_size);
+
+ if(closing_tries++ == 5) {
+ /* Still can't get going, so bail out */
+ g_warning ("The handle daemon didnt start up properly");
+ return(FALSE);
}
- g_warning ("The handle daemon didnt start up properly");
- return(FALSE);
+
+ sleepytime.tv_sec=0;
+ sleepytime.tv_nsec=10000000; /* 10ms */
+
+ nanosleep (&sleepytime, NULL);
+ goto map_again;
}
if((*data)->daemon_running==DAEMON_DIED_AT_STARTUP) {
g_warning ("Handle daemon failed to start");
return(FALSE);
}
+
+ /* Do some sanity checking on the shared memory we
+ * attached
+ */
+ if(((*data)->daemon_running!=DAEMON_RUNNING) ||
+#ifdef NEED_LINK_UNLINK
+ (strncmp ((*data)->daemon, "/tmp/mono-handle-daemon-",
+ 24)!=0)) {
+#else
+ (strncmp ((*data)->daemon+1, "mono-handle-daemon-", 19)!=0)) {
+#endif
+ g_warning ("Shared memory sanity check failed.");
+ g_warning("status: %d", (*data)->daemon_running);
+#ifdef NEED_LINK_UNLINK
+ g_warning("daemon: [%s]", (*data)->daemon);
+#else
+ g_warning("daemon: [%s]", (*data)->daemon+1);
+#endif
+ return(FALSE);
+ }
/* From now on, it's up to the daemon to delete the shared
* memory segment