1
1
write to file and then rename, so when the file is open for read, its content is known to have been written.

Fixes open-mpi/ompi#1230
Этот коммит содержится в:
Gilles Gouaillardet 2015-12-21 16:37:51 +09:00
родитель 862b12acf9
Коммит db4f483653

Просмотреть файл

@ -607,6 +607,7 @@ create_rndv_file(mca_btl_sm_component_t *comp_ptr,
int rc = OPAL_SUCCESS; int rc = OPAL_SUCCESS;
int fd = -1; int fd = -1;
char *fname = NULL; char *fname = NULL;
char *tmpfname = NULL;
/* used as a temporary store so we can extract shmem_ds info */ /* used as a temporary store so we can extract shmem_ds info */
mca_common_sm_module_t *tmp_modp = NULL; 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 /* 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. */ * 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; int err = errno;
opal_show_help("help-mpi-btl-sm.txt", "sys call fail", true, opal_show_help("help-mpi-btl-sm.txt", "sys call fail", true,
"open(2)", strerror(err), err); "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 */ /* only do this for the mpool case */
OBJ_RELEASE(tmp_modp); OBJ_RELEASE(tmp_modp);
} }
if (0 != rename(tmpfname, fname)) {
rc = OPAL_ERR_IN_ERRNO;
goto out;
}
out: out:
if (-1 != fd) { if (-1 != fd) {
(void)close(fd); (void)close(fd);
} }
if (NULL != tmpfname) {
free(tmpfname);
}
return rc; return rc;
} }