From 7ce8ff58f8ac129437fcfccf53fe7fed1fd36492 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Tue, 2 Oct 2012 03:11:16 +0200 Subject: [PATCH] Update the standalone testcase, too. --- .gitignore | 1 + Makefile | 7 ++++-- input.c | 1 - slider_watcher.c | 64 ++++++++++++++++++++++++++++++++++++------------ 4 files changed, 55 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 813033de4..35c5875cc 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ lua-* mupdf-thirdparty.zip djvulibre* kpdfview +slider_watcher *.o kindlepdfviewer-*.zip diff --git a/Makefile b/Makefile index dc673dfc2..5585ef152 100644 --- a/Makefile +++ b/Makefile @@ -121,8 +121,11 @@ kpdfview: kpdfview.o einkfb.o pdf.o blitbuffer.o drawcontext.o popen_noshell.o i $(LDFLAGS) \ -o kpdfview -lm -ldl -lpthread $(EMU_LDFLAGS) $(DYNAMICLIBSTDCPP) -slider_watcher: slider_watcher.c - $(CC) $(CFLAGS) $< -o $@ +slider_watcher.o: %.o: %.c + $(CC) -c $(CFLAGS) $< -o $@ + +slider_watcher: popen_noshell.o slider_watcher.o + $(CC) $(CFLAGS) popen_noshell.o slider_watcher.o -o $@ ft.o: %.o: %.c $(THIRDPARTYLIBS) $(CC) -c $(KPDFREADER_CFLAGS) -I$(FREETYPEDIR)/include -I$(MUPDFDIR)/fitz $< -o $@ diff --git a/input.c b/input.c index f8077f1f8..126f94a9c 100644 --- a/input.c +++ b/input.c @@ -33,7 +33,6 @@ #include "input.h" #include #include -#include #define CODE_IN_SAVER 10000 #define CODE_OUT_SAVER 10001 diff --git a/slider_watcher.c b/slider_watcher.c index 6a4e26e15..cca6827a5 100644 --- a/slider_watcher.c +++ b/slider_watcher.c @@ -16,8 +16,11 @@ along with this program. If not, see . */ -#include +#include "popen-noshell/popen_noshell.h" +#include #include +#include +#include #include #include #include @@ -25,18 +28,19 @@ #include #include #include +#include -#define OUTPUT_SIZE 21 -#define EVENT_PIPE "/tmp/event_slider" #define CODE_IN_SAVER 10000 #define CODE_OUT_SAVER 10001 int main ( int argc, char *argv[] ) { - int fd, ret; + int fd; FILE *fp; - char std_out[OUTPUT_SIZE] = ""; + char std_out[256]; + int status; + struct popen_noshell_pass_to_pclose pclose_arg; struct input_event ev; __u16 key_code = 10000; @@ -51,7 +55,7 @@ main ( int argc, char *argv[] ) /* open npipe for writing */ fd = open(argv[1], O_RDWR | O_NONBLOCK); if(fd < 0) { - printf("Open %s falied: %s\n", argv[1], strerror(errno)); + printf("Open %s failed: %s\n", argv[1], strerror(errno)); exit(EXIT_FAILURE); } @@ -60,15 +64,25 @@ main ( int argc, char *argv[] ) ev.code = key_code; ev.value = 1; - while(1) { - /* listen power slider events */ - memset(std_out, 0, OUTPUT_SIZE); - fp = popen("lipc-wait-event -s 0 com.lab126.powerd goingToScreenSaver,outOfScreenSaver", "r"); - ret = fread(std_out, OUTPUT_SIZE, 1, fp); - pclose(fp); + /* listen power slider events */ + char *exec_file = "lipc-wait-event"; + char *arg1 = "-m"; + char *arg2 = "-s"; + char *arg3 = "0"; + char *arg4 = "com.lab126.powerd"; + char *arg5 = "goingToScreenSaver,outOfScreenSaver"; + char *arg6 = (char *) NULL; + char *chargv[] = {exec_file, arg1, arg2, arg3, arg4, arg5, arg6}; + + fp = popen_noshell(exec_file, (const char * const *)chargv, "r", &pclose_arg, 0); + if (!fp) { + err(EXIT_FAILURE, "popen_noshell()"); + } + + while(fgets(std_out, sizeof(std_out)-1, fp)) { + + /* printf("Got line: %s", std_out); */ - /* fill event struct */ - gettimeofday(&ev.time, NULL); if(std_out[0] == 'g') { ev.code = CODE_IN_SAVER; } else if(std_out[0] == 'o') { @@ -77,9 +91,29 @@ main ( int argc, char *argv[] ) printf("Unrecognized event.\n"); exit(EXIT_FAILURE); } + /* fill event struct */ + gettimeofday(&ev.time, NULL); + + /* printf("Send event %d\n", ev.code); */ /* generate event */ - ret = write(fd, &ev, sizeof(struct input_event)); + if(write(fd, &ev, sizeof(struct input_event)) == -1) { + printf("Failed to generate event.\n"); + } + } + + status = pclose_noshell(&pclose_arg); + if (status == -1) { + err(EXIT_FAILURE, "pclose_noshell()"); + } else { + printf("Power slider event listener child exited with status %d.\n", status); + + if WIFEXITED(status) { + printf("Child exited normally with status: %d.\n", WEXITSTATUS(status)); + } + if WIFSIGNALED(status) { + printf("Child terminated by signal: %d.\n", WTERMSIG(status)); + } } close(fd);