From cb5e57dd373c1c06ec1030d71ed80933b7cb96bd Mon Sep 17 00:00:00 2001 From: coast Date: Thu, 5 Feb 2026 03:02:25 +0330 Subject: update --- src/daemon.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/daemon.c') diff --git a/src/daemon.c b/src/daemon.c index 7be3e73..746a6ce 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -1,4 +1,3 @@ -#define _GNU_SOURCE #include #include #include @@ -7,7 +6,10 @@ #include #include #include +#include +#include #include +#include #include #include #include @@ -101,6 +103,22 @@ int client_mode(int retry, char *combo, char *cmd) { } } +int make_executable_if_needed(char *cfg) { + struct stat st; + if (stat(cfg, &st) == 0) { + if (!(st.st_mode & S_IXUSR)) { + if (chmod(cfg, st.st_mode | S_IXUSR) == -1) { + perror("chmod"); + return -1; + } + } + } else { + perror("stat"); + return -1; + } + return 0; +} + int main(int argc, char *argv[]) { if (argc >= 2 && strcmp(argv[1], "wait") == 0) return client_mode(1, NULL, NULL); @@ -134,7 +152,11 @@ int main(int argc, char *argv[]) { snprintf(def, 511, "%s/.config/piss/pissrc", getpwuid(getuid())->pw_dir); cfg = def; } - // Use execvp so the shebang (#! /usr/bin/lua) is respected + + if (make_executable_if_needed(cfg) == -1) { + exit(1); + } + char *args[] = {cfg, NULL}; execvp(cfg, args); perror("execvp"); -- cgit v1.3