Fossil SCM

Improvements to detection and reporting of file-descriptor 2 not open.

drh 2015-02-08 21:15 trunk
Commit fdfc039bb3bc3a91865ea416201b9c5d4a2207fb
1 file changed +9 -5
+9 -5
--- src/main.c
+++ src/main.c
@@ -698,18 +698,22 @@
698698
** can corrupt the data file. To avoid this problem, make sure open()
699699
** will never return file descriptor 2 or less. */
700700
if( !is_valid_fd(2) ){
701701
int nTry = 0;
702702
int fd = 0;
703
- while( !is_valid_fd(2)
704
- && (nTry++)<2
705
- && (fd = open("/dev/null",O_WRONLY))>=0 && fd<2 ){}
706
- if( fd<2 && !is_valid_fd(2) ){
703
+ int x = 0;
704
+ do{
705
+ fd = open("/dev/null",O_WRONLY);
706
+ if( fd>=2 ) break;
707
+ if( fd<0 ) x = errno;
708
+ }while( nTry++ < 2 );
709
+ if( fd<2 ){
707710
g.cgiOutput = 1;
708711
g.httpOut = stdout;
709712
g.fullHttpReply = !g.isHTTP;
710
- fossil_fatal("file descriptor 2 is not open");
713
+ fossil_fatal("file descriptor 2 is not open. (fd=%d, errno=%d)",
714
+ fd, x);
711715
}
712716
}
713717
#endif
714718
rc = name_search(zCmdName, aCommand, count(aCommand), FOSSIL_FIRST_CMD, &idx);
715719
if( rc==1 ){
716720
--- src/main.c
+++ src/main.c
@@ -698,18 +698,22 @@
698 ** can corrupt the data file. To avoid this problem, make sure open()
699 ** will never return file descriptor 2 or less. */
700 if( !is_valid_fd(2) ){
701 int nTry = 0;
702 int fd = 0;
703 while( !is_valid_fd(2)
704 && (nTry++)<2
705 && (fd = open("/dev/null",O_WRONLY))>=0 && fd<2 ){}
706 if( fd<2 && !is_valid_fd(2) ){
 
 
 
707 g.cgiOutput = 1;
708 g.httpOut = stdout;
709 g.fullHttpReply = !g.isHTTP;
710 fossil_fatal("file descriptor 2 is not open");
 
711 }
712 }
713 #endif
714 rc = name_search(zCmdName, aCommand, count(aCommand), FOSSIL_FIRST_CMD, &idx);
715 if( rc==1 ){
716
--- src/main.c
+++ src/main.c
@@ -698,18 +698,22 @@
698 ** can corrupt the data file. To avoid this problem, make sure open()
699 ** will never return file descriptor 2 or less. */
700 if( !is_valid_fd(2) ){
701 int nTry = 0;
702 int fd = 0;
703 int x = 0;
704 do{
705 fd = open("/dev/null",O_WRONLY);
706 if( fd>=2 ) break;
707 if( fd<0 ) x = errno;
708 }while( nTry++ < 2 );
709 if( fd<2 ){
710 g.cgiOutput = 1;
711 g.httpOut = stdout;
712 g.fullHttpReply = !g.isHTTP;
713 fossil_fatal("file descriptor 2 is not open. (fd=%d, errno=%d)",
714 fd, x);
715 }
716 }
717 #endif
718 rc = name_search(zCmdName, aCommand, count(aCommand), FOSSIL_FIRST_CMD, &idx);
719 if( rc==1 ){
720

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button