@@ -874,19 +874,30 @@ static void _ios_init(ios_t *s)
874
874
/* stream object initializers. we do no allocation. */
875
875
876
876
#if !defined(_OS_WINDOWS_ )
877
+ /*
878
+ * NOTE: we do not handle system call restart in this function,
879
+ * please do it manually:
880
+ *
881
+ * do
882
+ * open_cloexec(...)
883
+ * while (-1 == fd && _enonfatal(errno))
884
+ */
877
885
static int open_cloexec (const char * path , int flags , mode_t mode )
878
886
{
879
887
#ifdef O_CLOEXEC
880
- static int no_cloexec = 0 ;
888
+ static int no_cloexec = 0 ;
881
889
882
890
if (!no_cloexec ) {
883
891
set_io_wait_begin (1 );
884
892
int fd = open (path , flags | O_CLOEXEC , mode );
885
893
set_io_wait_begin (0 );
894
+
886
895
if (fd != -1 )
887
896
return fd ;
888
897
if (errno != EINVAL )
889
898
return -1 ;
899
+
900
+ /* O_CLOEXEC not supported. */
890
901
no_cloexec = 1 ;
891
902
}
892
903
#endif
@@ -918,12 +929,15 @@ ios_t *ios_file(ios_t *s, const char *fname, int rd, int wr, int create, int tru
918
929
#else
919
930
// The mode of the created file is (mode & ~umask), which resolves with
920
931
// default umask to u=rw,g=r,o=r
921
- fd = open_cloexec (fname , flags ,
922
- S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH );
932
+ do
933
+ fd = open_cloexec (fname , flags ,
934
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH );
935
+ while (-1 == fd && _enonfatal (errno ));
923
936
#endif
924
- s = ios_fd (s , fd , 1 , 1 );
925
937
if (fd == -1 )
926
938
goto open_file_err ;
939
+
940
+ s = ios_fd (s , fd , 1 , 1 );
927
941
if (!rd )
928
942
s -> readable = 0 ;
929
943
if (!wr )
0 commit comments