chore: organize code

add -Wextra by default
pipefd to communicate better with parent and forked process
rustify some stuff
add the desktop parser to the file read
This commit is contained in:
2025-08-27 22:02:14 +02:00
parent 056ec64bcb
commit 109c9bd0be
17 changed files with 185 additions and 113 deletions

View File

@@ -2,6 +2,7 @@
#define SESSIONSH_
#include <sys/types.h>
#include <unistd.h>
#include "macros.h"
#include "util.h"
@@ -12,10 +13,58 @@ enum SessionType {
SHELL,
};
enum ExecType {
EXEC_SHELL,
EXEC_DESKTOP,
};
struct desktop_exec {
char** args;
int arg_count;
};
struct session_exec {
enum ExecType typ;
union {
char* shell;
struct desktop_exec desktop;
};
};
static inline struct session_exec session_exec_shell(char* shell) {
return (struct session_exec){
.typ = EXEC_SHELL,
.shell = shell,
};
}
static inline struct session_exec session_exec_desktop(int arg_count,
char** args) {
return (struct session_exec){
.typ = EXEC_DESKTOP,
.desktop =
{
.args = args,
.arg_count = arg_count,
},
};
}
static inline int session_exec_exec(struct session_exec* exec,
char** NNULLABLE envlist) {
switch (exec->typ) {
case EXEC_SHELL:
return execle(exec->shell, exec->shell, NULL, envlist);
case EXEC_DESKTOP:
return execve(exec->desktop.args[0], exec->desktop.args, envlist);
default:
__builtin_unreachable();
}
}
struct session {
char* NNULLABLE name;
char* NNULLABLE exec;
char* NULLABLE tryexec;
struct session_exec exec;
enum SessionType type;
};