From 21e3c369049ea0b44dd4f26a42e407b3dda4719f Mon Sep 17 00:00:00 2001 From: Zhaofeng Li Date: Wed, 26 Apr 2023 16:07:36 -0600 Subject: [PATCH] Allow overriding xdg-user-dir executable This makes it easier to set the path as xdg-user-dir may not be in PATH. --- CMakeLists.txt | 7 +++++++ src/darlingserver.cpp | 8 ++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index be05372..04e2b2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,6 +66,7 @@ endif() add_subdirectory(duct-tape) set(DARLINGSERVER_INIT_PROCESS "/sbin/launchd" CACHE STRING "The init process darlingserver should execute (default is \"/sbin/launchd\")") +set(DARLINGSERVER_XDG_USER_DIR_CMD "xdg-user-dir" CACHE STRING "The xdg-user-dir binary darlingserver should execute (default is \"xdg-user-dir\")") include_directories( include @@ -165,3 +166,9 @@ if (NOT "${DARLINGSERVER_INIT_PROCESS}" STREQUAL "") DARLINGSERVER_INIT_PROCESS="${DARLINGSERVER_INIT_PROCESS}" ) endif() + +if (NOT "${DARLINGSERVER_XDG_USER_DIR_CMD}" STREQUAL "") + target_compile_definitions(darlingserver PRIVATE + DARLINGSERVER_XDG_USER_DIR_CMD="${DARLINGSERVER_XDG_USER_DIR_CMD}" + ) +endif() diff --git a/src/darlingserver.cpp b/src/darlingserver.cpp index 2f2d7fd..40a7ca8 100644 --- a/src/darlingserver.cpp +++ b/src/darlingserver.cpp @@ -48,6 +48,10 @@ #define DARLINGSERVER_INIT_PROCESS "/sbin/launchd" #endif +#ifndef DARLINGSERVER_XDG_USER_DIR_CMD + #define DARLINGSERVER_XDG_USER_DIR_CMD "xdg-user-dir" +#endif + #if DSERVER_ASAN #include #endif @@ -90,9 +94,9 @@ void fixPermissionsRecursive(const char* path, uid_t originalUID, gid_t original const char* xdgDirectory(const char* name) { static char dir[4096]; - char* cmd = (char*) malloc(16 + strlen(name)); + char* cmd = (char*) malloc(sizeof(DARLINGSERVER_XDG_USER_DIR_CMD) + 1 + strlen(name)); - sprintf(cmd, "xdg-user-dir %s", name); + sprintf(cmd, DARLINGSERVER_XDG_USER_DIR_CMD " %s", name); FILE* proc = popen(cmd, "r");