aboutsummaryrefslogtreecommitdiffstats
path: root/src/log.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/log.c')
-rw-r--r--src/log.c87
1 files changed, 78 insertions, 9 deletions
diff --git a/src/log.c b/src/log.c
index c117779..b8b2186 100644
--- a/src/log.c
+++ b/src/log.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.12 2008/03/10 11:49:33 james
+ * *** empty log message ***
+ *
* Revision 1.11 2008/03/07 13:16:02 james
* *** empty log message ***
*
@@ -47,8 +50,7 @@ static char rcsid[] = "$Id$";
#include "project.h"
-typedef struct
-{
+typedef struct {
LOG_SIGNATURE;
int do_close;
int rotate;
@@ -56,6 +58,69 @@ typedef struct
char *filename;
} File_Log;
+
+static Log *loggers = NULL;
+
+
+static void
+sighup (int dummy)
+{
+ Log *l;
+
+ for (l = loggers; l; l = l->next) {
+ if (l->sighup)
+ l->sighup (l);
+ }
+}
+
+
+void
+log_register_handlers (void)
+{
+ struct sigaction sa = { 0 };
+
+ sa.sa_handler = sighup;
+ sa.sa_flags = SA_RESTART;
+ sigaction (SIGHUP, &sa, NULL);
+}
+
+
+void
+log_add (Log * l)
+{
+ log_register_handlers ();
+
+ l->next = loggers;
+ loggers = l;
+}
+
+void
+log_remove (Log * l)
+{
+ Log **ptr = &loggers;
+
+ /* Take out of cleanup list */
+ while (*ptr && (*ptr != l))
+ ptr = &((*ptr)->next);
+
+ if (*ptr)
+ *ptr = l->next;
+}
+
+
+static void
+flog_sighup (Log * _l)
+{
+ File_Log *l = (File_Log *) _l;
+ if (!l->fp)
+ return;
+
+ fclose (l->fp);
+
+ l->fp = fopen (l->filename, "a+");
+}
+
+
static void
flog_log (Log * _l, char *buf)
{
@@ -110,28 +175,32 @@ Log *
file_log_new (char *fn, int rotate)
{
File_Log *l;
- FILE *f;
int dc = 1;
+ l = xmalloc (sizeof (File_Log));
+
if (fn && strcmp (fn, "-")) {
- f = fopen (fn, "a+");
- if (!f)
+ l->fp = fopen (fn, "a+");
+ if (!l->fp) {
+ free (l);
return NULL;
+ }
+ l->sighup = flog_sighup;
} else {
- f = stderr;
+ l->fp = stderr;
dc = 0;
}
- l = xmalloc (sizeof (File_Log));
l->log = flog_log;
l->close = flog_close;
- l->fp = f;
l->do_close = dc;
l->rotate = rotate;
l->filename = strdup (fn);
- fput_cp (f, 0xffef);
+ fput_cp (l->fp, 0xffef);
+
+ log_add ((Log *) l);
return (Log *) l;
}