/* * This utility will do a brute force clean of a node. It will * attempt to clean up any files in the user's session directory. * It will also look for any orted and orterun processes that are * not part of this job, and kill them off. */ int main(int argc, char *argv[]) { int ret = ORTE_SUCCESS; #if OPAL_ENABLE_FT_CR == 1 char *tmp_env_var; #endif /* This is needed so we can print the help message */ if (ORTE_SUCCESS != (ret = opal_init_util(&argc, &argv))) { return ret; } if (ORTE_SUCCESS != (ret = parse_args(argc, argv))) { return ret; } #if OPAL_ENABLE_FT_CR == 1 /* Disable the checkpoint notification routine for this * tool. As we will never need to checkpoint this tool. * Note: This must happen before opal_init(). */ opal_cr_set_enabled(false); /* Select the none component, since we don't actually use a checkpointer */ (void) mca_base_var_env_name("crs", &tmp_env_var); opal_setenv(tmp_env_var, "none", true, &environ); free(tmp_env_var); tmp_env_var = NULL; (void) mca_base_var_env_name("opal_cr_is_tool", &tmp_env_var); opal_setenv(tmp_env_var, "1", true, NULL); free(tmp_env_var); #endif if (ORTE_SUCCESS != (ret = orte_init(&argc, &argv, ORTE_PROC_TOOL))) { return ret; } /* * Clean out all session directories - we don't have to protect * our own session directory because (since we are a tool) we * didn't create one! */ if (orte_clean_globals.verbose) { fprintf(stderr, "orte-clean: cleaning session dir tree %s\n", orte_process_info.top_session_dir); } opal_os_dirpath_destroy(orte_process_info.top_session_dir, true, NULL); /* now kill any lingering procs, if we can */ kill_procs(); orte_finalize(); return ORTE_SUCCESS; }
int opal_crs_base_cleanup_flush(void) { int argc, i; /* * Cleanup files first */ if( NULL != cleanup_file_argv ) { argc = opal_argv_count(cleanup_file_argv); for( i = 0; i < argc; ++i) { opal_output_verbose(15, opal_crs_base_framework.framework_output, "opal:crs: cleanup_flush: Remove File <%s>\n", cleanup_file_argv[i]); unlink(cleanup_file_argv[i]); } opal_argv_free(cleanup_file_argv); cleanup_file_argv = NULL; } /* * Try to cleanup directories next */ if( NULL != cleanup_dir_argv ) { argc = opal_argv_count(cleanup_dir_argv); for( i = 0; i < argc; ++i) { opal_output_verbose(15, opal_crs_base_framework.framework_output, "opal:crs: cleanup_flush: Remove Dir <%s>\n", cleanup_dir_argv[i]); opal_os_dirpath_destroy(cleanup_dir_argv[i], true, NULL); } opal_argv_free(cleanup_dir_argv); cleanup_dir_argv = NULL; } return OPAL_SUCCESS; }
/* * This utility will do a brute force clean of a node. It will * attempt to clean up any files in the user's session directory. * It will also look for any orted and orterun processes that are * not part of this job, and kill them off. */ int main(int argc, char *argv[]) { int ret = ORTE_SUCCESS; /* This is needed so we can print the help message */ if (ORTE_SUCCESS != (ret = opal_init_util(&argc, &argv))) { return ret; } if (ORTE_SUCCESS != (ret = parse_args(argc, argv))) { return ret; } if (ORTE_SUCCESS != (ret = orte_init(&argc, &argv, ORTE_PROC_TOOL))) { return ret; } /* * Clean out all session directories - we don't have to protect * our own session directory because (since we are a tool) we * didn't create one! */ if (orte_clean_globals.verbose) { fprintf(stderr, "orte-clean: cleaning session dir tree %s\n", orte_process_info.top_session_dir); } opal_os_dirpath_destroy(orte_process_info.top_session_dir, true, NULL); /* now kill any lingering procs, if we can */ kill_procs(); orte_finalize(); return ORTE_SUCCESS; }
/** * This function attempts to remove a directory along with all the * files in it. If the recursive variable is non-zero, then it will * try to recursively remove all directories. If provided, the * callback function is executed prior to the directory or file being * removed. If the callback returns non-zero, then no removal is * done. */ int opal_os_dirpath_destroy(const char *path, bool recursive, opal_os_dirpath_destroy_callback_fn_t cbfunc) { int rc, exit_status = OPAL_SUCCESS; bool is_dir = false; DIR *dp; struct dirent *ep; char *filenm; #ifndef HAVE_STRUCT_DIRENT_D_TYPE struct stat buf; #endif if (NULL == path) { /* protect against error */ return OPAL_ERROR; } /* * Make sure we have access to the the base directory */ if( OPAL_SUCCESS != (rc = opal_os_dirpath_access(path, 0) ) ) { exit_status = rc; goto cleanup; } /* Open up the directory */ dp = opendir(path); if (NULL == dp) { return OPAL_ERROR; } while (NULL != (ep = readdir(dp)) ) { /* skip: * - . and .. */ if ((0 == strcmp(ep->d_name, ".")) || (0 == strcmp(ep->d_name, "..")) ) { continue; } /* Check to see if it is a directory */ is_dir = false; /* Create a pathname. This is not always needed, but it makes * for cleaner code just to create it here. Note that we are * allocating memory here, so we need to free it later on. */ filenm = opal_os_path(false, path, ep->d_name, NULL); #ifdef HAVE_STRUCT_DIRENT_D_TYPE if (DT_DIR == ep->d_type) { is_dir = true; } #else /* have dirent.d_type */ rc = stat(filenm, &buf); if (rc < 0 || S_ISDIR(buf.st_mode)) { is_dir = true; } #endif /* have dirent.d_type */ /* * If not recursively decending, then if we find a directory then fail * since we were not told to remove it. */ if( is_dir && !recursive) { /* Set the error indicating that we found a directory, * but continue removing files */ exit_status = OPAL_ERROR; free(filenm); continue; } /* Will the caller allow us to remove this file/directory? */ if(NULL != cbfunc) { /* * Caller does not wish to remove this file/directory, * continue with the rest of the entries */ if( ! (cbfunc(path, ep->d_name)) ) { free(filenm); continue; } } /* Directories are recursively destroyed */ if(is_dir) { rc = opal_os_dirpath_destroy(filenm, recursive, cbfunc); free(filenm); if (OPAL_SUCCESS != rc) { exit_status = rc; closedir(dp); goto cleanup; } } /* Files are removed right here */ else { if( 0 != (rc = unlink(filenm) ) ) { exit_status = OPAL_ERROR; } free(filenm); } } /* Done with this directory */ closedir(dp); cleanup: /* * If the directory is empty, them remove it */ if(opal_os_dirpath_is_empty(path)) { rmdir(path); } return exit_status; }
/** * This function attempts to remove a directory along with all the * files in it. If the recursive variable is non-zero, then it will * try to recursively remove all directories. If provided, the * callback function is executed prior to the directory or file being * removed. If the callback returns non-zero, then no removal is * done. */ int opal_os_dirpath_destroy(const char *path, bool recursive, opal_os_dirpath_destroy_callback_fn_t cbfunc) { int rc, exit_status = OPAL_SUCCESS; bool is_dir = false; if (NULL == path) { /* protect against error */ return OPAL_ERROR; } /* * Make sure we have access to the the base directory */ if( OPAL_SUCCESS != (rc = opal_os_dirpath_access(path, 0) ) ) { exit_status = rc; goto cleanup; } #ifndef __WINDOWS__ { DIR *dp; struct dirent *ep; char *filenm; #ifndef HAVE_STRUCT_DIRENT_D_TYPE struct stat buf; #endif /* Open up the directory */ dp = opendir(path); if (NULL == dp) { return OPAL_ERROR; } while (NULL != (ep = readdir(dp)) ) { /* skip: * - . and .. */ if ((0 == strcmp(ep->d_name, ".")) || (0 == strcmp(ep->d_name, "..")) ) { continue; } /* Check to see if it is a directory */ is_dir = false; /* Create a pathname. This is not always needed, but it makes * for cleaner code just to create it here. Note that we are * allocating memory here, so we need to free it later on. */ filenm = opal_os_path(false, path, ep->d_name, NULL); #ifdef HAVE_STRUCT_DIRENT_D_TYPE if (DT_DIR == ep->d_type) { is_dir = true; } #else /* have dirent.d_type */ rc = stat(filenm, &buf); if (rc < 0 || S_ISDIR(buf.st_mode)) { is_dir = true; } #endif /* have dirent.d_type */ /* * If not recursively decending, then if we find a directory then fail * since we were not told to remove it. */ if( is_dir && !recursive) { /* Set the error indicating that we found a directory, * but continue removing files */ exit_status = OPAL_ERROR; free(filenm); continue; } /* Will the caller allow us to remove this file/directory? */ if(NULL != cbfunc) { /* * Caller does not wish to remove this file/directory, * continue with the rest of the entries */ if( ! (cbfunc(path, ep->d_name)) ) { free(filenm); continue; } } /* Directories are recursively destroyed */ if(is_dir) { rc = opal_os_dirpath_destroy(filenm, recursive, cbfunc); free(filenm); if (OPAL_SUCCESS != rc) { exit_status = rc; closedir(dp); goto cleanup; } } /* Files are removed right here */ else { if( 0 != (rc = unlink(filenm) ) ) { exit_status = OPAL_ERROR; } free(filenm); } } /* Done with this directory */ closedir(dp); } #else { char search_path[MAX_PATH]; HANDLE file; WIN32_FIND_DATA file_data; TCHAR *file_name; strncpy(search_path, path, strlen(path)+1); strncat (search_path, OPAL_PATH_SEP"*", 3); file = FindFirstFile(search_path, &file_data); if (INVALID_HANDLE_VALUE == file) { FindClose(file); return OPAL_ERROR; } do { /* Skip . and .. */ if ((0 == strcmp(file_data.cFileName, ".")) || (0 == strcmp(file_data.cFileName, "..")) ) { continue; } is_dir = false; if(file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { is_dir = true; } /* * If not recursively decending, then if we find a directory then fail * since we were not told to remove it. */ if( is_dir && !recursive) { /* Set the error indicating that we found a directory, * but continue removing files */ exit_status = OPAL_ERROR; continue; } /* Will the caller allow us to remove this file/directory */ if( NULL != cbfunc) { /* * Caller does not wish to remove this file/directory, * continue with the rest of the entries */ if( !cbfunc(path, file_data.cFileName) ) { continue; } } file_name = opal_os_path(false, path, file_data.cFileName, NULL); if( is_dir ) { if( OPAL_SUCCESS != (rc = opal_os_dirpath_destroy(file_name, recursive, cbfunc) ) ) { exit_status = rc; free(file_name); FindClose(file); goto cleanup; } } else { DeleteFile(file_name); } free(file_name); } while( 0 != FindNextFile(file, &file_data) ); FindClose(file); } #endif cleanup: /* * If the directory is empty, them remove it */ if(opal_os_dirpath_is_empty(path)) { rmdir(path); } return exit_status; }
int orte_session_dir_finalize(orte_process_name_t *proc) { int rc; char *tmp; char *job_session_dir, *vpid, *proc_session_dir; if (!orte_create_session_dirs) { /* didn't create them */ return ORTE_SUCCESS; } /* need to setup the top_session_dir with the prefix */ tmp = opal_os_path(false, orte_process_info.tmpdir_base, orte_process_info.top_session_dir, NULL); /* define the proc and job session directories for this process */ if (ORTE_SUCCESS != (rc = orte_util_convert_vpid_to_string(&vpid, proc->vpid))) { ORTE_ERROR_LOG(rc); free(tmp); return rc; } job_session_dir = orte_build_job_session_dir(tmp, proc, proc->jobid); if( NULL == job_session_dir) { free(tmp); free(vpid); return ORTE_ERR_OUT_OF_RESOURCE; } proc_session_dir = opal_os_path( false, job_session_dir, vpid, NULL ); if( NULL == proc_session_dir ) { ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE); free(tmp); free(vpid); free(job_session_dir); return ORTE_ERR_OUT_OF_RESOURCE; } opal_os_dirpath_destroy(proc_session_dir, false, orte_dir_check_file); opal_os_dirpath_destroy(job_session_dir, false, orte_dir_check_file); opal_os_dirpath_destroy(tmp, false, orte_dir_check_file); if (opal_os_dirpath_is_empty(proc_session_dir)) { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: found proc session dir empty - deleting"); } rmdir(proc_session_dir); } else { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: proc session dir not empty - leaving"); } goto CLEANUP; } if (opal_os_dirpath_is_empty(job_session_dir)) { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: found job session dir empty - deleting"); } rmdir(job_session_dir); } else { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: job session dir not empty - leaving"); } goto CLEANUP; } if (opal_os_dirpath_is_empty(tmp)) { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: found top session dir empty - deleting"); } rmdir(tmp); } else { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: top session dir not empty - leaving"); } } CLEANUP: free(tmp); free(vpid); free(job_session_dir); free(proc_session_dir); return ORTE_SUCCESS; }
/* * A job has aborted - so force cleanup of the session directory */ int orte_session_dir_cleanup(orte_jobid_t jobid) { int rc = ORTE_SUCCESS; char *tmp; char *job_session_dir=NULL; if (!orte_create_session_dirs) { /* didn't create them */ return ORTE_SUCCESS; } /* need to setup the top_session_dir with the prefix */ tmp = opal_os_path(false, orte_process_info.tmpdir_base, orte_process_info.top_session_dir, NULL); /* we can only blow away session directories for our job family */ job_session_dir = orte_build_job_session_dir(tmp, ORTE_PROC_MY_NAME, jobid); if (NULL == job_session_dir) { rc = ORTE_ERR_OUT_OF_RESOURCE; goto CLEANUP; } if (ORTE_JOBID_WILDCARD != jobid) { opal_os_dirpath_destroy(job_session_dir, true, orte_dir_check_file); } else { /* if we want the session_dir removed for ALL jobids, then * just recursively blow the whole session away for our job family, * saving only output files */ opal_os_dirpath_destroy(job_session_dir, true, orte_dir_check_file_output); } /* now attempt to eliminate the top level directory itself - this * will fail if anything is present, but ensures we cleanup if * we are the last one out */ opal_os_dirpath_destroy(tmp, false, orte_dir_check_file); if (NULL != job_session_dir && opal_os_dirpath_is_empty(job_session_dir)) { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: found job session dir empty - deleting"); } rmdir(job_session_dir); } else { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: job session dir not empty - leaving"); } goto CLEANUP; } if (opal_os_dirpath_is_empty(tmp)) { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: found top session dir empty - deleting"); } rmdir(tmp); } else { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: top session dir not empty - leaving"); } } CLEANUP: free(tmp); if (NULL != job_session_dir) free(job_session_dir); return rc; }
int orte_session_dir_finalize(orte_process_name_t *proc) { int rc=ORTE_SUCCESS; if (!orte_create_session_dirs || orte_process_info.rm_session_dirs ) { /* we haven't created them or RM will clean them up for us*/ return ORTE_SUCCESS; } if (NULL == orte_process_info.job_session_dir || NULL == orte_process_info.proc_session_dir) { /* this should never happen - it means we are calling * cleanup *before* properly setting up the session * dir system. This leaves open the possibility of * accidentally removing directories we shouldn't * touch */ rc = ORTE_ERR_NOT_INITIALIZED; goto CLEANUP; } opal_os_dirpath_destroy(orte_process_info.proc_session_dir, false, orte_dir_check_file); opal_os_dirpath_destroy(orte_process_info.job_session_dir, false, orte_dir_check_file); if( NULL != orte_process_info.top_session_dir ){ opal_os_dirpath_destroy(orte_process_info.top_session_dir, false, orte_dir_check_file); } if (opal_os_dirpath_is_empty(orte_process_info.proc_session_dir)) { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: found proc session dir empty - deleting"); } rmdir(orte_process_info.proc_session_dir); } else { if (orte_debug_flag) { if (OPAL_ERR_NOT_FOUND == opal_os_dirpath_access(orte_process_info.proc_session_dir, 0)) { opal_output(0, "sess_dir_finalize: proc session dir does not exist"); } else { opal_output(0, "sess_dir_finalize: proc session dir not empty - leaving"); } } goto CLEANUP; } if (opal_os_dirpath_is_empty(orte_process_info.job_session_dir)) { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: found job session dir empty - deleting"); } rmdir(orte_process_info.job_session_dir); } else { if (orte_debug_flag) { if (OPAL_ERR_NOT_FOUND == opal_os_dirpath_access(orte_process_info.job_session_dir, 0)) { opal_output(0, "sess_dir_finalize: job session dir does not exist"); } else { opal_output(0, "sess_dir_finalize: job session dir not empty - leaving"); } } goto CLEANUP; } if(NULL != orte_process_info.top_session_dir) { if (opal_os_dirpath_is_empty(orte_process_info.top_session_dir)) { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: found top session dir empty - deleting"); } rmdir(orte_process_info.top_session_dir); } else { if (orte_debug_flag) { if (OPAL_ERR_NOT_FOUND == opal_os_dirpath_access(orte_process_info.top_session_dir, 0)) { opal_output(0, "sess_dir_finalize: top session dir does not exist"); } else { opal_output(0, "sess_dir_finalize: top session dir not empty - leaving"); } } } } CLEANUP: return rc; }
/* * A job has aborted - so force cleanup of the session directory */ int orte_session_dir_cleanup(orte_jobid_t jobid) { int rc = ORTE_SUCCESS; if (!orte_create_session_dirs || orte_process_info.rm_session_dirs ) { /* we haven't created them or RM will clean them up for us*/ return ORTE_SUCCESS; } if (NULL == orte_process_info.job_session_dir || NULL == orte_process_info.proc_session_dir) { /* this should never happen - it means we are calling * cleanup *before* properly setting up the session * dir system. This leaves open the possibility of * accidentally removing directories we shouldn't * touch */ rc = ORTE_ERR_NOT_INITIALIZED; goto CLEANUP; } /* recursively blow the whole session away for our job family, * saving only output files */ opal_os_dirpath_destroy(orte_process_info.job_session_dir, true, orte_dir_check_file); /* now attempt to eliminate the top level directory itself - this * will fail if anything is present, but ensures we cleanup if * we are the last one out */ if( NULL != orte_process_info.top_session_dir ){ opal_os_dirpath_destroy(orte_process_info.top_session_dir, false, orte_dir_check_file); } if (opal_os_dirpath_is_empty(orte_process_info.job_session_dir)) { if (orte_debug_flag) { opal_output(0, "sess_dir_cleanup: found job session dir empty - deleting"); } rmdir(orte_process_info.job_session_dir); } else { if (orte_debug_flag) { if (OPAL_ERR_NOT_FOUND == opal_os_dirpath_access(orte_process_info.job_session_dir, 0)) { opal_output(0, "sess_dir_cleanup: job session dir does not exist"); } else { opal_output(0, "sess_dir_cleanup: job session dir not empty - leaving"); } } goto CLEANUP; } if ( NULL != orte_process_info.top_session_dir ){ if( opal_os_dirpath_is_empty(orte_process_info.top_session_dir) ) { if (orte_debug_flag) { opal_output(0, "sess_dir_cleanup: found top session dir empty - deleting"); } rmdir(orte_process_info.top_session_dir); } else { if (orte_debug_flag) { if (OPAL_ERR_NOT_FOUND == opal_os_dirpath_access(orte_process_info.top_session_dir, 0)) { opal_output(0, "sess_dir_cleanup: top session dir does not exist"); } else { opal_output(0, "sess_dir_cleanup: top session dir not empty - leaving"); } } } } CLEANUP: return rc; }
int orte_session_dir_finalize(orte_process_name_t *proc) { if (!orte_create_session_dirs || orte_process_info.rm_session_dirs ) { /* we haven't created them or RM will clean them up for us*/ return ORTE_SUCCESS; } if (NULL == orte_process_info.job_session_dir || NULL == orte_process_info.proc_session_dir) { /* this should never happen - it means we are calling * cleanup *before* properly setting up the session * dir system. This leaves open the possibility of * accidentally removing directories we shouldn't * touch */ return ORTE_ERR_NOT_INITIALIZED; } opal_os_dirpath_destroy(orte_process_info.proc_session_dir, false, orte_dir_check_file); opal_os_dirpath_destroy(orte_process_info.job_session_dir, false, orte_dir_check_file); /* only remove the jobfam session dir if we are the * local daemon and we are finalizing our own session dir */ if ((ORTE_PROC_IS_HNP || ORTE_PROC_IS_DAEMON) && (ORTE_PROC_MY_NAME == proc)) { opal_os_dirpath_destroy(orte_process_info.jobfam_session_dir, false, orte_dir_check_file); } if( NULL != orte_process_info.top_session_dir ){ opal_os_dirpath_destroy(orte_process_info.top_session_dir, false, orte_dir_check_file); } if (opal_os_dirpath_is_empty(orte_process_info.proc_session_dir)) { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: found proc session dir empty - deleting"); } rmdir(orte_process_info.proc_session_dir); } else { if (orte_debug_flag) { if (OPAL_ERR_NOT_FOUND == opal_os_dirpath_access(orte_process_info.proc_session_dir, 0)) { opal_output(0, "sess_dir_finalize: proc session dir does not exist"); } else { opal_output(0, "sess_dir_finalize: proc session dir not empty - leaving"); } } } if (opal_os_dirpath_is_empty(orte_process_info.job_session_dir)) { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: found job session dir empty - deleting"); } rmdir(orte_process_info.job_session_dir); } else { if (orte_debug_flag) { if (OPAL_ERR_NOT_FOUND == opal_os_dirpath_access(orte_process_info.job_session_dir, 0)) { opal_output(0, "sess_dir_finalize: job session dir does not exist"); } else { opal_output(0, "sess_dir_finalize: job session dir not empty - leaving"); } } } if (opal_os_dirpath_is_empty(orte_process_info.jobfam_session_dir)) { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: found jobfam session dir empty - deleting"); } rmdir(orte_process_info.jobfam_session_dir); } else { if (orte_debug_flag) { if (OPAL_ERR_NOT_FOUND == opal_os_dirpath_access(orte_process_info.jobfam_session_dir, 0)) { opal_output(0, "sess_dir_finalize: jobfam session dir does not exist"); } else { opal_output(0, "sess_dir_finalize: jobfam session dir not empty - leaving"); } } } if(NULL != orte_process_info.top_session_dir) { if (opal_os_dirpath_is_empty(orte_process_info.top_session_dir)) { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: found top session dir empty - deleting"); } rmdir(orte_process_info.top_session_dir); } else { if (orte_debug_flag) { if (OPAL_ERR_NOT_FOUND == opal_os_dirpath_access(orte_process_info.top_session_dir, 0)) { opal_output(0, "sess_dir_finalize: top session dir does not exist"); } else { opal_output(0, "sess_dir_finalize: top session dir not empty - leaving"); } } } } return ORTE_SUCCESS; }
/* * A job has aborted - so force cleanup of the session directory */ int orte_session_dir_cleanup(orte_jobid_t jobid) { int rc; char *tmp; char *job, *job_session_dir; /* need to setup the top_session_dir with the prefix */ tmp = opal_os_path(false, orte_process_info.tmpdir_base, orte_process_info.top_session_dir, NULL); /* define the proc and job session directories for this process */ if (ORTE_SUCCESS != (rc = orte_ns.convert_jobid_to_string(&job, jobid))) { ORTE_ERROR_LOG(rc); free(tmp); return rc; } job_session_dir = opal_os_path( false, orte_process_info.universe_session_dir, job, NULL ); if( NULL == job_session_dir ) { ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE); free(tmp); free(job); return ORTE_ERR_OUT_OF_RESOURCE; } opal_os_dirpath_destroy(job_session_dir, true, orte_dir_check_file); opal_os_dirpath_destroy(orte_process_info.universe_session_dir, false, orte_dir_check_file); opal_os_dirpath_destroy(tmp, false, orte_dir_check_file); if (opal_os_dirpath_is_empty(job_session_dir)) { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: found job session dir empty - deleting"); } rmdir(job_session_dir); } else { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: job session dir not empty - leaving"); } goto CLEANUP; } if (opal_os_dirpath_is_empty(orte_process_info.universe_session_dir)) { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: found univ session dir empty - deleting"); } rmdir(orte_process_info.universe_session_dir); } else { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: univ session dir not empty - leaving"); } goto CLEANUP; } if (opal_os_dirpath_is_empty(tmp)) { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: found top session dir empty - deleting"); } rmdir(tmp); } else { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: top session dir not empty - leaving"); } } CLEANUP: free(tmp); free(job); free(job_session_dir); return ORTE_SUCCESS; }
int orte_session_dir_finalize(orte_process_name_t *proc) { int rc; char *tmp; char *job_session_dir, *vpid, *proc_session_dir; if (!orte_create_session_dirs) { /* didn't create them */ return ORTE_SUCCESS; } if (NULL == orte_process_info.tmpdir_base && NULL == orte_process_info.top_session_dir) { /* this should never happen - it means we are calling * cleanup *before* properly setting up the session * dir system. This leaves open the possibility of * accidentally removing directories we shouldn't * touch */ ORTE_ERROR_LOG(ORTE_ERR_NOT_INITIALIZED); return ORTE_ERR_NOT_INITIALIZED; } /* need to setup the top_session_dir with the prefix */ tmp = opal_os_path(false, orte_process_info.tmpdir_base, orte_process_info.top_session_dir, NULL); /* define the proc and job session directories for this process */ if (ORTE_SUCCESS != (rc = orte_util_convert_vpid_to_string(&vpid, proc->vpid))) { ORTE_ERROR_LOG(rc); free(tmp); return rc; } job_session_dir = orte_build_job_session_dir(tmp, proc, proc->jobid); if( NULL == job_session_dir) { free(tmp); free(vpid); return ORTE_ERR_OUT_OF_RESOURCE; } proc_session_dir = opal_os_path( false, job_session_dir, vpid, NULL ); if( NULL == proc_session_dir ) { ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE); free(tmp); free(vpid); free(job_session_dir); return ORTE_ERR_OUT_OF_RESOURCE; } opal_os_dirpath_destroy(proc_session_dir, false, orte_dir_check_file); opal_os_dirpath_destroy(job_session_dir, false, orte_dir_check_file); opal_os_dirpath_destroy(tmp, false, orte_dir_check_file); if (opal_os_dirpath_is_empty(proc_session_dir)) { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: found proc session dir empty - deleting"); } rmdir(proc_session_dir); } else { if (orte_debug_flag) { if (OPAL_ERR_NOT_FOUND == opal_os_dirpath_access(proc_session_dir, 0)) { opal_output(0, "sess_dir_finalize: proc session dir does not exist"); } else { opal_output(0, "sess_dir_finalize: proc session dir not empty - leaving"); } } goto CLEANUP; } if (opal_os_dirpath_is_empty(job_session_dir)) { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: found job session dir empty - deleting"); } rmdir(job_session_dir); } else { if (orte_debug_flag) { if (OPAL_ERR_NOT_FOUND == opal_os_dirpath_access(job_session_dir, 0)) { opal_output(0, "sess_dir_finalize: job session dir does not exist"); } else { opal_output(0, "sess_dir_finalize: job session dir not empty - leaving"); } } goto CLEANUP; } if (opal_os_dirpath_is_empty(tmp)) { if (orte_debug_flag) { opal_output(0, "sess_dir_finalize: found top session dir empty - deleting"); } rmdir(tmp); } else { if (orte_debug_flag) { if (OPAL_ERR_NOT_FOUND == opal_os_dirpath_access(tmp, 0)) { opal_output(0, "sess_dir_finalize: top session dir does not exist"); } else { opal_output(0, "sess_dir_finalize: top session dir not empty - leaving"); } } } CLEANUP: free(tmp); free(vpid); free(job_session_dir); free(proc_session_dir); return ORTE_SUCCESS; }
/* * A job has aborted - so force cleanup of the session directory */ int orte_session_dir_cleanup(orte_jobid_t jobid) { int rc = ORTE_SUCCESS; char *tmp = NULL; char *job_session_dir=NULL; if (!orte_create_session_dirs) { /* didn't create them */ return ORTE_SUCCESS; } if (NULL == orte_process_info.tmpdir_base && NULL == orte_process_info.top_session_dir) { /* this should never happen - it means we are calling * cleanup *before* properly setting up the session * dir system. This leaves open the possibility of * accidentally removing directories we shouldn't * touch */ rc = ORTE_ERR_NOT_INITIALIZED; goto CLEANUP; } /* need to setup the top_session_dir with the prefix */ tmp = opal_os_path(false, orte_process_info.tmpdir_base, orte_process_info.top_session_dir, NULL); /* we can only blow away session directories for our job family */ job_session_dir = orte_build_job_session_dir(tmp, ORTE_PROC_MY_NAME, jobid); if (NULL == job_session_dir) { rc = ORTE_ERR_OUT_OF_RESOURCE; goto CLEANUP; } if (ORTE_JOBID_WILDCARD != jobid) { opal_os_dirpath_destroy(job_session_dir, true, orte_dir_check_file); } else { /* if we want the session_dir removed for ALL jobids, then * just recursively blow the whole session away for our job family, * saving only output files */ opal_os_dirpath_destroy(job_session_dir, true, orte_dir_check_file_output); } /* now attempt to eliminate the top level directory itself - this * will fail if anything is present, but ensures we cleanup if * we are the last one out */ opal_os_dirpath_destroy(tmp, false, orte_dir_check_file); if (NULL != job_session_dir && opal_os_dirpath_is_empty(job_session_dir)) { if (orte_debug_flag) { opal_output(0, "sess_dir_cleanup: found job session dir empty - deleting"); } rmdir(job_session_dir); } else { if (orte_debug_flag) { if (OPAL_ERR_NOT_FOUND == opal_os_dirpath_access(job_session_dir, 0)) { opal_output(0, "sess_dir_cleanup: job session dir does not exist"); } else { opal_output(0, "sess_dir_cleanup: job session dir not empty - leaving"); } } goto CLEANUP; } if (opal_os_dirpath_is_empty(tmp)) { if (orte_debug_flag) { opal_output(0, "sess_dir_cleanup: found top session dir empty - deleting"); } rmdir(tmp); } else { if (orte_debug_flag) { if (OPAL_ERR_NOT_FOUND == opal_os_dirpath_access(tmp, 0)) { opal_output(0, "sess_dir_cleanup: top session dir does not exist"); } else { opal_output(0, "sess_dir_cleanup: top session dir not empty - leaving"); } } } CLEANUP: if (NULL != tmp) free(tmp); if (NULL != job_session_dir) free(job_session_dir); return rc; }