un-do make check since there's no useful content .. fooled by INSTALL!
[debian/amanda] / server-src / logfile.c
index a1517447e8e5b17f0149343e8f655a9f85707039..1f812cdbc8cd1aae2798cae0f35aacbee2934ffc 100644 (file)
@@ -52,7 +52,7 @@ char *logtype_str[] = {
 
 char *program_str[] = {
     "UNKNOWN", "planner", "driver", "amreport", "dumper", "chunker",
-    "taper", "amflush"
+    "taper", "amflush", "amdump", "amidxtaped", "amfetchdump", "amcheckdump"
 };
 
 int curlinenum;
@@ -78,10 +78,22 @@ static void open_log(void);
 static void close_log(void);
 
 void
-logerror(
-    char *     msg)
+amanda_log_trace_log(
+    GLogLevelFlags log_level,
+    const gchar *message)
 {
-    log_add(L_FATAL, "%s", msg);
+    logtype_t logtype = L_ERROR;
+
+    switch (log_level) {
+       case G_LOG_LEVEL_ERROR:
+       case G_LOG_LEVEL_CRITICAL:
+           logtype = L_FATAL;
+           break;
+
+       default:
+           return;
+    }
+    log_add(logtype, "%s", message);
 }
 
 
@@ -112,12 +124,15 @@ printf_arglist_function2(char *log_genstring, logtype_t, typ, char *, pname, cha
 printf_arglist_function1(void log_add, logtype_t, typ, char *, format)
 {
     va_list argp;
-    int saved_errout;
     char *leader = NULL;
     char *xlated_fmt = gettext(format);
     char linebuf[STR_SIZE];
     size_t n;
+    static gboolean in_log_add = 0;
 
+    /* avoid recursion */
+    if (in_log_add)
+       return;
 
     /* format error message */
 
@@ -130,31 +145,32 @@ printf_arglist_function1(void log_add, logtype_t, typ, char *, format)
     }
 
     arglist_start(argp, format);
-    g_vsnprintf(linebuf, SIZEOF(linebuf)-1, xlated_fmt, argp);
+    /* use sizeof(linebuf)-2 to save space for a trailing newline */
+    g_vsnprintf(linebuf, SIZEOF(linebuf)-2, xlated_fmt, argp);
                                                /* -1 to allow for '\n' */
     arglist_end(argp);
 
     /* avoid recursive call from error() */
 
-    saved_errout = erroutput_type;
-    erroutput_type &= ~ERR_AMANDALOG;
+    in_log_add = 1;
 
     /* append message to the log file */
 
     if(multiline == -1) open_log();
 
-    if (fullwrite(logfd, leader, strlen(leader)) < 0) {
+    if (full_write(logfd, leader, strlen(leader)) < strlen(leader)) {
        error(_("log file write error: %s"), strerror(errno));
        /*NOTREACHED*/
     }
 
     amfree(leader);
 
+    /* add a newline if necessary */
     n = strlen(linebuf);
     if(n == 0 || linebuf[n-1] != '\n') linebuf[n++] = '\n';
     linebuf[n] = '\0';
 
-    if (fullwrite(logfd, linebuf, n) < 0) {
+    if (full_write(logfd, linebuf, n) < n) {
        error(_("log file write error: %s"), strerror(errno));
        /*NOTREACHED*/
     }
@@ -162,7 +178,7 @@ printf_arglist_function1(void log_add, logtype_t, typ, char *, format)
     if(multiline != -1) multiline++;
     else close_log();
 
-    erroutput_type = saved_errout;
+    in_log_add = 0;
 }
 
 void
@@ -227,11 +243,6 @@ open_log(void)
 {
     char *conf_logdir;
 
-    /* now that we have a logfile, let the debug module know how to write
-     * error messages to it.  This is due to some rather obscure linking 
-     * problems. */
-    set_logerror(logerror);
-
     conf_logdir = config_dir_relative(getconf_str(CNF_LOGDIR));
     logfile = vstralloc(conf_logdir, "/log", NULL);
     amfree(conf_logdir);