diff --git a/opal/mca/btl/sm/btl_sm_component.c b/opal/mca/btl/sm/btl_sm_component.c index 5dee6205848..efe78f3060c 100644 --- a/opal/mca/btl/sm/btl_sm_component.c +++ b/opal/mca/btl/sm/btl_sm_component.c @@ -607,6 +607,7 @@ create_rndv_file(mca_btl_sm_component_t *comp_ptr, int rc = OPAL_SUCCESS; int fd = -1; char *fname = NULL; + char *tmpfname = NULL; /* used as a temporary store so we can extract shmem_ds info */ mca_common_sm_module_t *tmp_modp = NULL; @@ -664,7 +665,12 @@ create_rndv_file(mca_btl_sm_component_t *comp_ptr, /* now just write the contents of tmp_modp->shmem_ds to the full * sizeof(opal_shmem_ds_t), so we know where the mpool_res_size starts. */ - if (-1 == (fd = open(fname, O_CREAT | O_RDWR, 0600))) { + asprintf(&tmpfname, "%s.tmp", fname); + if (NULL == tmpfname) { + rc = OPAL_ERR_OUT_OF_RESOURCE; + goto out; + } + if (-1 == (fd = open(tmpfname, O_CREAT | O_RDWR, 0600))) { int err = errno; opal_show_help("help-mpi-btl-sm.txt", "sys call fail", true, "open(2)", strerror(err), err); @@ -690,11 +696,18 @@ create_rndv_file(mca_btl_sm_component_t *comp_ptr, /* only do this for the mpool case */ OBJ_RELEASE(tmp_modp); } + if (0 != rename(tmpfname, fname)) { + rc = OPAL_ERR_IN_ERRNO; + goto out; + } out: if (-1 != fd) { (void)close(fd); } + if (NULL != tmpfname) { + free(tmpfname); + } return rc; }