From b2b3cdeff742bf1d7293cf44723ac3116b477d16 Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Wed, 26 Sep 2007 10:16:04 +0000 Subject: [PATCH] Mac/Linux/UNIX: V6 client uses shmget() to run V5 applications svn path=/trunk/boinc/; revision=13667 --- client/app.C | 41 +++++++++++++++++---------------- client/app_start.C | 56 +++++++++++++++++++++++++++------------------- 2 files changed, 55 insertions(+), 42 deletions(-) diff --git a/client/app.C b/client/app.C index fc0cbb4793..7d4ef099a2 100644 --- a/client/app.C +++ b/client/app.C @@ -180,28 +180,31 @@ void ACTIVE_TASK::cleanup_task() { } #else int retval; - + if (app_client_shm.shm) { -#ifdef USE_FILE_MAPPED_SHMEM - retval = detach_shmem(app_client_shm.shm, sizeof(SHARED_MEM)); -#else - retval = detach_shmem(app_client_shm.shm); - #endif - if (retval) { - msg_printf(NULL, MSG_INTERNAL_ERROR, - "Couldn't detach shared memory: %s", boincerror(retval) - ); +#ifndef __EMX__ + if (app_version->api_major_version() >= 6) { + retval = detach_shmem_mmap(app_client_shm.shm, sizeof(SHARED_MEM)); + } else +#endif + { + retval = detach_shmem(app_client_shm.shm); + 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) { exit(0); } diff --git a/client/app_start.C b/client/app_start.C index fc571bc834..d0fcab55c6 100644 --- a/client/app_start.C +++ b/client/app_start.C @@ -52,7 +52,7 @@ #include #endif -#ifdef USE_FILE_MAPPED_SHMEM +#if(!defined (_WIN32) && !defined (__EMX__)) #include #endif @@ -146,6 +146,13 @@ int ACTIVE_TASK::get_shmem_seg_name() { #else 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); // 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 // if (!app_client_shm.shm) { -#ifdef USE_FILE_MAPPED_SHMEM - sprintf(buf, "%s/%s", slot_dir, MMAPPED_FILE_NAME); - if (g_use_sandbox) { - if (!boinc_file_exists(buf)) { - int fd = open(buf, O_RDWR | O_CREAT, 0660); - if (fd >= 0) { - close (fd); - set_to_project_group(buf); + if (app_version->api_major_version() >= 6) { + // Use mmap() shared memory + sprintf(buf, "%s/%s", slot_dir, MMAPPED_FILE_NAME); + if (g_use_sandbox) { + if (!boinc_file_exists(buf)) { + int fd = open(buf, O_RDWR | O_CREAT, 0660); + if (fd >= 0) { + close (fd); + set_to_project_group(buf); + } } } - } - retval = create_shmem( - buf, sizeof(SHARED_MEM), (void**)&app_client_shm.shm - ); -#else // !defined(USE_FILE_MAPPED_SHMEM) - retval = create_shmem( - shmem_seg_name, sizeof(SHARED_MEM), gstate.boinc_project_gid, - (void**)&app_client_shm.shm - ); -#endif // !defined(USE_FILE_MAPPED_SHMEM) - if (retval) { - needs_shmem = true; - destroy_shmem(shmem_seg_name); // Don't leave an orphan shmem segment - return retval; + retval = create_shmem_mmap( + buf, sizeof(SHARED_MEM), (void**)&app_client_shm.shm + ); + } else { + // Use shmget() shared memory + retval = create_shmem( + shmem_seg_name, sizeof(SHARED_MEM), gstate.boinc_project_gid, + (void**)&app_client_shm.shm + ); + + if (retval) { + needs_shmem = true; + destroy_shmem(shmem_seg_name); // Don't leave an orphan shmem segment + return retval; + } } needs_shmem = false; }