]> git.sur5r.net Git - bacula/bacula/commitdiff
Apply get_basename to printed filenames to reduce unnecessarily long paths
authorKern Sibbald <kern@sibbald.com>
Mon, 7 Feb 2011 09:18:07 +0000 (10:18 +0100)
committerKern Sibbald <kern@sibbald.com>
Mon, 7 Feb 2011 09:18:46 +0000 (10:18 +0100)
bacula/src/baconfig.h
bacula/src/lib/message.c
bacula/src/lib/message.h
bacula/src/lib/smartall.c

index cc258f4404fc21d6acd997df625ff9da62c2932e..f9f7807ec1b8e9e1a6c50bddfb9234d38bb93360 100644 (file)
@@ -554,6 +554,9 @@ int getdomainname(char *name, int len);
 
 
 #if defined(HAVE_WIN32)
+/*
+ *   Windows
+ */
 #define DEFAULT_CONFIGDIR "C:\\Documents and Settings\\All Users\\Application Data\\Bacula"
 #define PathSeparator '\\'
 
@@ -565,6 +568,9 @@ extern void pause_msg(const char *file, const char *func, int line, const char *
 #define pause(msg) if (debug_level) pause_msg(__FILE__, __func__, __LINE__, (msg))
 
 #else
+/*
+ *   Unix/Linix
+ */
 #define PathSeparator '/'
 /* Define Winsock functions if we aren't on Windows */
 
index b07b8e7b1fb1a555ba3bdfab87916c5d21d311c1..4e0998abef14498ff0ff454b6ad9bd1c7ae2968b 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2011 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.
@@ -191,7 +191,7 @@ void my_name_is(int argc, char *argv[], const char *name)
       } else {
          l = argv[0];
 #if defined(HAVE_WIN32)
-         /* On Windows allow c: junk */
+         /* On Windows allow c: drive specification */
          if (l[1] == ':') {
             l += 2;
          }
@@ -907,27 +907,26 @@ send_to_file:
 
 /*********************************************************************
  *
- *  This subroutine returns the filename portion of a Windows 
- *  path.  It is used because Microsoft Visual Studio sets __FILE__ 
- *  to the full path.
+ *  This subroutine returns the filename portion of a path.  
+ *  It is used because some compilers set __FILE__ 
+ *  to the full path.  Try to return base + next higher path.
  */
 
-inline const char *
+const char *
 get_basename(const char *pathname)
 {
-#if defined(_MSC_VER)
-   const char *basename;
+   const char *basename, *basename2;
    
-   if ((basename = strrchr(pathname, '\\')) == NULL) {
+   if ((basename = strrchr(pathname, PathSeparator)) == NULL) {
       basename = pathname;
+      if ((basename2 = strrchr(pathname, PathSeparator)) != NULL) {
+         basename = basename2 + 1;
+      }
    } else {
       basename++;
    }
 
    return basename;
-#else
-   return pathname;
-#endif
 }
 
 /*
@@ -1517,7 +1516,7 @@ void q_msg(const char *file, int line, JCR *jcr, int type, utime_t mtime, const
    POOLMEM *pool_buf;
 
    pool_buf = get_pool_memory(PM_EMSG);
-   i = Mmsg(pool_buf, "%s:%d ", file, line);
+   i = Mmsg(pool_buf, "%s:%d ", get_basename(file), line);
 
    for (;;) {
       maxlen = sizeof_pool_memory(pool_buf) - i - 1;
index 57edef9707919af3840a0b0732c4f42259f9cb8d..de7fd4094cc4522d872e20d803f10e39a1ff2af7 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2009 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2011 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.
@@ -145,6 +145,8 @@ void e_msg(const char *file, int line, int type, int level, const char *fmt,...)
 void Jmsg(JCR *jcr, int type, utime_t mtime, const char *fmt,...);
 void Qmsg(JCR *jcr, int type, utime_t mtime, const char *fmt,...);
 bool get_trace(void);
+const char *get_basename(const char *pathname);
+
 
 struct B_DB;
 typedef void (*sql_query_func)(JCR *jcr, const char *cmd);
index db2066d0e57a883a3e7fb4d3d1634a1e7f34f4ca..f5f0be853c8bd17a88dab913af4fa38ec591e626 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2011 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.
@@ -187,7 +187,7 @@ void sm_free(const char *file, int line, void *fp)
    P(mutex);
    Dmsg4(1150, "sm_free %d at %p from %s:%d\n",
          head->ablen, fp,
-         head->abfname, head->ablineno);
+         get_basename(head->abfname), head->ablineno);
 
    if (!head->abin_use) {
       V(mutex);
@@ -214,7 +214,7 @@ void sm_free(const char *file, int line, void *fp)
       V(mutex);
       Dmsg4(0, "Overrun buffer: len=%d addr=%p allocated: %s:%d\n",
          head->ablen, fp,
-         head->abfname, head->ablineno);
+         get_basename(head->abfname), head->ablineno);
       Emsg2(M_ABORT, 0, _("Buffer overrun called from %s:%d\n"), file, line);
    }
    if (sm_buffers > 0) {
@@ -290,7 +290,7 @@ void *sm_realloc(const char *fname, int lineno, void *ptr, unsigned int size)
    void *buf;
    char *cp = (char *) ptr;
 
-   Dmsg4(1400, "sm_realloc %s:%d %p %d\n", fname, (uint32_t)lineno, ptr, size);
+   Dmsg4(1400, "sm_realloc %s:%d %p %d\n", get_basename(fname), (uint32_t)lineno, ptr, size);
    if (size <= 0) {
       e_msg(fname, lineno, M_ABORT, 0, _("sm_realloc size: %d\n"), size);
    }
@@ -330,7 +330,7 @@ void *sm_realloc(const char *fname, int lineno, void *ptr, unsigned int size)
       /* All done.  Free and dechain the original buffer. */
       sm_free(fname, lineno, ptr);
    }
-   Dmsg4(4150, _("sm_realloc %d at %p from %s:%d\n"), size, buf, fname, (uint32_t)lineno);
+   Dmsg4(4150, _("sm_realloc %d at %p from %s:%d\n"), size, buf, get_basename(fname), (uint32_t)lineno);
    return buf;
 }
 
@@ -403,7 +403,7 @@ void sm_dump(bool bufdump, bool in_use)
 
          Pmsg6(0, "%s buffer: %s %d bytes at %p from %s:%d\n", 
             in_use?"In use":"Orphaned",
-            my_name, memsize, cp, ap->abfname, ap->ablineno);
+            my_name, memsize, cp, get_basename(ap->abfname), ap->ablineno);
          if (bufdump) {
             char buf[20];
             unsigned llen = 0;
@@ -436,7 +436,7 @@ void sm_check(const char *fname, int lineno, bool bufdump)
 {
    if (!sm_check_rtn(fname, lineno, bufdump)) {
       Emsg2(M_ABORT, 0, _("Damaged buffer found. Called from %s:%d\n"),
-            fname, (uint32_t)lineno);
+            get_basename(fname), (uint32_t)lineno);
    }
 }
 
@@ -468,7 +468,7 @@ int sm_check_rtn(const char *fname, int lineno, bool bufdump)
       badbuf |= bad;
       if (bad) {
          Pmsg2(0, 
-            _("\nDamaged buffers found at %s:%d\n"), fname, (uint32_t)lineno);
+            _("\nDamaged buffers found at %s:%d\n"), get_basename(fname), (uint32_t)lineno);
 
          if (bad & 0x1) {
             Pmsg0(0,  _("  discovery of bad prev link.\n"));
@@ -494,7 +494,7 @@ int sm_check_rtn(const char *fname, int lineno, bool bufdump)
 
             Pmsg4(0, 
               _("Damaged buffer:  %6u bytes allocated at line %d of %s %s\n"),
-               memsize, ap->ablineno, my_name, ap->abfname
+               memsize, ap->ablineno, my_name, get_basename(ap->abfname)
             );
             if (bufdump) {
                unsigned llen = 0;