diff options
| -rw-r--r-- | makefile | 4 | ||||
| -rw-r--r-- | src/daemon.c | 26 |
2 files changed, 26 insertions, 4 deletions
@@ -1,8 +1,8 @@ PREFIX = /usr/local MANPREFIX = $(PREFIX)/share/man -X11INC = /usr/X11R6/include -X11LIB = /usr/X11R6/lib +X11INC = /usr/local/include +X11LIB = /usr/local/lib INCS = -I$(X11INC) LIBS = -L$(X11LIB) -lX11 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"); |
