From 7cf5bfe38b8345b2466d3ef7ba7d06040dc57e9d Mon Sep 17 00:00:00 2001 From: "Alex Xu (Hello71)" Date: Wed, 16 Aug 2017 20:48:34 -0400 Subject: Improve C example. --- .gitignore | 1 + Makefile | 10 +++++++++- example.c | 6 +++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 0ac38cb..c8df796 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /inhibit-screensaver +/c-example *.o diff --git a/Makefile b/Makefile index 699b2a1..685a684 100644 --- a/Makefile +++ b/Makefile @@ -3,13 +3,21 @@ bindir := $(prefix)/bin CFLAGS += $(shell pkg-config --cflags dbus-1) -Wall -Wextra -std=c99 LDLIBS := $(shell pkg-config --libs dbus-1) +all: inhibit-screensaver c-example inhibit-screensaver: inhibit-screensaver.o +c-example: c-example.o + +c-example.o: example.c + $(COMPILE.c) $(OUTPUT_OPTION) $< + clean: - $(RM) inhibit-screensaver.o inhibit-screensaver + $(RM) inhibit-screensaver.o inhibit-screensaver c-example.o c-example install: install -D -m0755 inhibit-screensaver $(bindir) uninstall: $(RM) $(bindir)/inhibit-screensaver + +.PHONY: clean install uninstall diff --git a/example.c b/example.c index b822312..2eeac2d 100644 --- a/example.c +++ b/example.c @@ -1,3 +1,4 @@ +#define _DEFAULT_SOURCE #include #include #include @@ -22,11 +23,14 @@ int main() { // works even if process dies! kill(getpid(), SIGKILL); + + // otherwise, release the inhibition: + close(pipefd[1]); } else { close(pipefd[1]); - close(0); dup2(pipefd[0], 0); execl("./inhibit-screensaver", "./inhibit-screensaver", "c-inhibitor-example", "testing", (char *)NULL); + perror("exec inhibit-screensaver"); exit(1); } } -- cgit v1.2.3-70-g09d2