aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile8
-rw-r--r--src/gammad.c11
2 files changed, 16 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 8d6abff..a25208d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,7 @@
PKGNAME = gammad
-COMmAND = gammad
+COMMAND = gammad
+KERNEL = linux
SRC = filter gammad output ramps util
@@ -18,9 +19,12 @@ WARN = -Wall -Wextra -pedantic -Wdouble-promotion -Wformat=2 -Winit-self -Wmissi
FFLAGS = -fstrict-aliasing -fstrict-overflow -fipa-pure-const -ftree-vrp -fstack-usage \
-funsafe-loop-optimizations
+CPP_linux = -DHAVE_LINUX_PROCFS
+CPP_linux-libre = $(CPP_linux)
+
CCFLAGS = -std=c99 $(WARN) $(FFLAGS) $(OPTIMISE)
LDFLAGS = $(OPTIMISE) -lgamma
-CPPFLAGS = -D'PKGNAME="$(PKGNAME)"' -D'COMMAND="$(COMMAND)"' -D_XOPEN_SOURCE=700
+CPPFLAGS = -D'PKGNAME="$(PKGNAME)"' -D'COMMAND="$(COMMAND)"' -D_XOPEN_SOURCE=700 $(CPP_$(KERNEL))
.PHONY: all
diff --git a/src/gammad.c b/src/gammad.c
index 5450399..92fbf4d 100644
--- a/src/gammad.c
+++ b/src/gammad.c
@@ -229,9 +229,13 @@ static int is_pidfile_reusable(const char* pidfile, const char* token)
int fd = -1, saved_errno, tries = 0;
char* content = NULL;
char* p;
- char* end;
pid_t pid = 0;
size_t n;
+#if defined(HAVE_LINUX_PROCFS)
+ char* end;
+#else
+ (void) token;
+#endif
/* Get PID */
retry:
@@ -271,6 +275,7 @@ static int is_pidfile_reusable(const char* pidfile, const char* token)
goto bad;
/* Validate PID */
+#if defined(HAVE_LINUX_PROCFS)
sprintf(temp, "/proc/%llu/environ", (unsigned long long)pid);
fd = open(temp, O_RDONLY);
if (fd < 0)
@@ -283,6 +288,10 @@ static int is_pidfile_reusable(const char* pidfile, const char* token)
for (end = (p = content) + n; p != end; p = strchr(p, '\0') + 1)
if (!strcmp(p, token))
return 0;
+#else
+ if ((kill(pid, 0) == 0) || (errno == EINVAL))
+ return 0;
+#endif
return 1;
bad: