Mac/Linux/UNIX: V6 client uses shmget() to run V5 applications

svn path=/trunk/boinc/; revision=13667
This commit is contained in:
Charlie Fenton 2007-09-26 10:16:04 +00:00
parent 774091d490
commit b2b3cdeff7
2 changed files with 55 additions and 42 deletions

View File

@ -180,28 +180,31 @@ void ACTIVE_TASK::cleanup_task() {
} }
#else #else
int retval; int retval;
if (app_client_shm.shm) { if (app_client_shm.shm) {
#ifdef USE_FILE_MAPPED_SHMEM #ifndef __EMX__
retval = detach_shmem(app_client_shm.shm, sizeof(SHARED_MEM)); if (app_version->api_major_version() >= 6) {
#else retval = detach_shmem_mmap(app_client_shm.shm, sizeof(SHARED_MEM));
retval = detach_shmem(app_client_shm.shm); } else
#endif #endif
if (retval) { {
msg_printf(NULL, MSG_INTERNAL_ERROR, retval = detach_shmem(app_client_shm.shm);
"Couldn't detach shared memory: %s", boincerror(retval) if (retval) {
); msg_printf(NULL, MSG_INTERNAL_ERROR,
"Couldn't detach shared memory: %s", boincerror(retval)
);
}
retval = destroy_shmem(shmem_seg_name);
if (retval) {
msg_printf(NULL, MSG_INTERNAL_ERROR,
"Couldn't destroy shared memory: %s", boincerror(retval)
);
}
app_client_shm.shm = NULL;
gstate.retry_shmem_time = 0;
} }
retval = destroy_shmem(shmem_seg_name);
if (retval) {
msg_printf(NULL, MSG_INTERNAL_ERROR,
"Couldn't destroy shared memory: %s", boincerror(retval)
);
}
app_client_shm.shm = NULL;
gstate.retry_shmem_time = 0;
} }
if (gstate.exit_after_finish) { if (gstate.exit_after_finish) {
exit(0); exit(0);
} }

View File

@ -52,7 +52,7 @@
#include <libkern/OSByteOrder.h> #include <libkern/OSByteOrder.h>
#endif #endif
#ifdef USE_FILE_MAPPED_SHMEM #if(!defined (_WIN32) && !defined (__EMX__))
#include <fcntl.h> #include <fcntl.h>
#endif #endif
@ -146,6 +146,13 @@ int ACTIVE_TASK::get_shmem_seg_name() {
#else #else
char init_data_path[256]; char init_data_path[256];
#ifndef __EMX__
// shmem_seg_name is not used with mmap() shared memory
if (app_version->api_major_version() >= 6) {
shmem_seg_name = -1;
return 0;
}
#endif
sprintf(init_data_path, "%s/%s", slot_dir, INIT_DATA_FILE); sprintf(init_data_path, "%s/%s", slot_dir, INIT_DATA_FILE);
// ftok() only works if there's a file at the given location // ftok() only works if there's a file at the given location
@ -578,30 +585,33 @@ int ACTIVE_TASK::start(bool first_time) {
// Set up core/app shared memory seg if needed // Set up core/app shared memory seg if needed
// //
if (!app_client_shm.shm) { if (!app_client_shm.shm) {
#ifdef USE_FILE_MAPPED_SHMEM if (app_version->api_major_version() >= 6) {
sprintf(buf, "%s/%s", slot_dir, MMAPPED_FILE_NAME); // Use mmap() shared memory
if (g_use_sandbox) { sprintf(buf, "%s/%s", slot_dir, MMAPPED_FILE_NAME);
if (!boinc_file_exists(buf)) { if (g_use_sandbox) {
int fd = open(buf, O_RDWR | O_CREAT, 0660); if (!boinc_file_exists(buf)) {
if (fd >= 0) { int fd = open(buf, O_RDWR | O_CREAT, 0660);
close (fd); if (fd >= 0) {
set_to_project_group(buf); close (fd);
set_to_project_group(buf);
}
} }
} }
} retval = create_shmem_mmap(
retval = create_shmem( buf, sizeof(SHARED_MEM), (void**)&app_client_shm.shm
buf, sizeof(SHARED_MEM), (void**)&app_client_shm.shm );
); } else {
#else // !defined(USE_FILE_MAPPED_SHMEM) // Use shmget() shared memory
retval = create_shmem( retval = create_shmem(
shmem_seg_name, sizeof(SHARED_MEM), gstate.boinc_project_gid, shmem_seg_name, sizeof(SHARED_MEM), gstate.boinc_project_gid,
(void**)&app_client_shm.shm (void**)&app_client_shm.shm
); );
#endif // !defined(USE_FILE_MAPPED_SHMEM)
if (retval) { if (retval) {
needs_shmem = true; needs_shmem = true;
destroy_shmem(shmem_seg_name); // Don't leave an orphan shmem segment destroy_shmem(shmem_seg_name); // Don't leave an orphan shmem segment
return retval; return retval;
}
} }
needs_shmem = false; needs_shmem = false;
} }