25
25
#include "ompi/constants.h"
26
26
#include "ompi/mca/sharedfp/sharedfp.h"
27
27
#include "ompi/mca/sharedfp/base/base.h"
28
+ #include "opal/util/output.h"
29
+ #include "opal/util/fd.h"
30
+
28
31
29
32
/*Use fcntl to lock the hidden file which stores the current position*/
30
33
#include <fcntl.h>
@@ -76,7 +79,10 @@ int mca_sharedfp_lockedfile_request_position(struct mca_sharedfp_base_data_t * s
76
79
77
80
/* read from the file */
78
81
lseek ( fd , 0 , SEEK_SET );
79
- read ( fd , & buf , sizeof (OMPI_MPI_OFFSET_TYPE ));
82
+ ret = opal_fd_read ( fd , sizeof (OMPI_MPI_OFFSET_TYPE ), & buf );
83
+ if (OPAL_SUCCESS != ret ) {
84
+ goto exit ;
85
+ }
80
86
if ( mca_sharedfp_lockedfile_verbose ) {
81
87
opal_output (ompi_sharedfp_base_framework .framework_output ,
82
88
"sharedfp_lockedfile_request_position: Read last_offset=%lld! ret=%d\n" ,buf , ret );
@@ -92,8 +98,11 @@ int mca_sharedfp_lockedfile_request_position(struct mca_sharedfp_base_data_t * s
92
98
93
99
/* write to the file */
94
100
lseek ( fd , 0 , SEEK_SET );
95
- write ( fd , & position , sizeof (OMPI_MPI_OFFSET_TYPE ));
96
-
101
+ ret = opal_best_effort_write ( fd , & position , sizeof (OMPI_MPI_OFFSET_TYPE ));
102
+ /* No need to handle error case here, the subsequent steps are identical
103
+ in case of ret != OPAL_SUCCESS, namely release lock and return ret */
104
+
105
+ exit :
97
106
/* unlock the file */
98
107
if ( mca_sharedfp_lockedfile_verbose ) {
99
108
opal_output (ompi_sharedfp_base_framework .framework_output ,
@@ -115,7 +124,10 @@ int mca_sharedfp_lockedfile_request_position(struct mca_sharedfp_base_data_t * s
115
124
if (fcntl (fd , F_SETLK , & fl ) == -1 ) {
116
125
opal_output (0 ,"sharedfp_lockedfile_request_position:failed to release lock for fd: %d\n" ,fd );
117
126
opal_output (0 ,"error(%i): %s" , errno , strerror (errno ));
118
- return OMPI_ERROR ;
127
+ /* Only overwrite error code if it was OPAL_SUCCESS previously */
128
+ if (OPAL_SUCCESS == ret ) {
129
+ ret = OMPI_ERROR ;
130
+ }
119
131
}
120
132
else {
121
133
if ( mca_sharedfp_lockedfile_verbose ) {
0 commit comments