fakeidentd: avoid extra fcntl calls

This commit is contained in:
Denis Vlasenko 2007-01-14 12:31:26 +00:00
parent 19250813a8
commit c14c95ec89

View File

@ -41,10 +41,12 @@ static int do_rd(int fd, void **paramp)
{ {
identd_buf_t *buf = *paramp; identd_buf_t *buf = *paramp;
char *cur, *p; char *cur, *p;
int retval = 0; /* session is ok (so far) */
int sz; int sz;
cur = buf->buf + buf->pos; cur = buf->buf + buf->pos;
if (buf->fd_flag & O_NONBLOCK)
fcntl(fd, F_SETFL, buf->fd_flag); fcntl(fd, F_SETFL, buf->fd_flag);
sz = safe_read(fd, cur, sizeof(buf->buf) - buf->pos); sz = safe_read(fd, cur, sizeof(buf->buf) - buf->pos);
@ -59,18 +61,18 @@ static int do_rd(int fd, void **paramp)
p = strpbrk(cur, "\r\n"); p = strpbrk(cur, "\r\n");
if (p) if (p)
*p = '\0'; *p = '\0';
if (p || !sz || buf->pos == sizeof(buf->buf)) { if (!p && sz && buf->pos <= sizeof(buf->buf))
/* fd is still in nonblocking mode - we never block here */ 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); 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;
term: term:
fcntl(fd, F_SETFL, buf->fd_flag & ~O_NONBLOCK);
free(buf); 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) static int do_timeout(void **paramp)