diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-14 12:07:25 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-14 12:07:25 +0000 |
commit | 19250813a83cb4e1691810d1887658e60e2942d8 (patch) | |
tree | 0994c9573d56581db0bd44bbc89aba34eaac1c6c /networking/isrv_identd.c | |
parent | ffcef2d1f71a1707b94e235e63495178144de861 (diff) | |
download | busybox-w32-19250813a83cb4e1691810d1887658e60e2942d8.tar.gz busybox-w32-19250813a83cb4e1691810d1887658e60e2942d8.tar.bz2 busybox-w32-19250813a83cb4e1691810d1887658e60e2942d8.zip |
fakeidentd: fix daemon mode (was thinking that it is in
inetd-wait mode and dying after timeout). Minor fixes,
comments are improved in places.
Diffstat (limited to 'networking/isrv_identd.c')
-rw-r--r-- | networking/isrv_identd.c | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/networking/isrv_identd.c b/networking/isrv_identd.c index b9481f8d3..30f9a7a26 100644 --- a/networking/isrv_identd.c +++ b/networking/isrv_identd.c | |||
@@ -13,14 +13,6 @@ | |||
13 | 13 | ||
14 | enum { TIMEOUT = 20 }; | 14 | enum { TIMEOUT = 20 }; |
15 | 15 | ||
16 | /* Why use alarm(TIMEOUT-1)? | ||
17 | * isrv's internal select() will run with timeout=TIMEOUT. | ||
18 | * If nothing happens during TIMEOUT-1 seconds (no accept/read), | ||
19 | * then ALL sessions timed out by now. Instead of closing them one-by-one | ||
20 | * (isrv calls do_timeout for each 'stale' session), | ||
21 | * SIGALRM triggered by alarm(TIMEOUT-1) will kill us, terminating them all. | ||
22 | */ | ||
23 | |||
24 | typedef struct identd_buf_t { | 16 | typedef struct identd_buf_t { |
25 | int pos; | 17 | int pos; |
26 | int fd_flag; | 18 | int fd_flag; |
@@ -34,8 +26,6 @@ static int new_peer(isrv_state_t *state, int fd) | |||
34 | int peer; | 26 | int peer; |
35 | identd_buf_t *buf = xzalloc(sizeof(*buf)); | 27 | identd_buf_t *buf = xzalloc(sizeof(*buf)); |
36 | 28 | ||
37 | alarm(TIMEOUT - 1); | ||
38 | |||
39 | peer = isrv_register_peer(state, buf); | 29 | peer = isrv_register_peer(state, buf); |
40 | if (peer < 0) | 30 | if (peer < 0) |
41 | return 0; /* failure */ | 31 | return 0; /* failure */ |
@@ -53,11 +43,9 @@ static int do_rd(int fd, void **paramp) | |||
53 | char *cur, *p; | 43 | char *cur, *p; |
54 | int sz; | 44 | int sz; |
55 | 45 | ||
56 | alarm(TIMEOUT - 1); | ||
57 | |||
58 | cur = buf->buf + buf->pos; | 46 | cur = buf->buf + buf->pos; |
59 | 47 | ||
60 | fcntl(fd, F_SETFL, buf->fd_flag | O_NONBLOCK); | 48 | fcntl(fd, F_SETFL, buf->fd_flag); |
61 | sz = safe_read(fd, cur, sizeof(buf->buf) - buf->pos); | 49 | sz = safe_read(fd, cur, sizeof(buf->buf) - buf->pos); |
62 | 50 | ||
63 | if (sz < 0) { | 51 | if (sz < 0) { |
@@ -95,6 +83,8 @@ static void inetd_mode(void) | |||
95 | identd_buf_t *buf = xzalloc(sizeof(*buf)); | 83 | identd_buf_t *buf = xzalloc(sizeof(*buf)); |
96 | /* We do NOT want nonblocking I/O here! */ | 84 | /* We do NOT want nonblocking I/O here! */ |
97 | buf->fd_flag = fcntl(0, F_GETFL, 0); | 85 | buf->fd_flag = fcntl(0, F_GETFL, 0); |
86 | do | ||
87 | alarm(TIMEOUT); | ||
98 | while (do_rd(0, (void*)&buf) == 0) /* repeat */; | 88 | while (do_rd(0, (void*)&buf) == 0) /* repeat */; |
99 | } | 89 | } |
100 | 90 | ||
@@ -139,6 +129,7 @@ int fakeidentd_main(int argc, char **argv) | |||
139 | xlisten(fd, 5); | 129 | xlisten(fd, 5); |
140 | } | 130 | } |
141 | 131 | ||
142 | isrv_run(fd, new_peer, do_rd, NULL, do_timeout, TIMEOUT, 1); | 132 | isrv_run(fd, new_peer, do_rd, /*do_wr:*/ NULL, do_timeout, |
133 | TIMEOUT, (opt & OPT_inetdwait) ? TIMEOUT : 0); | ||
143 | return 0; | 134 | return 0; |
144 | } | 135 | } |