aboutsummaryrefslogtreecommitdiff
path: root/networking/isrv_identd.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2014-01-10 17:12:54 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2014-01-10 17:12:54 +0100
commit604b7b6cc03bab020f03d35f0064ab0e87845616 (patch)
treea6d4fc56ce883a01a0a89260c0291466a03c8a40 /networking/isrv_identd.c
parent1bdbf264540892a20d07cd81d2918dd5519f4bb3 (diff)
downloadbusybox-w32-604b7b6cc03bab020f03d35f0064ab0e87845616.tar.gz
busybox-w32-604b7b6cc03bab020f03d35f0064ab0e87845616.tar.bz2
busybox-w32-604b7b6cc03bab020f03d35f0064ab0e87845616.zip
fakeidentd: simplify ndelay manipulations
function old new delta new_peer 91 79 -12 do_rd 197 152 -45 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/isrv_identd.c')
-rw-r--r--networking/isrv_identd.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/networking/isrv_identd.c b/networking/isrv_identd.c
index c6b0f6528..252c8aba9 100644
--- a/networking/isrv_identd.c
+++ b/networking/isrv_identd.c
@@ -25,8 +25,7 @@ enum { TIMEOUT = 20 };
25 25
26typedef struct identd_buf_t { 26typedef struct identd_buf_t {
27 int pos; 27 int pos;
28 int fd_flag; 28 char buf[64 - sizeof(int)];
29 char buf[64 - 2*sizeof(int)];
30} identd_buf_t; 29} identd_buf_t;
31 30
32#define bogouser bb_common_bufsiz1 31#define bogouser bb_common_bufsiz1
@@ -42,7 +41,7 @@ static int new_peer(isrv_state_t *state, int fd)
42 if (isrv_register_fd(state, peer, fd) < 0) 41 if (isrv_register_fd(state, peer, fd) < 0)
43 return peer; /* failure, unregister peer */ 42 return peer; /* failure, unregister peer */
44 43
45 buf->fd_flag = fcntl(fd, F_GETFL) | O_NONBLOCK; 44 ndelay_on(fd);
46 isrv_want_rd(state, fd); 45 isrv_want_rd(state, fd);
47 return 0; 46 return 0;
48} 47}
@@ -55,8 +54,6 @@ static int do_rd(int fd, void **paramp)
55 54
56 cur = buf->buf + buf->pos; 55 cur = buf->buf + buf->pos;
57 56
58 if (buf->fd_flag & O_NONBLOCK)
59 fcntl(fd, F_SETFL, buf->fd_flag);
60 sz = safe_read(fd, cur, sizeof(buf->buf) - 1 - buf->pos); 57 sz = safe_read(fd, cur, sizeof(buf->buf) - 1 - buf->pos);
61 58
62 if (sz < 0) { 59 if (sz < 0) {
@@ -70,7 +67,7 @@ static int do_rd(int fd, void **paramp)
70 p = strpbrk(cur, "\r\n"); 67 p = strpbrk(cur, "\r\n");
71 if (p) 68 if (p)
72 *p = '\0'; 69 *p = '\0';
73 if (!p && sz && buf->pos < (int)sizeof(buf->buf)) 70 if (!p && sz)
74 return 0; /* "session is ok" */ 71 return 0; /* "session is ok" */
75 72
76 /* Terminate session. If we are in server mode, then 73 /* Terminate session. If we are in server mode, then
@@ -78,8 +75,11 @@ static int do_rd(int fd, void **paramp)
78 if (fd == 0) 75 if (fd == 0)
79 fd++; /* inetd mode? then write to fd 1 */ 76 fd++; /* inetd mode? then write to fd 1 */
80 fdprintf(fd, "%s : USERID : UNIX : %s\r\n", buf->buf, bogouser); 77 fdprintf(fd, "%s : USERID : UNIX : %s\r\n", buf->buf, bogouser);
81 if (buf->fd_flag & O_NONBLOCK) 78 /*
82 fcntl(fd, F_SETFL, buf->fd_flag & ~O_NONBLOCK); 79 * Why bother if we are going to close fd now anyway?
80 * if (server)
81 * ndelay_off(fd);
82 */
83 term: 83 term:
84 free(buf); 84 free(buf);
85 return 1; /* "terminate" */ 85 return 1; /* "terminate" */
@@ -94,10 +94,9 @@ static void inetd_mode(void)
94{ 94{
95 identd_buf_t *buf = xzalloc(sizeof(*buf)); 95 identd_buf_t *buf = xzalloc(sizeof(*buf));
96 /* buf->pos = 0; - xzalloc did it */ 96 /* buf->pos = 0; - xzalloc did it */
97 /* We do NOT want nonblocking I/O here! */
98 /* buf->fd_flag = 0; - xzalloc did it */
99 do 97 do
100 alarm(TIMEOUT); 98 alarm(TIMEOUT);
99 /* Note: we do NOT want nonblocking I/O here! */
101 while (do_rd(0, (void*)&buf) == 0); 100 while (do_rd(0, (void*)&buf) == 0);
102} 101}
103 102