From: <sv...@va...> - 2009-02-11 14:53:22
|
Author: sewardj Date: 2009-02-11 14:53:15 +0000 (Wed, 11 Feb 2009) New Revision: 454 Log: Make the temporary log file directory be per-user, rather than having one for all users. That is, instead of /tmp/valkyrie_logs, use /tmp/valkyrie_logs_<username>. There's no guarantee that a /tmp directory created by one user is writable by another; hence they need to be per-user. Modified: trunk/configure.in trunk/valkyrie/core/memcheck_object.cpp trunk/valkyrie/core/valkyrie_object.cpp trunk/valkyrie/vk_config.cpp trunk/valkyrie/vk_utils.cpp trunk/valkyrie/vk_utils.h Modified: trunk/configure.in =================================================================== --- trunk/configure.in 2009-01-17 12:46:04 UTC (rev 453) +++ trunk/configure.in 2009-02-11 14:53:15 UTC (rev 454) @@ -200,7 +200,7 @@ AC_DEFINE_UNQUOTED(VK_CFG_DIR, ".$PACKAGE", [valkyrie config dir]) AC_DEFINE_UNQUOTED(VK_DBASE_DIR, "dbase/", [valkyrie config dbase dir]) AC_DEFINE_UNQUOTED(VK_SUPPS_DIR, "suppressions/", [valkyrie config supps dir]) -AC_DEFINE_UNQUOTED(VK_LOGS_DIR, "/tmp/valkyrie_logs/", [valkyrie config logs dir]) +AC_DEFINE_UNQUOTED(VK_LOGS_DIRP, "/tmp/valkyrie_logs_", [valkyrie config logs directory prefix]) # programs AC_DEFINE_UNQUOTED(BIN_VALGRIND, "$VALGRIND", [valgrind executable]) Modified: trunk/valkyrie/core/memcheck_object.cpp =================================================================== --- trunk/valkyrie/core/memcheck_object.cpp 2009-01-17 12:46:04 UTC (rev 453) +++ trunk/valkyrie/core/memcheck_object.cpp 2009-02-11 14:53:15 UTC (rev 454) @@ -338,7 +338,8 @@ */ bool Memcheck::runValgrind( QStringList vgflags ) { - m_saveFname = vk_mkstemp( QString( VK_LOGS_DIR ) + "mc_log", "xml" ); + m_saveFname = vk_mkstemp( QString( get_VK_LOGS_DIR() ) + + "mc_log", "xml" ); vk_assert( !m_saveFname.isEmpty() ); vgflags.insert( ++(vgflags.begin()), ("--log-file=" + m_saveFname) ); @@ -421,7 +422,8 @@ QString fname_logList = vkConfig->rdEntry( "merge", "valkyrie" ); statusMsg( "Merging logs in file-list", fname_logList ); - m_saveFname = vk_mkstemp( QString( VK_LOGS_DIR ) + "mc_merged", "xml" ); + m_saveFname = vk_mkstemp( QString( get_VK_LOGS_DIR() ) + + "mc_merged", "xml" ); vk_assert( !m_saveFname.isEmpty() ); QStringList flags; Modified: trunk/valkyrie/core/valkyrie_object.cpp =================================================================== --- trunk/valkyrie/core/valkyrie_object.cpp 2009-01-17 12:46:04 UTC (rev 453) +++ trunk/valkyrie/core/valkyrie_object.cpp 2009-02-11 14:53:15 UTC (rev 454) @@ -25,7 +25,7 @@ // Minimum version of Valgrind required -const char* pchVersionVgMin = "3.3.0"; +const char* pchVersionVgMin = "3.4.0"; /* class Valkyrie --------------------------------------------------- */ @@ -102,7 +102,7 @@ "Browser:", "", urlValkyrie::browser ); addOpt( DFLT_LOGDIR, VkOPTION::NOT_POPT, VkOPTION::WDG_LEDIT, "valkyrie", '\0', "default-logdir", - "", "", VK_LOGS_DIR, + "", "", get_VK_LOGS_DIR(), "Log Dir:", "", urlValkyrie::logDir ); addOpt( WORKING_DIR, VkOPTION::ARG_STRING, VkOPTION::WDG_LEDIT, "valkyrie", '\0', "working-dir", Modified: trunk/valkyrie/vk_config.cpp =================================================================== --- trunk/valkyrie/vk_config.cpp 2009-01-17 12:46:04 UTC (rev 453) +++ trunk/valkyrie/vk_config.cpp 2009-02-11 14:53:15 UTC (rev 454) @@ -844,9 +844,10 @@ } } - /* Further, check for temporary log dir (VK_LOGS_DIR), make if !exists */ - if ( !QFile::exists( VK_LOGS_DIR ) ) { - if ( !checkRCEntry( VK_LOGS_DIR, vk) ) { + /* Further, check for temporary log dir (VK_LOGS_DIRP + username), + make if !exists */ + if ( !QFile::exists( get_VK_LOGS_DIR() ) ) { + if ( !checkRCEntry( get_VK_LOGS_DIR(), vk) ) { return false; } } Modified: trunk/valkyrie/vk_utils.cpp =================================================================== --- trunk/valkyrie/vk_utils.cpp 2009-01-17 12:46:04 UTC (rev 453) +++ trunk/valkyrie/vk_utils.cpp 2009-02-11 14:53:15 UTC (rev 454) @@ -15,6 +15,7 @@ #include <stdarg.h> // va_start, va_end #include <sys/types.h> // getpid #include <unistd.h> // getpid +#include <pwd.h> // getpwuid #include <qapplication.h> #include <qfileinfo.h> @@ -142,6 +143,24 @@ } +/* Get the log directory associated with this user --------------------- */ +// Just do this once, and cache the results. +QString get_VK_LOGS_DIR () +{ + static QString res = NULL; + if (!res) { + pid_t me = getuid(); + struct passwd* pw = getpwuid( me ); + /* This should never fail. Is it worth trying to continue if it + does? I don't think so. */ + vk_assert(pw); + res = QString( VK_LOGS_DIRP ) + QString( pw->pw_name ) + "/"; + vk_assert(res); + } + return res; +} + + /* Version check ------------------------------------------------------- Given version string of "major.minor.patch" (e.g. 3.3.0), hex version = (major << 16) + (minor << 8) + patch Modified: trunk/valkyrie/vk_utils.h =================================================================== --- trunk/valkyrie/vk_utils.h 2009-01-17 12:46:04 UTC (rev 453) +++ trunk/valkyrie/vk_utils.h 2009-02-11 14:53:15 UTC (rev 454) @@ -85,6 +85,9 @@ /* create a unique filename -------------------------------------------- */ QString vk_mkstemp( QString filepath, QString ext=QString::null ); +/* Get the log directory associated with this user --------------------- */ +QString get_VK_LOGS_DIR (); + /* "valgrind 3.0.5" --> 0x030005 --------------------------------------- */ int strVersion2hex( QString ver_str ); |