]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/message.c
Move bnet_despool() into class in bsock.c
[bacula/bacula] / bacula / src / lib / message.c
old mode 100755 (executable)
new mode 100644 (file)
index dc91de9..9b161a7
@@ -1,15 +1,7 @@
-/*
- * Bacula message handling routines
- *
- *   Kern Sibbald, April 2000
- *
- *   Version $Id$
- *
- */
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
 */
+/*
+ * Bacula message handling routines
+ *
+ *   Kern Sibbald, April 2000
+ *
+ *   Version $Id$
+ *
+ */
 
 
 #include "bacula.h"
@@ -155,11 +155,9 @@ get_db_type(void)
 void
 set_db_type(const char *name)
 {
-   if (catalog_db != NULL)
-   {
+   if (catalog_db != NULL) {
       free(catalog_db);
    }
-
    catalog_db = bstrdup(name);
 }
 
@@ -426,6 +424,7 @@ void close_msg(JCR *jcr)
          case MD_APPEND:
             if (d->fd) {
                fclose(d->fd);            /* close open file descriptor */
+               d->fd = NULL;
             }
             break;
          case MD_MAIL:
@@ -486,6 +485,7 @@ void close_msg(JCR *jcr)
 rem_temp_file:
             /* Remove temp file */
             fclose(d->fd);
+            d->fd = NULL;
             unlink(d->mail_filename);
             free_pool_memory(d->mail_filename);
             d->mail_filename = NULL;
@@ -563,6 +563,10 @@ void term_msg()
       fclose(trace_fd);
       trace_fd = NULL;
    }
+   if (catalog_db) {
+      free(catalog_db);
+      catalog_db = NULL;
+   }
    term_last_jobs_list();
 }
 
@@ -644,7 +648,7 @@ void dispatch_message(JCR *jcr, int type, time_t mtime, char *msg)
                    esc_msg = check_pool_memory_size(esc_msg, len*2+1);
                    p_sql_escape(esc_msg, msg, len);
 
-                   bstrftimes(dt, sizeof(dt), mtime);
+                   bstrutime(dt, sizeof(dt), mtime);
                    Mmsg(cmd, "INSERT INTO Log (JobId, Time, LogText) VALUES (%s,'%s','%s')",
                          edit_int64(jcr->JobId, ed1), dt, esc_msg);
                    p_sql_query(jcr, cmd);
@@ -747,6 +751,7 @@ send_to_file:
                 /* On error, we close and reopen to handle log rotation */
                 if (ferror(d->fd)) {
                    fclose(d->fd);
+                   d->fd = NULL;
                    if (open_dest_file(jcr, d, mode)) {
                       fputs(dt, d->fd);
                       fputs(msg, d->fd);
@@ -765,12 +770,14 @@ send_to_file:
                 if (type != M_ABORT && type != M_ERROR_TERM) { /* already printed */
                    fputs(dt, stdout);
                    fputs(msg, stdout);
+                   fflush(stdout);
                 }
                 break;
              case MD_STDERR:
                 Dmsg1(850, "STDERR for following msg: %s", msg);
                 fputs(dt, stderr);
                 fputs(msg, stderr);
+                fflush(stdout);
                 break;
              default:
                 break;
@@ -860,6 +867,7 @@ d_msg(const char *file, int line, int level, const char *fmt,...)
           }
        } else {   /* not tracing */
           fputs(buf, stdout);
+          fflush(stdout);
        }
     }
 }
@@ -916,6 +924,7 @@ p_msg(const char *file, int line, int level, const char *fmt,...)
     bvsnprintf(buf+len, sizeof(buf)-len, (char *)fmt, arg_ptr);
     va_end(arg_ptr);
     fputs(buf, stdout);
+    fflush(stdout);
 }