| @@ -1,17 +1,18 @@ | | | @@ -1,17 +1,18 @@ |
1 | $NetBSD: patch-stud.c,v 1.2 2015/02/20 09:32:07 fhajny Exp $ | | 1 | $NetBSD: patch-stud.c,v 1.3 2015/02/23 22:27:37 fhajny Exp $ |
2 | | | 2 | |
3 | SunOS fixes as per https://github.com/bumptech/stud/pull/71. | | 3 | SunOS fixes as per https://github.com/bumptech/stud/pull/71. |
4 | SSL fixes as per https://github.com/bumptech/stud/pull/130. | | 4 | SSL fixes as per https://github.com/bumptech/stud/pull/130. |
| | | 5 | Fix for POSIX accept() that can also return ECONNABORTED. |
5 | | | 6 | |
6 | --- stud.c.orig 2012-08-10 23:40:19.000000000 +0000 | | 7 | --- stud.c.orig 2012-08-10 23:40:19.000000000 +0000 |
7 | +++ stud.c | | 8 | +++ stud.c |
8 | @@ -189,9 +189,17 @@ typedef struct proxystate { | | 9 | @@ -189,9 +189,17 @@ typedef struct proxystate { |
9 | | | 10 | |
10 | /* Set a file descriptor (socket) to non-blocking mode */ | | 11 | /* Set a file descriptor (socket) to non-blocking mode */ |
11 | static void setnonblocking(int fd) { | | 12 | static void setnonblocking(int fd) { |
12 | - int flag = 1; | | 13 | - int flag = 1; |
13 | - | | 14 | - |
14 | - assert(ioctl(fd, FIONBIO, &flag) == 0); | | 15 | - assert(ioctl(fd, FIONBIO, &flag) == 0); |
15 | + int flag; | | 16 | + int flag; |
16 | +#if defined(O_NONBLOCK) | | 17 | +#if defined(O_NONBLOCK) |
17 | + /* O_NONBLOCK is more portable and POSIX-standard */ | | 18 | + /* O_NONBLOCK is more portable and POSIX-standard */ |
| @@ -58,26 +59,35 @@ SSL fixes as per https://github.com/bump | | | @@ -58,26 +59,35 @@ SSL fixes as per https://github.com/bump |
58 | - LOG("{%s} Unexpected SSL error (in handshake): %d\n", w->fd == ps->fd_up ? "client" : "backend", err); | | 59 | - LOG("{%s} Unexpected SSL error (in handshake): %d\n", w->fd == ps->fd_up ? "client" : "backend", err); |
59 | + | | 60 | + |
60 | + // Try and get more detail on the error from the SSL | | 61 | + // Try and get more detail on the error from the SSL |
61 | + // error queue. ERR_error_string requires a char buffer | | 62 | + // error queue. ERR_error_string requires a char buffer |
62 | + // of 120 bytes. | | 63 | + // of 120 bytes. |
63 | + unsigned long err_detail = ERR_get_error(); | | 64 | + unsigned long err_detail = ERR_get_error(); |
64 | + char err_msg[120]; | | 65 | + char err_msg[120]; |
65 | + ERR_error_string(err_detail, err_msg); | | 66 | + ERR_error_string(err_detail, err_msg); |
66 | + | | 67 | + |
67 | + LOG("{client} Unexpected SSL error (in handshake): %d, %s\n", err, err_msg); | | 68 | + LOG("{client} Unexpected SSL error (in handshake): %d, %s\n", err, err_msg); |
68 | shutdown_proxy(ps, SHUTDOWN_SSL); | | 69 | shutdown_proxy(ps, SHUTDOWN_SSL); |
69 | } | | 70 | } |
70 | } | | 71 | } |
| | | 72 | @@ -1312,7 +1335,7 @@ static void handle_accept(struct ev_loop |
| | | 73 | break; |
| | | 74 | |
| | | 75 | default: |
| | | 76 | - assert(errno == EINTR || errno == EWOULDBLOCK || errno == EAGAIN); |
| | | 77 | + assert(errno == EINTR || errno == EWOULDBLOCK || errno == EAGAIN || errno == ECONNABORTED); |
| | | 78 | break; |
| | | 79 | } |
| | | 80 | return; |
71 | @@ -1751,24 +1774,16 @@ void daemonize () { | | 81 | @@ -1751,24 +1774,16 @@ void daemonize () { |
72 | exit(0); | | 82 | exit(0); |
73 | } | | 83 | } |
74 | | | 84 | |
75 | - /* close standard streams */ | | 85 | - /* close standard streams */ |
76 | - fclose(stdin); | | 86 | - fclose(stdin); |
77 | - fclose(stdout); | | 87 | - fclose(stdout); |
78 | - fclose(stderr); | | 88 | - fclose(stderr); |
79 | - | | 89 | - |
80 | /* reopen standard streams to null device */ | | 90 | /* reopen standard streams to null device */ |
81 | - stdin = fopen(NULL_DEV, "r"); | | 91 | - stdin = fopen(NULL_DEV, "r"); |
82 | - if (stdin == NULL) { | | 92 | - if (stdin == NULL) { |
83 | + if (freopen(NULL_DEV, "r", stdin) == NULL) { | | 93 | + if (freopen(NULL_DEV, "r", stdin) == NULL) { |