From d97454793c666e512819ce9475bc6f20596ee990 Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Thu, 28 Jun 2007 11:10:01 +0000 Subject: [PATCH] Delete orphan shared memory segments at BOINC startup svn path=/trunk/boinc/; revision=13047 --- client/file_names.C | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/client/file_names.C b/client/file_names.C index b8f0c03799..364cb07133 100644 --- a/client/file_names.C +++ b/client/file_names.C @@ -28,6 +28,10 @@ #include #include #include +#if HAVE_SYS_IPC_H +#include +#endif +#include "shmem.h" #endif #include "filesys.h" @@ -190,8 +194,23 @@ void delete_old_slot_dirs() { strcpy(filename, ""); retval = dir_scan(filename, dirp, sizeof(filename)); if (retval) break; - sprintf(path, "%s/%s", SLOTS_DIR, filename); + snprintf(path, sizeof(path), "%s/%s", SLOTS_DIR, filename); if (is_dir(path)) { +#ifndef _WIN32 + char init_data_path[1024]; + SHMEM_SEG_NAME shmem_seg_name; + + // If BOINC crashes or exits suddenly (e.g., due to + // being called with --exit_after_finish) it may leave + // orphan shared memory segments in the system. Clean + // these up here. (We must do this before deleting the + // INIT_DATA_FILE, if any, from each slot directory.) + snprintf(init_data_path, sizeof(init_data_path), "%s/%s", path, INIT_DATA_FILE); + shmem_seg_name = ftok(init_data_path, 1); + if (shmem_seg_name != -1) { + destroy_shmem(shmem_seg_name); + } +#endif if (!gstate.active_tasks.is_slot_dir_in_use(path)) { clean_out_dir(path); boinc_rmdir(path);