@@ -593,6 +593,7 @@ create_rndv_file(mca_btl_sm_component_t *comp_ptr,
593
593
int rc = OPAL_SUCCESS ;
594
594
int fd = -1 ;
595
595
char * fname = NULL ;
596
+ char * tmpfname = NULL ;
596
597
/* used as a temporary store so we can extract shmem_ds info */
597
598
mca_common_sm_module_t * tmp_modp = NULL ;
598
599
@@ -650,7 +651,12 @@ create_rndv_file(mca_btl_sm_component_t *comp_ptr,
650
651
651
652
/* now just write the contents of tmp_modp->shmem_ds to the full
652
653
* sizeof(opal_shmem_ds_t), so we know where the mpool_res_size starts. */
653
- if (-1 == (fd = open (fname , O_CREAT | O_RDWR , 0600 ))) {
654
+ asprintf (& tmpfname , "%s.tmp" , fname );
655
+ if (NULL == tmpfname ) {
656
+ rc = OPAL_ERR_OUT_OF_RESOURCE ;
657
+ goto out ;
658
+ }
659
+ if (-1 == (fd = open (tmpfname , O_CREAT | O_RDWR , 0600 ))) {
654
660
int err = errno ;
655
661
opal_show_help ("help-mpi-btl-sm.txt" , "sys call fail" , true,
656
662
"open(2)" , strerror (err ), err );
@@ -676,11 +682,20 @@ create_rndv_file(mca_btl_sm_component_t *comp_ptr,
676
682
/* only do this for the mpool case */
677
683
OBJ_RELEASE (tmp_modp );
678
684
}
685
+ (void )close (fd );
686
+ fd = -1 ;
687
+ if (0 != rename (tmpfname , fname )) {
688
+ rc = OPAL_ERR_IN_ERRNO ;
689
+ goto out ;
690
+ }
679
691
680
692
out :
681
693
if (-1 != fd ) {
682
694
(void )close (fd );
683
695
}
696
+ if (NULL != tmpfname ) {
697
+ free (tmpfname );
698
+ }
684
699
return rc ;
685
700
}
686
701
0 commit comments