From 4567e8845abf6c0979c4b9f1a4b12b62a9de97b5 Mon Sep 17 00:00:00 2001 From: Xorg Date: Sat, 9 Jan 2021 15:40:06 +0100 Subject: [PATCH] Util: workaround in start_daemon() for AppImage --- src/CMakeLists.txt | 1 + src/daemon.c | 3 +++ src/util.c | 9 ++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8c5f1e12..ab3a1554 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -172,6 +172,7 @@ add_definitions(-DPRGVER="${PROJECT_VERSION}" -DGETTEXT_PACKAGE="${CMAKE_PROJECT_NAME}" -DLOCALEDIR="${CMAKE_INSTALL_FULL_LOCALEDIR}" -DTERMINFODIR="/lib/terminfo" + -DDAEMON_EXEC="${DAEMON_EXEC}" -DDAEMON_PATH="${DAEMON_PATH}" ) diff --git a/src/daemon.c b/src/daemon.c index 01e3264c..780b2db8 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -408,5 +408,8 @@ int main(void) free(ti->thread); pthread_mutex_destroy(&ti->mutex); + if(getenv("APPDIR") != NULL) + remove("/tmp/"DAEMON_EXEC); + return err; } diff --git a/src/util.c b/src/util.c index 641eff4d..20777a47 100644 --- a/src/util.c +++ b/src/util.c @@ -423,12 +423,19 @@ const char *start_daemon(bool graphical) pid_t pid; char *msg = NULL; char *const appdir = getenv("APPDIR"); - char *const daemon = (appdir == NULL) ? DAEMON_PATH : format("%s/%s", appdir, DAEMON_PATH); + char *const daemon = (appdir == NULL) ? DAEMON_PATH : format("/tmp/%s", DAEMON_EXEC); char *const cmd1[] = { daemon, NULL }; char *const cmd2[] = { "pkexec", daemon, NULL }; char *const cmd3[] = { "pkexec", "--disable-internal-agent", daemon, NULL }; char *const *cmd = cmd2; + if(appdir != NULL) + { + /* Hack to allow pkexec to run daemon (when running from AppImage) */ + char *const cmdcopy = format("cp %s/%s %s", appdir, DAEMON_PATH, daemon); + system(cmdcopy); + } + if(graphical) cmd = cmd3; else if(IS_ROOT)