Skip to content

Commit d352eb9

Browse files
committed
remove outdated workaround for OpenBSD fclose() calling close()
Test program: ```c #include <sys/utsname.h> #include <stdio.h> #include <stdlib.h> #include <fcntl.h> static int closed; int close(int unused) { closed = 1; return 0; } int main() { struct utsname os; int fd; FILE *file; char *closed_str[] = {" not", ""}; uname(&os); if ((fd = open("/dev/null", O_RDONLY)) == -1) return 1; if ((file = fdopen(fd, "rb")) == NULL) return 1; printf("Operating system: %s/%s %s %s\n", os.sysname, os.machine, os.release, os.version); closed = 0; fclose(stdin); printf("close()%s called on stdin\n", closed_str[closed]); closed = 0; fclose(file); printf("close()%s called on nonstd stream\n", closed_str[closed]); } ``` Output: ```console $ ./a.out Operating system: OpenBSD/amd64 7.4 GENERIC.MP#0 close() not called on stdin close() not called on nonstd stream ```
1 parent d5cc80a commit d352eb9

File tree

2 files changed

+2
-7
lines changed

2 files changed

+2
-7
lines changed

configure

-3
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,6 @@ check_define __FreeBSD__ && bsd_detected=true
220220
check_define __OpenBSD__ && {
221221
bsd_detected=true
222222
echo "CFLAGS+=-DIS_OPENBSD">>config.mak
223-
check_compile_run 'whether OpenBSDs fclose() (illegally) calls close()' \
224-
'#include <stdio.h>\n#include<stdlib.h>\nint close(int x){exit(0);}int main(){fclose(stdin);return 1;}' && \
225-
OUR_CPPFLAGS="$OUR_CPPFLAGS -DBROKEN_FCLOSE"
226223
}
227224
check_define __sun && check_define __SVR4 && solaris_detected=true
228225
check_define __HAIKU__ && haiku_detected=true

src/libproxychains.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ typedef struct {
115115
unsigned int first, last, flags;
116116
} close_range_args_t;
117117

118-
/* If there is some `close` or `close_range` system call before do_init,
118+
/* If there is some `close` or `close_range` system call before do_init,
119119
we buffer it, and actually execute them in do_init. */
120120
static int close_fds[16];
121121
static int close_fds_cnt = 0;
@@ -560,9 +560,7 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ
560560
}
561561
}
562562
}
563-
#ifndef BROKEN_FCLOSE
564563
fclose(file);
565-
#endif
566564
if(!count) {
567565
fprintf(stderr, "error: no valid proxy found in config\n");
568566
exit(1);
@@ -639,7 +637,7 @@ HOOKFUNC(int, close_range, unsigned first, unsigned last, int flags) {
639637
int protected_fds[] = {req_pipefd[0], req_pipefd[1], resp_pipefd[0], resp_pipefd[1]};
640638
intsort(protected_fds, 4);
641639
/* We are skipping protected_fds while calling true_close_range()
642-
* If protected_fds cut the range into some sub-ranges, we close sub-ranges BEFORE cut point in the loop.
640+
* If protected_fds cut the range into some sub-ranges, we close sub-ranges BEFORE cut point in the loop.
643641
* [first, cut1-1] , [cut1+1, cut2-1] , [cut2+1, cut3-1]
644642
* Finally, we delete the remaining sub-range, outside the loop. [cut3+1, tail]
645643
*/

0 commit comments

Comments
 (0)