summaryrefslogtreecommitdiffstats
path: root/src/daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon.c')
-rw-r--r--src/daemon.c26
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");