aboutsummaryrefslogtreecommitdiff
path: root/networking/isrv_identd.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-01-14 12:31:26 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-01-14 12:31:26 +0000
commitc14c95ec89b50c936c72c431f867fccf71a324eb (patch)
treea7be7640d0e2d02c2bb4db08a0a28015934ccfef /networking/isrv_identd.c
parent19250813a83cb4e1691810d1887658e60e2942d8 (diff)
downloadbusybox-c14c95ec89b50c936c72c431f867fccf71a324eb.tar.gz
fakeidentd: avoid extra fcntl calls
Diffstat (limited to 'networking/isrv_identd.c')
-rw-r--r--networking/isrv_identd.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/networking/isrv_identd.c b/networking/isrv_identd.c
index 30f9a7a26..389103920 100644
--- a/networking/isrv_identd.c
+++ b/networking/isrv_identd.c
@@ -41,11 +41,13 @@ static int do_rd(int fd, void **paramp)
{
identd_buf_t *buf = *paramp;
char *cur, *p;
+ int retval = 0; /* session is ok (so far) */
int sz;
cur = buf->buf + buf->pos;
- fcntl(fd, F_SETFL, buf->fd_flag);
+ if (buf->fd_flag & O_NONBLOCK)
+ fcntl(fd, F_SETFL, buf->fd_flag);
sz = safe_read(fd, cur, sizeof(buf->buf) - buf->pos);
if (sz < 0) {
@@ -59,18 +61,18 @@ static int do_rd(int fd, void **paramp)
p = strpbrk(cur, "\r\n");
if (p)
*p = '\0';
- if (p || !sz || buf->pos == sizeof(buf->buf)) {
- /* fd is still in nonblocking mode - we never block here */
- fdprintf(fd, "%s : USERID : UNIX : %s\r\n", buf->buf, bogouser);
- goto term;
- }
- ok:
- fcntl(fd, F_SETFL, buf->fd_flag & ~O_NONBLOCK);
- return 0;
+ if (!p && sz && buf->pos <= sizeof(buf->buf))
+ goto ok;
+ /* Terminate session. If we are in server mode, then
+ * fd is still in nonblocking mode - we never block here */
+ fdprintf(fd, "%s : USERID : UNIX : %s\r\n", buf->buf, bogouser);
term:
- fcntl(fd, F_SETFL, buf->fd_flag & ~O_NONBLOCK);
free(buf);
- return 1;
+ retval = 1; /* terminate */
+ ok:
+ if (buf->fd_flag & O_NONBLOCK)
+ fcntl(fd, F_SETFL, buf->fd_flag & ~O_NONBLOCK);
+ return retval;
}
static int do_timeout(void **paramp)