]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/message.c
Strip pathname portion off all message routines that print filename:line.
[bacula/bacula] / bacula / src / lib / message.c
index bac2f479da39e9a7b546f2f34098ad8661fc1d1c..44070a79e5837486f0853d2b666b891ffe0ec6f4 100755 (executable)
@@ -26,6 +26,8 @@
 #include "bacula.h"
 #include "jcr.h"
 
+sql_query p_sql_query = NULL;
+
 #define FULL_LOCATION 1               /* set for file:line in Debug messages */
 
 /*
@@ -60,7 +62,7 @@ const char *host_os = HOST_OS;
 const char *distname = DISTNAME;
 const char *distver = DISTVER;
 static FILE *trace_fd = NULL;
-#ifdef HAVE_WIN32
+#if defined(HAVE_WIN32)
 static bool trace = true;
 #else
 static bool trace = false;
@@ -152,15 +154,12 @@ void
 init_msg(JCR *jcr, MSGS *msg)
 {
    DEST *d, *dnew, *temp_chain = NULL;
-#ifndef HAVE_WIN32
-   int i;
-#endif
 
    if (jcr == NULL && msg == NULL) {
       init_last_jobs_list();
    }
 
-#ifndef HAVE_WIN32
+#if !defined(HAVE_WIN32)
    /*
     * Make sure we have fd's 0, 1, 2 open
     *  If we don't do this one of our sockets may open
@@ -169,6 +168,7 @@ init_msg(JCR *jcr, MSGS *msg)
     *
     */
    int fd;
+   int i;
    fd = open("/dev/null", O_RDONLY, 0644);
    if (fd > 2) {
       close(fd);
@@ -185,7 +185,7 @@ init_msg(JCR *jcr, MSGS *msg)
    if (msg == NULL) {
       daemon_msgs = (MSGS *)malloc(sizeof(MSGS));
       memset(daemon_msgs, 0, sizeof(MSGS));
-#ifndef HAVE_WIN32
+#if !defined(HAVE_WIN32)
       for (i=1; i<=M_MAX; i++) {
          add_msg_dest(daemon_msgs, MD_STDOUT, i, NULL, NULL);
       }
@@ -577,7 +577,7 @@ void dispatch_message(JCR *jcr, int type, time_t mtime, char *msg)
     }
 
     if (type == M_ABORT || type == M_ERROR_TERM) {
-#ifndef HAVE_WIN32
+#if !defined(HAVE_WIN32)
        fputs(dt, stdout);
        fputs(msg, stdout);         /* print this here to INSURE that it is printed */
        fflush(stdout);
@@ -595,6 +595,19 @@ void dispatch_message(JCR *jcr, int type, time_t mtime, char *msg)
     for (d=msgs->dest_chain; d; d=d->next) {
        if (bit_is_set(type, d->msg_types)) {
           switch (d->dest_code) {
+             case MD_CATALOG:
+                char ed1[50];
+                if (!jcr || !jcr->db) {
+                   break;
+                }
+                if (p_sql_query) {
+                   POOL_MEM cmd(PM_MESSAGE);
+                   bstrftimes(dt, sizeof(dt), mtime);
+                   Mmsg(cmd, "INSERT INTO Log (JobId, Time, LogText) VALUES (%s,'%s','%s')",
+                         edit_int64(jcr->JobId, ed1), dt, msg);
+                   p_sql_query(jcr, cmd.c_str());
+                }
+                break;
              case MD_CONSOLE:
                 Dmsg1(850, "CONSOLE for following msg: %s", msg);
                 if (!con_fd) {
@@ -760,9 +773,14 @@ d_msg(const char *file, int line, int level, const char *fmt,...)
           /* visual studio passes the whole path to the file as well
            * which makes for very long lines
            */
-          const char *f = strrchr(file, '\\');
-          if (f) file = f + 1;
-          len = bsnprintf(buf, sizeof(buf), "%s: %s:%d ", my_name, file, line);
+          const char *basename;
+
+          if ((basename = strrchr(file, '\\')) == NULL) {
+             basename = file;
+          } else {
+             basename++;
+          }
+          len = bsnprintf(buf, sizeof(buf), "%s: %s:%d ", my_name, basename, line);
        } else {
           len = 0;
        }
@@ -837,7 +855,14 @@ p_msg(const char *file, int line, int level, const char *fmt,...)
 
 #ifdef FULL_LOCATION
     if (level >= 0) {
-       len = bsnprintf(buf, sizeof(buf), "%s: %s:%d ", my_name, file, line);
+       const char *basename;
+
+       if ((basename = strrchr(file, '\\')) == NULL) {
+          basename = file;
+       } else {
+          basename++;
+       }
+       len = bsnprintf(buf, sizeof(buf), "%s: %s:%d ", my_name, basename, line);
     } else {
        len = 0;
     }
@@ -882,7 +907,14 @@ t_msg(const char *file, int line, int level, const char *fmt,...)
 
 #ifdef FULL_LOCATION
        if (details) {
-          len = bsnprintf(buf, sizeof(buf), "%s: %s:%d ", my_name, file, line);
+          const char *basename;
+
+          if ((basename = strrchr(file, '\\')) == NULL) {
+             basename = file;
+          } else {
+             basename++;
+          }
+          len = bsnprintf(buf, sizeof(buf), "%s: %s:%d ", my_name, basename, line);
        } else {
           len = 0;
        }
@@ -913,6 +945,14 @@ e_msg(const char *file, int line, int type, int level, const char *fmt,...)
     va_list   arg_ptr;
     int len;
 
+    const char *basename;
+
+    if ((basename = strrchr(file, '\\')) == NULL) {
+       basename = file;
+    } else {
+       basename++;
+    }
+
     /*
      * Check if we have a message destination defined.
      * We always report M_ABORT and M_ERROR_TERM
@@ -924,23 +964,23 @@ e_msg(const char *file, int line, int type, int level, const char *fmt,...)
     switch (type) {
     case M_ABORT:
        len = bsnprintf(buf, sizeof(buf), _("%s: ABORTING due to ERROR in %s:%d\n"),
-               my_name, file, line);
+               my_name, basename, line);
        break;
     case M_ERROR_TERM:
        len = bsnprintf(buf, sizeof(buf), _("%s: ERROR TERMINATION at %s:%d\n"),
-               my_name, file, line);
+               my_name, basename, line);
        break;
     case M_FATAL:
        if (level == -1)            /* skip details */
           len = bsnprintf(buf, sizeof(buf), _("%s: Fatal Error because: "), my_name);
        else
-          len = bsnprintf(buf, sizeof(buf), _("%s: Fatal Error at %s:%d because:\n"), my_name, file, line);
+          len = bsnprintf(buf, sizeof(buf), _("%s: Fatal Error at %s:%d because:\n"), my_name, basename, line);
        break;
     case M_ERROR:
        if (level == -1)            /* skip details */
           len = bsnprintf(buf, sizeof(buf), _("%s: ERROR: "), my_name);
        else
-          len = bsnprintf(buf, sizeof(buf), _("%s: ERROR in %s:%d "), my_name, file, line);
+          len = bsnprintf(buf, sizeof(buf), _("%s: ERROR in %s:%d "), my_name, basename, line);
        break;
     case M_WARNING:
        len = bsnprintf(buf, sizeof(buf), _("%s: Warning: "), my_name);
@@ -1074,9 +1114,16 @@ void j_msg(const char *file, int line, JCR *jcr, int type, time_t mtime, const c
    va_list   arg_ptr;
    int i, len, maxlen;
    POOLMEM *pool_buf;
+   const char *basename;
+
+   if ((basename = strrchr(file, '\\')) == NULL) {
+      basename = file;
+   } else {
+      basename++;
+   }
 
    pool_buf = get_pool_memory(PM_EMSG);
-   i = Mmsg(pool_buf, "%s:%d ", file, line);
+   i = Mmsg(pool_buf, "%s:%d ", basename, line);
 
    for (;;) {
       maxlen = sizeof_pool_memory(pool_buf) - i - 1;
@@ -1103,7 +1150,15 @@ int m_msg(const char *file, int line, POOLMEM **pool_buf, const char *fmt, ...)
    va_list   arg_ptr;
    int i, len, maxlen;
 
-   i = sprintf(*pool_buf, "%s:%d ", file, line);
+   const char *basename;
+
+   if ((basename = strrchr(file, '\\')) == NULL) {
+      basename = file;
+   } else {
+      basename++;
+   }
+
+   i = sprintf(*pool_buf, "%s:%d ", basename, line);
 
    for (;;) {
       maxlen = sizeof_pool_memory(*pool_buf) - i - 1;
@@ -1124,7 +1179,15 @@ int m_msg(const char *file, int line, POOLMEM *&pool_buf, const char *fmt, ...)
    va_list   arg_ptr;
    int i, len, maxlen;
 
-   i = sprintf(pool_buf, "%s:%d ", file, line);
+   const char *basename;
+
+   if ((basename = strrchr(file, '\\')) == NULL) {
+      basename = file;
+   } else {
+      basename++;
+   }
+
+   i = sprintf(pool_buf, "%s:%d ", basename, line);
 
    for (;;) {
       maxlen = sizeof_pool_memory(pool_buf) - i - 1;