From 9ce7cd61e1b5bbfc71a551675d56d870da0aab33 Mon Sep 17 00:00:00 2001 From: grialion <48643945+grialion@users.noreply.github.com> Date: Sat, 17 Jan 2026 16:48:13 +0100 Subject: [PATCH] fix: search Xorg binary in PATH --- include/desktop_exec.h | 1 + src/auth.c | 35 ++++++++++++++++++++++------------- src/desktop_exec.c | 2 +- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/include/desktop_exec.h b/include/desktop_exec.h index 9504fb8..c0d7a7c 100644 --- a/include/desktop_exec.h +++ b/include/desktop_exec.h @@ -6,6 +6,7 @@ #include "macros.h" +char* NULLABLE search_path(const char* NNULLABLE for_binary); int execvpe_desktop(char** args, char* NNULLABLE* NNULLABLE envlist); int parse_exec_string(const char* exec_s, int* arg_count, char*** args); void free_parsed_args(int arg_count, char** args); diff --git a/src/auth.c b/src/auth.c index c0aaae4..0e97f61 100644 --- a/src/auth.c +++ b/src/auth.c @@ -23,9 +23,6 @@ #include "ui.h" #include "util.h" -// no PATH search for now -#define XORG_COMMAND "/usr/bin/X" - #define XORG_MESSAGE_LENGTH 16 static void try_source_file(struct Vector* NNULLABLE vec_envlist, @@ -139,16 +136,8 @@ static void push_dyn_arr(void*** arr, void* item) { // TODO: properly pass this down extern int vt; -// TODO: add error msgs -/// returns on completion -static void launch_with_xorg_server(struct session_exec* NNULLABLE exec, - struct passwd* pw, - char** NNULLABLE envlist) { - int xorg_pipefd[2]; - if (pipe(xorg_pipefd) == -1) _exit(EXIT_FAILURE); - pid_t xorg_pid = fork(); - if (xorg_pid == 0) { +static void start_xorg_server(struct passwd* pw, char** NNULLABLE envlist, int xorg_pipefd[2]) { close(xorg_pipefd[0]); if (!pw->pw_dir) _exit(EXIT_FAILURE); // !!!!!!!!!! ATTENTION: this fails silently, of course add failure msgs but @@ -167,13 +156,33 @@ static void launch_with_xorg_server(struct session_exec* NNULLABLE exec, _exit(EXIT_FAILURE); } - int exit = execle(XORG_COMMAND, XORG_COMMAND, "-displayfd", fd_str, vt_path, + char* xorg_path = search_path("Xorg"); + if (!xorg_path) { + (void)fputs("couldn't find Xorg binary in PATH, sure it's installed?\n", stderr); + _exit(EXIT_FAILURE); + } + + int exit = execle(xorg_path, xorg_path, "-displayfd", fd_str, vt_path, NULL, envlist); perror("exec"); free(vt_path); free(fd_str); + free(xorg_path); _exit(exit); +} + +// TODO: add error msgs +/// returns on completion +static void launch_with_xorg_server(struct session_exec* NNULLABLE exec, + struct passwd* pw, + char** NNULLABLE envlist) { + int xorg_pipefd[2]; + if (pipe(xorg_pipefd) == -1) _exit(EXIT_FAILURE); + + pid_t xorg_pid = fork(); + if (xorg_pid == 0) { + start_xorg_server(pw, envlist, xorg_pipefd); } int display = 0; diff --git a/src/desktop_exec.c b/src/desktop_exec.c index b8d1c9a..c457305 100644 --- a/src/desktop_exec.c +++ b/src/desktop_exec.c @@ -17,7 +17,7 @@ // returns NULL on any error // otherwise it returns the absolute path of the program that MUST BE FREED -static char* NULLABLE search_path(const char* NNULLABLE for_binary) { +char* NULLABLE search_path(const char* NNULLABLE for_binary) { if (strchr(for_binary, '/') != NULL) { // skip absolute paths return strdup(for_binary);