fix: search Xorg binary in PATH

This commit is contained in:
grialion
2026-01-17 16:48:13 +01:00
parent b0d0a2e890
commit 9ce7cd61e1
3 changed files with 24 additions and 14 deletions

View File

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

View File

@@ -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,15 +156,35 @@ 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;
if (!x_get_display(xorg_pipefd, &display)) {
(void)fputs("failed to get X display, aborting\n", stderr);

View File

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