From f65f2d30fdad1a960ba1028fefbb51807532688e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 29 Dec 2024 17:19:13 +0100 Subject: Make user homepath optional in setup-gsr-ui --- main.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 4a46f54..23b6104 100644 --- a/main.c +++ b/main.c @@ -119,7 +119,7 @@ static int copy_file_atomic_set_capabilities(const char *source_path, const char static void usage(void) { fprintf(stderr, "usage alt.1: kms-server-proxy \n"); - fprintf(stderr, "usage alt.2: kms-server-proxy setup-gsr-ui \n"); + fprintf(stderr, "usage alt.2: kms-server-proxy setup-gsr-ui [user_homepath]\n"); exit(1); } @@ -130,6 +130,12 @@ static int setup_gsr_ui(const char *user_homepath) { return 1; } + if(!user_homepath) { + user_homepath = getenv("HOME"); + if(!user_homepath) + user_homepath = "/tmp"; + } + char kms_server_proxy_local_filepath[PATH_MAX]; /* Update kms-server-proxy-N to kms-server-proxy-N+1 on update (update that needs to run before this program launches itself) */ snprintf(kms_server_proxy_local_filepath, sizeof(kms_server_proxy_local_filepath), "%s/.local/share/gpu-screen-recorder/kms-server-proxy-1", user_homepath); @@ -205,9 +211,10 @@ static int launch_gsr_kms_server(const char *initial_socket_path, const char *ca } int main(int argc, char **argv) { - if(argc == 3) { + if(argc == 2 || argc == 3) { + const char *user_homepath = argc == 3 ? argv[2] : NULL; if(strcmp(argv[1], "setup-gsr-ui") == 0) { - return setup_gsr_ui(argv[2]); + return setup_gsr_ui(user_homepath); } else { fprintf(stderr, "error: invalid option \"%s\".\n", argv[1]); usage(); -- cgit v1.2.3