From: Kern Sibbald Date: Mon, 7 Feb 2011 09:18:07 +0000 (+0100) Subject: Apply get_basename to printed filenames to reduce unnecessarily long paths X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=468ab65cf5377005a15bb493335e9310a500414e;p=bacula%2Fbacula Apply get_basename to printed filenames to reduce unnecessarily long paths --- diff --git a/bacula/src/baconfig.h b/bacula/src/baconfig.h index cc258f4404..f9f7807ec1 100644 --- a/bacula/src/baconfig.h +++ b/bacula/src/baconfig.h @@ -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 */ diff --git a/bacula/src/lib/message.c b/bacula/src/lib/message.c index b07b8e7b1f..4e0998abef 100644 --- a/bacula/src/lib/message.c +++ b/bacula/src/lib/message.c @@ -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; diff --git a/bacula/src/lib/message.h b/bacula/src/lib/message.h index 57edef9707..de7fd4094c 100644 --- a/bacula/src/lib/message.h +++ b/bacula/src/lib/message.h @@ -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); diff --git a/bacula/src/lib/smartall.c b/bacula/src/lib/smartall.c index db2066d0e5..f5f0be853c 100644 --- a/bacula/src/lib/smartall.c +++ b/bacula/src/lib/smartall.c @@ -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;