]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/message.c
Correct Qmsg() that was not updated correctly when committing a
[bacula/bacula] / bacula / src / lib / message.c
old mode 100755 (executable)
new mode 100644 (file)
index 804a417..e4cef4e
@@ -7,22 +7,42 @@
  *
  */
 /*
-   Copyright (C) 2000-2006 Kern Sibbald
-
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   version 2 as amended with additional clauses defined in the
-   file LICENSE in the main source directory.
-
-   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 
-   the file LICENSE for additional details.
-
+   Bacula® - The Network Backup Solution
+
+   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.
+   This program is Free Software; you can redistribute it and/or
+   modify it under the terms of version two of the GNU General Public
+   License as published by the Free Software Foundation plus additions
+   that are listed in the file LICENSE.
+
+   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.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+   Bacula® is a registered trademark of John Walker.
+   The licensor of Bacula is the Free Software Foundation Europe
+   (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"
 #include "jcr.h"
 
@@ -93,11 +113,11 @@ void my_name_is(int argc, char *argv[], const char *name)
    if (argc>0 && argv && argv[0]) {
       /* strip trailing filename and save exepath */
       for (l=p=argv[0]; *p; p++) {
-         if (*p == '/') {
+         if (IsPathSeparator(*p)) {
             l = p;                       /* set pos of last slash */
          }
       }
-      if (*l == '/') {
+      if (IsPathSeparator(*l)) {
          l++;
       } else {
          l = argv[0];
@@ -123,7 +143,7 @@ void my_name_is(int argc, char *argv[], const char *name)
          *q++ = *p++;
       }
       *q = 0;
-      if (strchr(exepath, '.') || exepath[0] != '/') {
+      if (strchr(exepath, '.') || !IsPathSeparator(exepath[0])) {
          if (getcwd(cpath, sizeof(cpath))) {
             free(exepath);
             exepath = (char *)malloc(strlen(cpath) + 1 + len);
@@ -414,16 +434,23 @@ 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:
          case MD_MAIL_ON_ERROR:
-            Dmsg0(850, "Got MD_MAIL or MD_MAIL_ON_ERROR\n");
+         case MD_MAIL_ON_SUCCESS:
+            Dmsg0(850, "Got MD_MAIL, MD_MAIL_ON_ERROR or MD_MAIL_ON_SUCCESS\n");
             if (!d->fd) {
                break;
             }
-            if (d->dest_code == MD_MAIL_ON_ERROR && jcr &&
-                jcr->JobStatus == JS_Terminated) {
+            if (
+                (d->dest_code == MD_MAIL_ON_ERROR && jcr &&
+                 jcr->JobStatus == JS_Terminated) 
+                ||
+                (d->dest_code == MD_MAIL_ON_SUCCESS && jcr &&
+                 jcr->JobStatus == JS_ErrorTerminated)
+                ){
                goto rem_temp_file;
             }
 
@@ -468,6 +495,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;
@@ -626,7 +654,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);
@@ -689,6 +717,7 @@ void dispatch_message(JCR *jcr, int type, time_t mtime, char *msg)
                 break;
              case MD_MAIL:
              case MD_MAIL_ON_ERROR:
+             case MD_MAIL_ON_SUCCESS:
                 Dmsg1(850, "MAIL for following msg: %s", msg);
                 if (!d->fd) {
                    POOLMEM *name = get_pool_memory(PM_MESSAGE);
@@ -728,6 +757,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);
@@ -746,12 +776,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;
@@ -841,6 +873,7 @@ d_msg(const char *file, int line, int level, const char *fmt,...)
           }
        } else {   /* not tracing */
           fputs(buf, stdout);
+          fflush(stdout);
        }
     }
 }
@@ -897,6 +930,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);
 }