bug-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] move client logging to log-buffer.[ch]


From: Alexey Mahotkin
Subject: [PATCH] move client logging to log-buffer.[ch]
Date: Thu, 24 Apr 2003 23:08:53 +0400
User-agent: Gnus/5.090006 (Oort Gnus v0.06) XEmacs/21.4 (Common Lisp, i386-debian-linux)


2003-04-24  Alexey Mahotkin <address@hidden>

Move logging buffer code to separate log-buffer.[ch]


 src/Makefile.am  |    1 
 src/Makefile.in  |   56 +++++++++--------
 src/client.c     |  157 -------------------------------------------------
 src/log-buffer.c |  173 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/log-buffer.h |   20 ++++++
 5 files changed, 224 insertions(+), 183 deletions(-)

--- ccvs/src/client.c~log-buffer        Thu Apr 24 23:03:50 2003
+++ ccvs-alexm/src/client.c     Thu Apr 24 23:05:12 2003
@@ -21,6 +21,7 @@
 #include "getline.h"
 #include "edit.h"
 #include "buffer.h"
+#include "log-buffer.h"
 
 #ifdef CLIENT_SUPPORT
 
@@ -406,162 +407,6 @@ static struct buffer *to_server;
 static struct buffer *from_server;
 
 
-/* We want to be able to log data sent between us and the server.  We
-   do it using log buffers.  Each log buffer has another buffer which
-   handles the actual I/O, and a file to log information to.
-
-   This structure is the closure field of a log buffer.  */
-
-struct log_buffer
-{
-    /* The underlying buffer.  */
-    struct buffer *buf;
-    /* The file to log information to.  */
-    FILE *log;
-};
-
-static struct buffer *log_buffer_initialize
-  PROTO((struct buffer *, FILE *, int, void (*) (struct buffer *)));
-static int log_buffer_input PROTO((void *, char *, int, int, int *));
-static int log_buffer_output PROTO((void *, const char *, int, int *));
-static int log_buffer_flush PROTO((void *));
-static int log_buffer_block PROTO((void *, int));
-static int log_buffer_shutdown PROTO((struct buffer *));
-
-/* Create a log buffer.  */
-
-static struct buffer *
-log_buffer_initialize (buf, fp, input, memory)
-     struct buffer *buf;
-     FILE *fp;
-     int input;
-     void (*memory) PROTO((struct buffer *));
-{
-    struct log_buffer *n;
-
-    n = (struct log_buffer *) xmalloc (sizeof *n);
-    n->buf = buf;
-    n->log = fp;
-    return buf_initialize (input ? log_buffer_input : NULL,
-                          input ? NULL : log_buffer_output,
-                          input ? NULL : log_buffer_flush,
-                          log_buffer_block,
-                          log_buffer_shutdown,
-                          memory,
-                          n);
-}
-
-/* The input function for a log buffer.  */
-
-static int
-log_buffer_input (closure, data, need, size, got)
-     void *closure;
-     char *data;
-     int need;
-     int size;
-     int *got;
-{
-    struct log_buffer *lb = (struct log_buffer *) closure;
-    int status;
-    size_t n_to_write;
-
-    if (lb->buf->input == NULL)
-       abort ();
-
-    status = (*lb->buf->input) (lb->buf->closure, data, need, size, got);
-    if (status != 0)
-       return status;
-
-    if (*got > 0)
-    {
-       n_to_write = *got;
-       if (fwrite (data, 1, n_to_write, lb->log) != n_to_write)
-           error (0, errno, "writing to log file");
-    }
-
-    return 0;
-}
-
-/* The output function for a log buffer.  */
-
-static int
-log_buffer_output (closure, data, have, wrote)
-     void *closure;
-     const char *data;
-     int have;
-     int *wrote;
-{
-    struct log_buffer *lb = (struct log_buffer *) closure;
-    int status;
-    size_t n_to_write;
-
-    if (lb->buf->output == NULL)
-       abort ();
-
-    status = (*lb->buf->output) (lb->buf->closure, data, have, wrote);
-    if (status != 0)
-       return status;
-
-    if (*wrote > 0)
-    {
-       n_to_write = *wrote;
-       if (fwrite (data, 1, n_to_write, lb->log) != n_to_write)
-           error (0, errno, "writing to log file");
-    }
-
-    return 0;
-}
-
-/* The flush function for a log buffer.  */
-
-static int
-log_buffer_flush (closure)
-     void *closure;
-{
-    struct log_buffer *lb = (struct log_buffer *) closure;
-
-    if (lb->buf->flush == NULL)
-       abort ();
-
-    /* We don't really have to flush the log file here, but doing it
-       will let tail -f on the log file show what is sent to the
-       network as it is sent.  */
-    if (fflush (lb->log) != 0)
-        error (0, errno, "flushing log file");
-
-    return (*lb->buf->flush) (lb->buf->closure);
-}
-
-/* The block function for a log buffer.  */
-
-static int
-log_buffer_block (closure, block)
-     void *closure;
-     int block;
-{
-    struct log_buffer *lb = (struct log_buffer *) closure;
-
-    if (block)
-       return set_block (lb->buf);
-    else
-       return set_nonblock (lb->buf);
-}
-
-/* The shutdown function for a log buffer.  */
-
-static int
-log_buffer_shutdown (buf)
-     struct buffer *buf;
-{
-    struct log_buffer *lb = (struct log_buffer *) buf->closure;
-    int retval;
-
-    retval = buf_shutdown (lb->buf);
-    if (fclose (lb->log) < 0)
-       error (0, errno, "closing log file");
-    return retval;
-}
-
 /*
  * Read a line from the server.  Result does not include the terminating \n.
  *
--- /dev/null   Wed Jan  1 02:48:46 2003
+++ ccvs-alexm/src/log-buffer.c Thu Apr 24 23:03:50 2003
@@ -0,0 +1,173 @@
+/* CVS client logging buffer.
+
+   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 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 General Public License for more details.  */
+
+#include <config.h>
+
+#include <stdio.h>
+
+#include "cvs.h"
+#include "buffer.h"
+
+/* We want to be able to log data sent between us and the server.  We
+   do it using log buffers.  Each log buffer has another buffer which
+   handles the actual I/O, and a file to log information to.
+
+   This structure is the closure field of a log buffer.  */
+
+struct log_buffer
+{
+    /* The underlying buffer.  */
+    struct buffer *buf;
+    /* The file to log information to.  */
+    FILE *log;
+};
+
+static int log_buffer_input PROTO((void *, char *, int, int, int *));
+static int log_buffer_output PROTO((void *, const char *, int, int *));
+static int log_buffer_flush PROTO((void *));
+static int log_buffer_block PROTO((void *, int));
+static int log_buffer_shutdown PROTO((struct buffer *));
+
+/* Create a log buffer.  */
+
+struct buffer *
+log_buffer_initialize (buf, fp, input, memory)
+     struct buffer *buf;
+     FILE *fp;
+     int input;
+     void (*memory) PROTO((struct buffer *));
+{
+    struct log_buffer *n;
+
+    n = (struct log_buffer *) xmalloc (sizeof *n);
+    n->buf = buf;
+    n->log = fp;
+    return buf_initialize (input ? log_buffer_input : NULL,
+                          input ? NULL : log_buffer_output,
+                          input ? NULL : log_buffer_flush,
+                          log_buffer_block,
+                          log_buffer_shutdown,
+                          memory,
+                          n);
+}
+
+/* The input function for a log buffer.  */
+
+static int
+log_buffer_input (closure, data, need, size, got)
+     void *closure;
+     char *data;
+     int need;
+     int size;
+     int *got;
+{
+    struct log_buffer *lb = (struct log_buffer *) closure;
+    int status;
+    size_t n_to_write;
+
+    if (lb->buf->input == NULL)
+       abort ();
+
+    status = (*lb->buf->input) (lb->buf->closure, data, need, size, got);
+    if (status != 0)
+       return status;
+
+    if (*got > 0)
+    {
+       n_to_write = *got;
+       if (fwrite (data, 1, n_to_write, lb->log) != n_to_write)
+           error (0, errno, "writing to log file");
+    }
+
+    return 0;
+}
+
+/* The output function for a log buffer.  */
+
+static int
+log_buffer_output (closure, data, have, wrote)
+     void *closure;
+     const char *data;
+     int have;
+     int *wrote;
+{
+    struct log_buffer *lb = (struct log_buffer *) closure;
+    int status;
+    size_t n_to_write;
+
+    if (lb->buf->output == NULL)
+       abort ();
+
+    status = (*lb->buf->output) (lb->buf->closure, data, have, wrote);
+    if (status != 0)
+       return status;
+
+    if (*wrote > 0)
+    {
+       n_to_write = *wrote;
+       if (fwrite (data, 1, n_to_write, lb->log) != n_to_write)
+           error (0, errno, "writing to log file");
+    }
+
+    return 0;
+}
+
+/* The flush function for a log buffer.  */
+
+static int
+log_buffer_flush (closure)
+     void *closure;
+{
+    struct log_buffer *lb = (struct log_buffer *) closure;
+
+    if (lb->buf->flush == NULL)
+       abort ();
+
+    /* We don't really have to flush the log file here, but doing it
+       will let tail -f on the log file show what is sent to the
+       network as it is sent.  */
+    if (fflush (lb->log) != 0)
+        error (0, errno, "flushing log file");
+
+    return (*lb->buf->flush) (lb->buf->closure);
+}
+
+/* The block function for a log buffer.  */
+
+static int
+log_buffer_block (closure, block)
+     void *closure;
+     int block;
+{
+    struct log_buffer *lb = (struct log_buffer *) closure;
+
+    if (block)
+       return set_block (lb->buf);
+    else
+       return set_nonblock (lb->buf);
+}
+
+/* The shutdown function for a log buffer.  */
+
+static int
+log_buffer_shutdown (buf)
+     struct buffer *buf;
+{
+    struct log_buffer *lb = (struct log_buffer *) buf->closure;
+    int retval;
+
+    retval = buf_shutdown (lb->buf);
+    if (fclose (lb->log) < 0)
+       error (0, errno, "closing log file");
+    return retval;
+}
+
--- /dev/null   Wed Jan  1 02:48:46 2003
+++ ccvs-alexm/src/log-buffer.h Thu Apr 24 23:03:50 2003
@@ -0,0 +1,20 @@
+/* CVS client logging buffer.
+
+   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 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 General Public License for more details.  */
+
+
+#ifndef LOG_BUFFER_H__
+#define LOG_BUFFER_H__
+
+struct buffer *log_buffer_initialize
+  PROTO((struct buffer *, FILE *, int, void (*) (struct buffer *)));
+
+#endif LOG_BUFFER_H__
--- ccvs/src/Makefile.am~log-buffer     Thu Apr 24 23:03:50 2003
+++ ccvs-alexm/src/Makefile.am  Thu Apr 24 23:06:52 2003
@@ -54,6 +54,7 @@ cvs_SOURCES = \
        import.c \
        lock.c \
        log.c \
+       log-buffer.c log-buffer.h \
        login.c \
        logmsg.c \
        main.c \
--- ccvs/src/Makefile.in~log-buffer     Thu Apr 24 23:03:50 2003
+++ ccvs-alexm/src/Makefile.in  Thu Apr 24 23:06:56 2003
@@ -146,6 +146,7 @@ cvs_SOURCES = \
        import.c \
        lock.c \
        log.c \
+       log-buffer.c log-buffer.h \
        login.c \
        logmsg.c \
        main.c \
@@ -226,17 +227,17 @@ am_cvs_OBJECTS = add.$(OBJEXT) admin.$(O
        expand_path.$(OBJEXT) fileattr.$(OBJEXT) filesubr.$(OBJEXT) \
        find_names.$(OBJEXT) hardlink.$(OBJEXT) hash.$(OBJEXT) \
        history.$(OBJEXT) ignore.$(OBJEXT) import.$(OBJEXT) \
-       lock.$(OBJEXT) log.$(OBJEXT) login.$(OBJEXT) logmsg.$(OBJEXT) \
-       main.$(OBJEXT) mkmodules.$(OBJEXT) modules.$(OBJEXT) \
-       myndbm.$(OBJEXT) no_diff.$(OBJEXT) parseinfo.$(OBJEXT) \
-       patch.$(OBJEXT) rcs.$(OBJEXT) rcscmds.$(OBJEXT) \
-       recurse.$(OBJEXT) release.$(OBJEXT) remove.$(OBJEXT) \
-       repos.$(OBJEXT) root.$(OBJEXT) rsh-client.$(OBJEXT) \
-       run.$(OBJEXT) scramble.$(OBJEXT) server.$(OBJEXT) \
-       socket-client.$(OBJEXT) status.$(OBJEXT) subr.$(OBJEXT) \
-       tag.$(OBJEXT) update.$(OBJEXT) version.$(OBJEXT) \
-       vers_ts.$(OBJEXT) watch.$(OBJEXT) wrapper.$(OBJEXT) \
-       zlib.$(OBJEXT)
+       lock.$(OBJEXT) log.$(OBJEXT) log-buffer.$(OBJEXT) \
+       login.$(OBJEXT) logmsg.$(OBJEXT) main.$(OBJEXT) \
+       mkmodules.$(OBJEXT) modules.$(OBJEXT) myndbm.$(OBJEXT) \
+       no_diff.$(OBJEXT) parseinfo.$(OBJEXT) patch.$(OBJEXT) \
+       rcs.$(OBJEXT) rcscmds.$(OBJEXT) recurse.$(OBJEXT) \
+       release.$(OBJEXT) remove.$(OBJEXT) repos.$(OBJEXT) \
+       root.$(OBJEXT) rsh-client.$(OBJEXT) run.$(OBJEXT) \
+       scramble.$(OBJEXT) server.$(OBJEXT) socket-client.$(OBJEXT) \
+       status.$(OBJEXT) subr.$(OBJEXT) tag.$(OBJEXT) update.$(OBJEXT) \
+       version.$(OBJEXT) vers_ts.$(OBJEXT) watch.$(OBJEXT) \
+       wrapper.$(OBJEXT) zlib.$(OBJEXT)
 cvs_OBJECTS = $(am_cvs_OBJECTS)
 cvs_LDFLAGS =
 SCRIPTS = $(bin_SCRIPTS)
@@ -263,22 +264,22 @@ am__depfiles_maybe = depfiles
 @AMDEP_TRUE@   ./$(DEPDIR)/hardlink.Po ./$(DEPDIR)/hash.Po \
 @AMDEP_TRUE@   ./$(DEPDIR)/history.Po ./$(DEPDIR)/ignore.Po \
 @AMDEP_TRUE@   ./$(DEPDIR)/import.Po ./$(DEPDIR)/lock.Po \
address@hidden@ ./$(DEPDIR)/log.Po ./$(DEPDIR)/login.Po \
address@hidden@ ./$(DEPDIR)/logmsg.Po ./$(DEPDIR)/main.Po \
address@hidden@ ./$(DEPDIR)/mkmodules.Po ./$(DEPDIR)/modules.Po \
address@hidden@ ./$(DEPDIR)/myndbm.Po ./$(DEPDIR)/no_diff.Po \
address@hidden@ ./$(DEPDIR)/parseinfo.Po ./$(DEPDIR)/patch.Po \
address@hidden@ ./$(DEPDIR)/rcs.Po ./$(DEPDIR)/rcscmds.Po \
address@hidden@ ./$(DEPDIR)/recurse.Po ./$(DEPDIR)/release.Po \
address@hidden@ ./$(DEPDIR)/remove.Po ./$(DEPDIR)/repos.Po \
address@hidden@ ./$(DEPDIR)/root.Po ./$(DEPDIR)/rsh-client.Po \
address@hidden@ ./$(DEPDIR)/run.Po ./$(DEPDIR)/scramble.Po \
address@hidden@ ./$(DEPDIR)/server.Po ./$(DEPDIR)/socket-client.Po \
address@hidden@ ./$(DEPDIR)/status.Po ./$(DEPDIR)/subr.Po \
address@hidden@ ./$(DEPDIR)/tag.Po ./$(DEPDIR)/update.Po \
address@hidden@ ./$(DEPDIR)/vers_ts.Po ./$(DEPDIR)/version.Po \
address@hidden@ ./$(DEPDIR)/watch.Po ./$(DEPDIR)/wrapper.Po \
address@hidden@ ./$(DEPDIR)/zlib.Po
address@hidden@ ./$(DEPDIR)/log-buffer.Po ./$(DEPDIR)/log.Po \
address@hidden@ ./$(DEPDIR)/login.Po ./$(DEPDIR)/logmsg.Po \
address@hidden@ ./$(DEPDIR)/main.Po ./$(DEPDIR)/mkmodules.Po \
address@hidden@ ./$(DEPDIR)/modules.Po ./$(DEPDIR)/myndbm.Po \
address@hidden@ ./$(DEPDIR)/no_diff.Po ./$(DEPDIR)/parseinfo.Po \
address@hidden@ ./$(DEPDIR)/patch.Po ./$(DEPDIR)/rcs.Po \
address@hidden@ ./$(DEPDIR)/rcscmds.Po ./$(DEPDIR)/recurse.Po \
address@hidden@ ./$(DEPDIR)/release.Po ./$(DEPDIR)/remove.Po \
address@hidden@ ./$(DEPDIR)/repos.Po ./$(DEPDIR)/root.Po \
address@hidden@ ./$(DEPDIR)/rsh-client.Po ./$(DEPDIR)/run.Po \
address@hidden@ ./$(DEPDIR)/scramble.Po ./$(DEPDIR)/server.Po \
address@hidden@ ./$(DEPDIR)/socket-client.Po ./$(DEPDIR)/status.Po \
address@hidden@ ./$(DEPDIR)/subr.Po ./$(DEPDIR)/tag.Po \
address@hidden@ ./$(DEPDIR)/update.Po ./$(DEPDIR)/vers_ts.Po \
address@hidden@ ./$(DEPDIR)/version.Po ./$(DEPDIR)/watch.Po \
address@hidden@ ./$(DEPDIR)/wrapper.Po ./$(DEPDIR)/zlib.Po
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
        $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 CCLD = $(CC)
@@ -382,6 +383,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
 @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
 @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
address@hidden@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
 @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
 @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@
 @AMDEP_TRUE@@am__include@ @address@hidden/$(DEPDIR)/address@hidden@

_


--alexm




reply via email to

[Prev in Thread] Current Thread [Next in Thread]