Fossil SCM
Improvements to detection and reporting of file-descriptor 2 not open.
Commit
fdfc039bb3bc3a91865ea416201b9c5d4a2207fb
Parent
88ed51221d2c81c…
1 file changed
+9
-5
+9
-5
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -698,18 +698,22 @@ | ||
| 698 | 698 | ** can corrupt the data file. To avoid this problem, make sure open() |
| 699 | 699 | ** will never return file descriptor 2 or less. */ |
| 700 | 700 | if( !is_valid_fd(2) ){ |
| 701 | 701 | int nTry = 0; |
| 702 | 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) ){ | |
| 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 ){ | |
| 707 | 710 | g.cgiOutput = 1; |
| 708 | 711 | g.httpOut = stdout; |
| 709 | 712 | 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); | |
| 711 | 715 | } |
| 712 | 716 | } |
| 713 | 717 | #endif |
| 714 | 718 | rc = name_search(zCmdName, aCommand, count(aCommand), FOSSIL_FIRST_CMD, &idx); |
| 715 | 719 | if( rc==1 ){ |
| 716 | 720 |
| --- 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 |