Delete orphan shared memory segments at BOINC startup

svn path=/trunk/boinc/; revision=13047
This commit is contained in:
Charlie Fenton 2007-06-28 11:10:01 +00:00
parent 390633ff7e
commit d97454793c
1 changed files with 20 additions and 1 deletions

View File

@ -28,6 +28,10 @@
#include <cstdio> #include <cstdio>
#include <sys/stat.h> #include <sys/stat.h>
#include <cctype> #include <cctype>
#if HAVE_SYS_IPC_H
#include <sys/ipc.h>
#endif
#include "shmem.h"
#endif #endif
#include "filesys.h" #include "filesys.h"
@ -190,8 +194,23 @@ void delete_old_slot_dirs() {
strcpy(filename, ""); strcpy(filename, "");
retval = dir_scan(filename, dirp, sizeof(filename)); retval = dir_scan(filename, dirp, sizeof(filename));
if (retval) break; if (retval) break;
sprintf(path, "%s/%s", SLOTS_DIR, filename); snprintf(path, sizeof(path), "%s/%s", SLOTS_DIR, filename);
if (is_dir(path)) { 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)) { if (!gstate.active_tasks.is_slot_dir_in_use(path)) {
clean_out_dir(path); clean_out_dir(path);
boinc_rmdir(path); boinc_rmdir(path);