Skip to content

btl/sm: fix race condition #1245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion opal/mca/btl/sm/btl_sm_component.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down