[syslog-ng] syslog_ng and NFS

Balazs Scheidler bazsi at balabit.hu
Mon Jun 9 11:43:15 CEST 2008


On Fri, 2008-05-30 at 16:19 -0700, Chris Wagner wrote:
> lseek before write will work as long as:
> 
>      1. syslog-ng isn’t multi-threaded
>      2. there aren’t multiple syslog-ng’s running on the same server
>         pointing at the same file
> 
> I tested that out (turning off APPEND and adding an lseek). NFS
> performance still great. I modified my conf to point all log messages
> to a single file (well configured multiple destinations to point to
> the same file) and things seemed to work fine over NFS – no mangling
> of messages. So with limited testing – seems to be a good solution.


I've pushed this patch to the 2.1 OSE branch, please check if it works
for you.

diff --git a/src/affile.c b/src/affile.c
index 77c23bf..1ed9bd0 100644
--- a/src/affile.c
+++ b/src/affile.c
@@ -330,7 +330,7 @@ affile_dw_init(LogPipe *s, GlobalConfig *cfg, PersistentConfig *persist)
   if (self->owner->flags & AFFILE_PIPE)
     flags = O_RDWR | O_NOCTTY | O_NONBLOCK | O_LARGEFILE;
   else
-    flags = O_WRONLY | O_CREAT | O_APPEND | O_NOCTTY | O_NONBLOCK | O_LARGEFILE;
+    flags = O_WRONLY | O_CREAT | O_NOCTTY | O_NONBLOCK | O_LARGEFILE;
 
   self->last_open_stamp = time(NULL);
   if (affile_open_file(self->filename->str, flags, 
@@ -357,6 +357,7 @@ affile_dw_init(LogPipe *s, GlobalConfig *cfg, PersistentConfig *persist)
       fdw = fd_write_new(fd);
       if (self->owner->flags & AFFILE_FSYNC)
         fdw->fsync = TRUE;
+      fdw->append = TRUE;
       log_writer_reopen(self->writer, fdw);
     }
   else
diff --git a/src/fdwrite.c b/src/fdwrite.c
index e668ddb..5597f12 100644
--- a/src/fdwrite.c
+++ b/src/fdwrite.c
@@ -38,6 +38,8 @@ fd_write_write_method(FDWrite *self, const void *buf, size_t buflen)
     {
       if (self->timeout)
         alarm_set(self->timeout);
+      if (self->append)
+        lseek(self->fd, 0, SEEK_END);
       rc = write(self->fd, buf, buflen);
       if (self->timeout > 0 && rc == -1 && errno == EINTR && alarm_has_fired())
         {
diff --git a/src/fdwrite.h b/src/fdwrite.h
index c8ba5c8..7a13ec3 100644
--- a/src/fdwrite.h
+++ b/src/fdwrite.h
@@ -33,7 +33,8 @@ struct _FDWrite
 {
   gint fd;
   GIOCondition cond;
-  gboolean fsync;
+  gboolean fsync:1,
+           append:1;
   gint timeout;
   size_t (*write)(FDWrite *self, const void *buf, size_t count);
   void (*free_fn)(FDWrite *self);


-- 
Bazsi



More information about the syslog-ng mailing list