Merge pull request #10 from zhaofengli/override-xdg-user-dir

Allow overriding xdg-user-dir executable
This commit is contained in:
Ariel Abreu 2023-05-01 14:35:54 -04:00 committed by GitHub
commit 782ebad23c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -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()

View File

@ -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 <sanitizer/lsan_interface.h>
#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");