prelude-lml/master: Improvement when reading input from stdin

[email protected] Mon, 8 Feb 2010 11:24:48 +0100 (CET)
Newsgroups gmane.comp.security.ids.prelude.cvs
Message-ID <[email protected]>
commit 6f6ed7f8659b559ca02a9481b5fc45bff18d7749
Author: Yoann Vandoorselaere <[email protected]>
Date:   Thu Feb 4 17:35:12 2010 +0100

    Improvement when reading input from stdin
    
    Previously, there was no monitor for stdin input, everything was read
    at once upon start and further input was ignored. We now use ev_io()
    for standard input monitoring.


========================================

 configure.in                      |    1 +
 libmissing/Makefile.am            |   39 ++++++++++++++++-
 libmissing/ioctl.c                |   51 +++++++++++++++++++++
 libmissing/m4/gnulib-cache.m4     |    3 +-
 libmissing/m4/gnulib-comp.m4      |   16 +++++++
 libmissing/m4/sys_ioctl_h.m4      |   68 +++++++++++++++++++++++++++++
 libmissing/sys_ioctl.in.h         |   73 +++++++++++++++++++++++++++++++
 libmissing/tests/Makefile.am      |    8 +++
 libmissing/tests/test-sys_ioctl.c |   27 +++++++++++
 src/file-server.c                 |   87 ++++++++++++++++++++++++++++++++-----
 10 files changed, 360 insertions(+), 13 deletions(-)

========================================

diff --git a/configure.in b/configure.in
index 2f8d55c..325d9af 100644
--- a/configure.in
+++ b/configure.in
@@ -50,6 +50,7 @@ AC_HEADER_TIME
 AC_TYPE_SIGNAL
 AC_C_INLINE
 AC_SYS_LARGEFILE
+AC_CHECK_HEADERS_ONCE(sys/filio.h)
 
 
 
diff --git a/libmissing/Makefile.am b/libmissing/Makefile.am
index f34c8d6..35a3d9c 100644
--- a/libmissing/Makefile.am
+++ b/libmissing/Makefile.am
@@ -9,7 +9,7 @@
 # the same distribution terms as the rest of that program.
 #
 # Generated by gnulib-tool.
-# Reproduce by: gnulib-tool --import --dir=. --lib=libmissing --source-base=libmissing --m4-base=libmissing/m4 --doc-base=libmissing/doc --tests-base=libmissing/tests --aux-dir=. --with-tests --lgpl --libtool --macro-prefix=gl --no-vc-files bind close fnmatch-gnu getaddrinfo glob iconv inet_ntop mktime nl_langinfo pathmax recvfrom servent sigaction sleep snprintf socket socklen strptime strsep sys_select
+# Reproduce by: gnulib-tool --import --dir=. --lib=libmissing --source-base=libmissing --m4-base=libmissing/m4 --doc-base=libmissing/doc --tests-base=libmissing/tests --aux-dir=. --with-tests --lgpl --libtool --macro-prefix=gl --no-vc-files bind close fnmatch-gnu getaddrinfo glob iconv inet_ntop ioctl mktime nl_langinfo pathmax recvfrom servent sigaction sleep snprintf socket socklen strptime strsep sys_select
 
 AUTOMAKE_OPTIONS = 1.5 gnits
 
@@ -408,6 +408,15 @@ EXTRA_libmissing_la_SOURCES += inet_ntop.c
 
 ## end   gnulib module inet_ntop
 
+## begin gnulib module ioctl
+
+
+EXTRA_DIST += ioctl.c w32sock.h
+
+EXTRA_libmissing_la_SOURCES += ioctl.c
+
+## end   gnulib module ioctl
+
 ## begin gnulib module langinfo
 
 BUILT_SOURCES += langinfo.h
@@ -1151,6 +1160,34 @@ EXTRA_libmissing_la_SOURCES += strsep.c
 
 ## end   gnulib module strsep
 
+## begin gnulib module sys_ioctl
+
+BUILT_SOURCES += sys/ioctl.h
+
+# We need the following in order to create <sys/ioctl.h> when the system
+# does not have a complete one.
+sys/ioctl.h: sys_ioctl.in.h $(WARN_ON_USE_H)
+	$(AM_V_at)$(MKDIR_P) sys
+	$(AM_V_GEN)rm -f $@-t $@ && \
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+	  sed -e 's|@''HAVE_SYS_IOCTL_H''@|$(HAVE_SYS_IOCTL_H)|g' \
+	      -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+	      -e 's|@''NEXT_SYS_IOCTL_H''@|$(NEXT_SYS_IOCTL_H)|g' \
+	      -e 's|@''GNULIB_IOCTL''@|$(GNULIB_IOCTL)|g' \
+	      -e 's|@''SYS_IOCTL_H_HAVE_WINSOCK2_H''@|$(SYS_IOCTL_H_HAVE_WINSOCK2_H)|g' \
+	      -e 's|@''SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|g' \
+	      -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+	      < $(srcdir)/sys_ioctl.in.h; \
+	} > $@-t && \
+	mv $@-t $@
+MOSTLYCLEANFILES += sys/ioctl.h sys/ioctl.h-t
+MOSTLYCLEANDIRS += sys
+
+EXTRA_DIST += sys_ioctl.in.h
+
+## end   gnulib module sys_ioctl
+
 ## begin gnulib module sys_select
 
 BUILT_SOURCES += sys/select.h
diff --git a/libmissing/ioctl.c b/libmissing/ioctl.c
new file mode 100644
index 0000000..771892b
--- /dev/null
+++ b/libmissing/ioctl.c
@@ -0,0 +1,51 @@
+/* ioctl.c --- wrappers for Windows ioctl function
+
+   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#include <sys/ioctl.h>
+
+#include <stdarg.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+int
+rpl_ioctl (int fd, int req, ...)
+{
+  void *buf;
+  va_list args;
+  SOCKET sock;
+  int r;
+
+  va_start (args, req);
+  buf = va_arg (args, void *);
+  va_end (args);
+
+  sock = FD_TO_SOCKET (fd);
+  r = ioctlsocket (sock, req, buf);
+  if (r < 0)
+    set_winsock_errno ();
+
+  return r;
+}
diff --git a/libmissing/m4/gnulib-cache.m4 b/libmissing/m4/gnulib-cache.m4
index 850d3bc..e5c9a79 100644
--- a/libmissing/m4/gnulib-cache.m4
+++ b/libmissing/m4/gnulib-cache.m4
@@ -15,7 +15,7 @@
 
 
 # Specification in the form of a command-line invocation:
-#   gnulib-tool --import --dir=. --lib=libmissing --source-base=libmissing --m4-base=libmissing/m4 --doc-base=libmissing/doc --tests-base=libmissing/tests --aux-dir=. --with-tests --lgpl --libtool --macro-prefix=gl --no-vc-files bind close fnmatch-gnu getaddrinfo glob iconv inet_ntop mktime nl_langinfo pathmax recvfrom servent sigaction sleep snprintf socket socklen strptime strsep sys_select
+#   gnulib-tool --import --dir=. --lib=libmissing --source-base=libmissing --m4-base=libmissing/m4 --doc-base=libmissing/doc --tests-base=libmissing/tests --aux-dir=. --with-tests --lgpl --libtool --macro-prefix=gl --no-vc-files bind close fnmatch-gnu getaddrinfo glob iconv inet_ntop ioctl mktime nl_langinfo pathmax recvfrom servent sigaction sleep snprintf socket socklen strptime strsep sys_select
 
 # Specification in the form of a few gnulib-tool.m4 macro invocations:
 gl_LOCAL_DIR([])
@@ -27,6 +27,7 @@ gl_MODULES([
   glob
   iconv
   inet_ntop
+  ioctl
   mktime
   nl_langinfo
   pathmax
diff --git a/libmissing/m4/gnulib-comp.m4 b/libmissing/m4/gnulib-comp.m4
index 957fe33..1001f6a 100644
--- a/libmissing/m4/gnulib-comp.m4
+++ b/libmissing/m4/gnulib-comp.m4
@@ -81,6 +81,16 @@ AC_SUBST([LTALLOCA])
   AM_ICONV
   gl_INET_NTOP
   gl_ARPA_INET_MODULE_INDICATOR([inet_ntop])
+  AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+  if test "$ac_cv_header_winsock2_h" = yes; then
+    dnl Even if the 'socket' module is not used here, another part of the
+    dnl application may use it and pass file descriptors that refer to
+    dnl sockets to the ioctl() function. So enable the support for sockets.
+    AC_LIBOBJ([ioctl])
+    gl_REPLACE_SYS_IOCTL_H
+  fi
+  gl_SYS_IOCTL_MODULE_INDICATOR([ioctl])
+  gl_MODULE_INDICATOR([ioctl])
   gl_LANGINFO_H
   gl_LOCALCHARSET
   LOCALCHARSET_TESTS_ENVIRONMENT="CHARSETALIASDIR=\"\$(top_builddir)/$gl_source_base\""
@@ -148,6 +158,8 @@ AC_SUBST([LTALLOCA])
   gl_FUNC_STRPTIME
   gl_FUNC_STRSEP
   gl_STRING_MODULE_INDICATOR([strsep])
+  gl_SYS_IOCTL_H
+  AC_PROG_MKDIR_P
   gl_HEADER_SYS_SELECT
   AC_PROG_MKDIR_P
   gl_HEADER_SYS_SOCKET
@@ -346,6 +358,7 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/glob.c
   lib/glob.in.h
   lib/inet_ntop.c
+  lib/ioctl.c
   lib/langinfo.in.h
   lib/localcharset.c
   lib/localcharset.h
@@ -395,6 +408,7 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/strnlen1.h
   lib/strptime.c
   lib/strsep.c
+  lib/sys_ioctl.in.h
   lib/sys_select.in.h
   lib/sys_socket.in.h
   lib/sys_stat.in.h
@@ -482,6 +496,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/strings_h.m4
   m4/strptime.m4
   m4/strsep.m4
+  m4/sys_ioctl_h.m4
   m4/sys_select_h.m4
   m4/sys_socket_h.m4
   m4/sys_stat_h.m4
@@ -546,6 +561,7 @@ AC_DEFUN([gl_FILE_LIST], [
   tests/test-strerror.c
   tests/test-string.c
   tests/test-strings.c
+  tests/test-sys_ioctl.c
   tests/test-sys_select.c
   tests/test-sys_socket.c
   tests/test-sys_stat.c
diff --git a/libmissing/m4/sys_ioctl_h.m4 b/libmissing/m4/sys_ioctl_h.m4
new file mode 100644
index 0000000..829dc61
--- /dev/null
+++ b/libmissing/m4/sys_ioctl_h.m4
@@ -0,0 +1,68 @@
+# sys_ioctl_h.m4 serial 5
+dnl Copyright (C) 2008-2010 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl Written by Bruno Haible.
+
+AC_DEFUN([gl_SYS_IOCTL_H],
+[
+  dnl Use AC_REQUIRE here, so that the default behavior below is expanded
+  dnl once only, before all statements that occur in other macros.
+  AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
+
+  AC_CHECK_HEADERS_ONCE([sys/ioctl.h])
+  if test $ac_cv_header_sys_ioctl_h = yes; then
+    HAVE_SYS_IOCTL_H=1
+    dnl Test whether <sys/ioctl.h> declares ioctl(), or whether some other
+    dnl header file, such as <unistd.h> or <stropts.h>, is needed for that.
+    AC_CACHE_CHECK([whether <sys/ioctl.h> declares ioctl],
+      [gl_cv_decl_ioctl_in_sys_ioctl_h],
+      [dnl We cannot use AC_CHECK_DECL because it produces its own messages.
+       AC_COMPILE_IFELSE(
+         [AC_LANG_PROGRAM(
+            [AC_INCLUDES_DEFAULT([#include <sys/ioctl.h>])],
+            [(void) ioctl;])],
+         [gl_cv_decl_ioctl_in_sys_ioctl_h=yes],
+         [gl_cv_decl_ioctl_in_sys_ioctl_h=no])
+      ])
+  else
+    HAVE_SYS_IOCTL_H=0
+  fi
+  AC_SUBST([HAVE_SYS_IOCTL_H])
+  dnl <sys/ioctl.h> is always overridden, because of GNULIB_POSIXCHECK.
+  gl_CHECK_NEXT_HEADERS([sys/ioctl.h])
+
+  dnl Check for declarations of anything we want to poison if the
+  dnl corresponding gnulib module is not in use.
+  gl_WARN_ON_USE_PREPARE([[#include <sys/ioctl.h>
+/* Some platforms declare ioctl in the wrong header.  */
+#ifndef __GLIBC__
+# include <unistd.h>
+#endif
+    ]], [ioctl])
+])
+
+dnl Unconditionally enables the replacement of <sys/ioctl.h>.
+AC_DEFUN([gl_REPLACE_SYS_IOCTL_H],
+[
+  dnl This is a no-op, because <sys/ioctl.h> is always overridden.
+  :
+])
+
+AC_DEFUN([gl_SYS_IOCTL_MODULE_INDICATOR],
+[
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+  AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
+  GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
+])
+
+AC_DEFUN([gl_SYS_IOCTL_H_DEFAULTS],
+[
+  GNULIB_IOCTL=0;         AC_SUBST([GNULIB_IOCTL])
+  dnl Assume proper GNU behavior unless another module says otherwise.
+  SYS_IOCTL_H_HAVE_WINSOCK2_H=0; AC_SUBST([SYS_IOCTL_H_HAVE_WINSOCK2_H])
+  SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=0;
+                        AC_SUBST([SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS])
+])
diff --git a/libmissing/sys_ioctl.in.h b/libmissing/sys_ioctl.in.h
new file mode 100644
index 0000000..d8bbacb
--- /dev/null
+++ b/libmissing/sys_ioctl.in.h
@@ -0,0 +1,73 @@
+/* Substitute for and wrapper around <sys/ioctl.h>.
+   Copyright (C) 2008-2010 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#ifndef _GL_SYS_IOCTL_H
+
+#if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+#endif
+
+/* The include_next requires a split double-inclusion guard.  */
+#if @HAVE_SYS_IOCTL_H@
+# @INCLUDE_NEXT@ @NEXT_SYS_IOCTL_H@
+#endif
+
+#ifndef _GL_SYS_IOCTL_H
+#define _GL_SYS_IOCTL_H
+
+/* AIX 5.1 and Solaris 10 declare ioctl() in <unistd.h> and in <stropts.h>,
+   but not in <sys/ioctl.h>.
+   But avoid namespace pollution on glibc systems.  */
+#ifndef __GLIBC__
+# include <unistd.h>
+#endif
+
+/* The definition of _GL_WARN_ON_USE is copied here.  */
+
+
+/* Declare overridden functions.  */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#if @GNULIB_IOCTL@
+# if @SYS_IOCTL_H_HAVE_WINSOCK2_H@
+#  undef ioctl
+#  define ioctl rpl_ioctl
+extern int ioctl (int fd, int request, ... /* {void *,char *} arg */);
+# endif
+#elif @SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
+# undef ioctl
+# define ioctl ioctl_used_without_requesting_gnulib_module_ioctl
+#elif defined GNULIB_POSIXCHECK
+# undef ioctl
+# if HAVE_RAW_DECL_IOCTL
+_GL_WARN_ON_USE (ioctl, "ioctl does not portably work on sockets - "
+                 "use gnulib module ioctl for portability");
+# endif
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* _GL_SYS_IOCTL_H */
+#endif /* _GL_SYS_IOCTL_H */
diff --git a/libmissing/tests/Makefile.am b/libmissing/tests/Makefile.am
index 0aaa768..4da05ba 100644
--- a/libmissing/tests/Makefile.am
+++ b/libmissing/tests/Makefile.am
@@ -395,6 +395,14 @@ EXTRA_DIST += test-strings.c
 
 ## end   gnulib module strings-tests
 
+## begin gnulib module sys_ioctl-tests
+
+TESTS += test-sys_ioctl
+check_PROGRAMS += test-sys_ioctl
+EXTRA_DIST += test-sys_ioctl.c
+
+## end   gnulib module sys_ioctl-tests
+
 ## begin gnulib module sys_select-tests
 
 TESTS += test-sys_select
diff --git a/libmissing/tests/test-sys_ioctl.c b/libmissing/tests/test-sys_ioctl.c
new file mode 100644
index 0000000..1f44d4a
--- /dev/null
+++ b/libmissing/tests/test-sys_ioctl.c
@@ -0,0 +1,27 @@
+/* Test of <sys/ioctl.h> substitute.
+   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Eric Blake <[email protected]>, 2009.  */
+
+#include <config.h>
+
+#include <sys/ioctl.h>
+
+int
+main (void)
+{
+  return 0;
+}
diff --git a/src/file-server.c b/src/file-server.c
index fdfa6c7..2f9aeeb 100644
--- a/src/file-server.c
+++ b/src/file-server.c
@@ -28,6 +28,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/types.h>
+#include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <errno.h>
@@ -35,6 +36,10 @@
 
 #include <gcrypt.h>
 
+#ifdef HAVE_SYS_FILIO_H
+# include <sys/filio.h>
+#endif
+
 #if TIME_WITH_SYS_TIME
 # include <sys/time.h>
 # include <time.h>
@@ -120,11 +125,16 @@ typedef struct {
         uint64_t need_more_read;
         uint64_t last_size;
 
-        ev_stat event;
+        union {
+                ev_stat st;
+                ev_io io;
+        } event;
+
         int prev_errno;
 } monitor_fd_t;
 
 
+static void libev_io_cb(ev_io *io, int revents);
 static void libev_stat_cb(ev_stat *st, int revents);
 static int check_logfile_data(monitor_fd_t *monitor, ev_statdata *st);
 void _lml_handle_signal_if_needed(void);
@@ -506,7 +516,7 @@ static int check_logfile_data(monitor_fd_t *monitor, ev_statdata *st)
         off_t len, ret;
         int eventno = 0;
 
-        if ( monitor->fd != stdin && ! monitor->need_more_read && st->st_size == monitor->last_size )
+        if ( ! monitor->need_more_read && st->st_size == monitor->last_size )
                 return 0;
 
         len = (st->st_size - monitor->last_size) + monitor->need_more_read;
@@ -550,6 +560,44 @@ static int check_logfile_data(monitor_fd_t *monitor, ev_statdata *st)
 }
 
 
+static int check_stdin_data(monitor_fd_t *monitor)
+{
+        size_t slen;
+        off_t ret, len = LOG_LINE_MAXSIZE;
+        int eventno = 0, bytes;
+
+        if ( config.batch_mode )
+                len = 8192;
+        else {
+                ret = ioctl(STDIN_FILENO, FIONREAD, &bytes);
+                if ( ret < 0 ) {
+                        prelude_log(PRELUDE_LOG_ERR, "FIONREAD failed on stdin: %s.\n", strerror(errno));
+                        return -1;
+                }
+
+                len = bytes;
+        }
+
+        while ( (ret = read_logfile(monitor, len)) >= 0 ) {
+
+                eventno++;
+                config.line_processed++;
+
+                /*
+                 * If the line we read only contained a '\n', string and len will be 0.
+                 */
+                if ( (slen = prelude_string_get_len(monitor->buf)) ) {
+                        lml_dispatch_log(monitor->source, prelude_string_get_string(monitor->buf), slen);
+                }
+
+                prelude_string_clear(monitor->buf);
+                _lml_handle_signal_if_needed();
+        }
+
+        return eventno;
+}
+
+
 
 static monitor_fd_t *monitor_new(lml_log_source_t *ls)
 {
@@ -571,10 +619,16 @@ static monitor_fd_t *monitor_new(lml_log_source_t *ls)
                 return NULL;
         }
 
-        ev_stat_init(&new->event, libev_stat_cb, lml_log_source_get_name(new->source), 1);
-        new->event.data = new;
+        if ( strcmp(lml_log_source_get_name(ls), STDIN_FILENAME) != 0 ) {
+                ev_stat_init(&new->event.st, libev_stat_cb, lml_log_source_get_name(new->source), 1);
+                new->event.st.data = new;
+                ev_stat_start(&new->event.st);
+        } else {
+                ev_io_init(&new->event.io, libev_io_cb, STDIN_FILENO, EV_READ);
+                new->event.io.data = new;
+                ev_io_start(&new->event.io);
+        }
 
-        ev_stat_start(&new->event);
         prelude_list_add(&inactive_fd_list, &new->list);
 
         return new;
@@ -832,6 +886,15 @@ static int is_file_already_used(monitor_fd_t *monitor, ev_statdata *st_old, ev_s
 }
 
 
+static void libev_io_cb(ev_io *io, int revents)
+{
+        int ret;
+
+        ret = check_stdin_data(io->data);
+        if ( ret <= 0 )
+                ev_io_stop(io);
+}
+
 
 static void libev_stat_cb(ev_stat *st, int revents)
 {
@@ -842,11 +905,9 @@ static void libev_stat_cb(ev_stat *st, int revents)
                 if ( monitor_open(monitor) < 0 )
                         return;
 
-        if ( monitor->fd != stdin ) {
-                ret = is_file_already_used(monitor, &st->prev, &st->attr);
-                if ( ret < 0 )
-                        return;
-        }
+        ret = is_file_already_used(monitor, &st->prev, &st->attr);
+        if ( ret < 0 )
+                return;
 
         /*
          * check mtime consistency.
@@ -881,7 +942,11 @@ int file_server_read_once(void)
         prelude_list_for_each_safe(&active_fd_list, tmp, bkp) {
                 monitor = prelude_list_entry(tmp, monitor_fd_t, list);
 
-                event = check_logfile_data(monitor, &monitor->event.attr);
+                if ( monitor->fd != stdin )
+                        event = check_logfile_data(monitor, &monitor->event.st.attr);
+                else
+                        event = check_stdin_data(monitor);
+
                 if ( event > 0 )
                         ret = event;
         }
_______________________________________________
Prelude-cvslog site list
[email protected]
http://lists.prelude-technologies.com/mailman/listinfo/prelude-cvslog