From 31e8427469ede148249796fed05be0165e321d23 Mon Sep 17 00:00:00 2001 From: Christian Beer Date: Thu, 16 Mar 2017 18:28:08 +0100 Subject: [PATCH 1/2] Manager/Lib: fix 'New Manager window' function on Linux This was not working because the manager was not detecting its own executable name and path so it couldn't start a new instance of itself. Windows and Mac use different codepaths so it worked there. The new library function can be extended for Windows and Mac to avoid code duplication. --- clientgui/BOINCGUIApp.cpp | 21 +++++++++++++++++++++ configure.ac | 5 +++++ lib/util.cpp | 17 +++++++++++++++++ lib/util.h | 2 ++ 4 files changed, 45 insertions(+) diff --git a/clientgui/BOINCGUIApp.cpp b/clientgui/BOINCGUIApp.cpp index 434769b5e4..f1a2dd485b 100644 --- a/clientgui/BOINCGUIApp.cpp +++ b/clientgui/BOINCGUIApp.cpp @@ -721,6 +721,16 @@ void CBOINCGUIApp::DetectExecutableName() { // Store the root directory for later use. m_strBOINCMGRExecutableName = pszProg; +#elif defined(__WXGTK__) + char path[PATH_MAX]; + if (!get_real_executable_path(path, PATH_MAX)) { + // find filename component + char* name = strrchr(path, '/'); + if (name) { + name++; + m_strBOINCMGRExecutableName = name; + } + } #endif } @@ -742,6 +752,17 @@ void CBOINCGUIApp::DetectRootDirectory() { // Store the root directory for later use. m_strBOINCMGRRootDirectory = szPath; +#elif defined(__WXGTK__) + char path[PATH_MAX]; + if (!get_real_executable_path(path, PATH_MAX)) { + // find path component + char* name = strrchr(path, '/'); + if (name) { + name++; + *name = '\0'; + m_strBOINCMGRRootDirectory = path; + } + } #endif } diff --git a/configure.ac b/configure.ac index 48defb1661..e7d8e00635 100644 --- a/configure.ac +++ b/configure.ac @@ -1017,6 +1017,11 @@ if test -e "/proc/self/stat"; then AC_DEFINE(HAVE__PROC_SELF_STAT, 1, [Define to 1 if /proc/self/stat exists]) fi +dnl Check for /proc/self/exe (Linux) +if test -e "/proc/self/exe"; then + AC_DEFINE(HAVE__PROC_SELF_EXE, 1, [Define to 1 if /proc/self/exe exists]) +fi + dnl Check for /proc/meminfo (Linux) if test -e "/proc/meminfo"; then AC_DEFINE(HAVE__PROC_MEMINFO, 1, [Define to 1 if /proc/meminfo exists]) diff --git a/lib/util.cpp b/lib/util.cpp index 4c94a67336..897d277d6e 100644 --- a/lib/util.cpp +++ b/lib/util.cpp @@ -625,3 +625,20 @@ double rand_normal() { cached = true; return z*cos(PI2*u2); } + +// determines the real path and filename of the current process +// not the current working directory +// +int get_real_executable_path(char* path, size_t max_len) { +#ifdef HAVE__PROC_SELF_EXE + int ret = readlink("/proc/self/exe", path, max_len); + if ( ret >= 0) { + path[ret] = '\0'; // readlink does not null terminate + return 0; + } else { + perror("readlink"); + return ERR_PROC_PARSE; + } +#endif + return ERR_NOT_IMPLEMENTED; +} diff --git a/lib/util.h b/lib/util.h index 7bf6b9cfbd..01f5c5ec41 100644 --- a/lib/util.h +++ b/lib/util.h @@ -110,6 +110,8 @@ extern bool process_exists(int); extern int wait_client_mutex(const char* dir, double timeout); +extern int get_real_executable_path(char* path, size_t max_len); + #ifdef GCL_SIMULATOR extern double simtime; #define time(x) ((int)simtime) From 573ee60fedce41310d5e481eaa5e74b97e7c6825 Mon Sep 17 00:00:00 2001 From: Christian Beer Date: Mon, 20 Mar 2017 10:00:01 +0100 Subject: [PATCH 2/2] Lib: fix compile error Fixes ambiguity reported by gcc "error: call of overloaded 'perror(const char [9])' is ambiguous" --- lib/util.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/util.cpp b/lib/util.cpp index 897d277d6e..9ea53a61d6 100644 --- a/lib/util.cpp +++ b/lib/util.cpp @@ -636,7 +636,11 @@ int get_real_executable_path(char* path, size_t max_len) { path[ret] = '\0'; // readlink does not null terminate return 0; } else { +#ifdef _USING_FCGI_ + FCGI::perror("readlink"); +#else perror("readlink"); +#endif return ERR_PROC_PARSE; } #endif