diff options
| author | coast <coasteen@proton.me> | 2026-02-05 03:02:25 +0330 |
|---|---|---|
| committer | coast <coasteen@proton.me> | 2026-02-05 03:02:25 +0330 |
| commit | cb5e57dd373c1c06ec1030d71ed80933b7cb96bd (patch) | |
| tree | ee3cf851f55cf446654956e2fb3415354f276cba /src/daemon.c | |
| parent | 426fea0f3bd973e532176e054096dc3a909dce06 (diff) | |
| download | chd-cb5e57dd373c1c06ec1030d71ed80933b7cb96bd.tar.gz chd-cb5e57dd373c1c06ec1030d71ed80933b7cb96bd.tar.bz2 chd-cb5e57dd373c1c06ec1030d71ed80933b7cb96bd.tar.xz chd-cb5e57dd373c1c06ec1030d71ed80933b7cb96bd.tar.zst | |
update
Diffstat (limited to 'src/daemon.c')
| -rw-r--r-- | src/daemon.c | 26 |
1 files changed, 24 insertions, 2 deletions
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 <X11/XKBlib.h> #include <X11/Xlib.h> #include <X11/keysym.h> @@ -7,7 +6,10 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <strings.h> +#include <sys/select.h> #include <sys/socket.h> +#include <sys/stat.h> #include <sys/un.h> #include <sys/wait.h> #include <unistd.h> @@ -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"); |
