Merge pull request #348 from NiLuJe/input-close-fix

Fix input.closeAll & don't leave zombie lipc-wait-event processes
This commit is contained in:
{Qingping,Dave} Hou
2012-10-02 17:42:35 -07:00
7 changed files with 268 additions and 83 deletions

15
.gitignore vendored
View File

@@ -12,6 +12,7 @@ crash.log
data
fonts
kpdfview
slider_watcher
*.o
kindlepdfviewer-*.zip
@@ -24,3 +25,17 @@ kpvcrlib/CMakeCache.txt
kpvcrlib/CMakeFiles/
kpvcrlib/cmake_install.cmake
kpvcrlib/Makefile
popen-noshell/libpopen_noshell.a
popen-noshell/*.o
popen-noshell/.svn/
popen-noshell/CREDITS
popen-noshell/Makefile
popen-noshell/README
popen-noshell/performance_tests/
popen-noshell/popen_noshell.c
popen-noshell/popen_noshell.h
popen-noshell/popen_noshell_examples.c
popen-noshell/popen_noshell_tests.c
popen-noshell/popen_noshell_tests.cpp

111
Makefile
View File

@@ -11,15 +11,18 @@ CRENGINEDIR=$(KPVCRLIBDIR)/crengine
FREETYPEDIR=$(MUPDFDIR)/thirdparty/freetype-2.4.10
LFSDIR=luafilesystem
POPENNSDIR=popen-noshell
# must point to directory with *.ttf fonts for crengine
TTF_FONTS_DIR=$(MUPDFDIR)/fonts
# set this to your ARM cross compiler:
HOST:=arm-none-linux-gnueabi
CC:=$(HOST)-gcc
CXX:=$(HOST)-g++
STRIP:=$(HOST)-strip
CHOST?=arm-none-linux-gnueabi
CC:=$(CHOST)-gcc
CXX:=$(CHOST)-g++
STRIP:=$(CHOST)-strip
AR:=$(CHOST)-ar
ifdef SBOX_UNAME_MACHINE
CC:=gcc
CXX:=g++
@@ -27,12 +30,16 @@ endif
HOSTCC:=gcc
HOSTCXX:=g++
CFLAGS:=-O3 $(SYSROOT)
CXXFLAGS:=-O3 $(SYSROOT)
# Base CFLAGS, without arch. We'll need it for luajit, because its Makefiles do some tricky stuff to differentiate HOST/TARGET
BASE_CFLAGS:=-O2 -ffast-math -pipe -fomit-frame-pointer -fno-stack-protector -U_FORTIFY_SOURCE
# Use this for debugging:
#BASE_CFLAGS:=-O0 -g
ARM_ARCH:=-march=armv6j -mtune=arm1136jf-s -mfpu=vfp
HOST_ARCH:=-march=native
HOSTCFLAGS:=$(HOST_ARCH) $(BASE_CFLAGS)
CFLAGS:=$(BASE_CFLAGS)
CXXFLAGS:=$(BASE_CFLAGS) -fno-use-cxa-atexit
LDFLAGS:=-Wl,-O1 -Wl,--as-needed
ARM_CFLAGS:=-march=armv6j -mtune=arm1136jf-s -mfpu=vfp
# use this for debugging:
#CFLAGS:=-O0 -g
DYNAMICLIBSTDCPP:=-lstdc++
ifdef STATICLIBSTDCPP
@@ -56,9 +63,11 @@ ifdef EMULATE_READER
ifeq "$(shell uname -s -m)" "Darwin x86_64"
EMU_LDFLAGS += -pagezero_size 10000 -image_base 100000000
endif
CFLAGS+= $(HOST_ARCH)
CXXFLAGS+= $(HOST_ARCH)
else
CFLAGS+= $(ARM_CFLAGS)
CXXFLAGS+= $(ARM_CFLAGS)
CFLAGS+= $(ARM_ARCH)
CXXFLAGS+= $(ARM_ARCH)
endif
# standard includes
@@ -88,16 +97,20 @@ THIRDPARTYLIBS := $(MUPDFLIBDIR)/libfreetype.a \
LUALIB := $(LUADIR)/src/libluajit.a
all:kpdfview
POPENNSLIB := $(POPENNSDIR)/libpopen_noshell.a
kpdfview: kpdfview.o einkfb.o pdf.o blitbuffer.o drawcontext.o input.o util.o ft.o lfs.o mupdfimg.o $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) djvu.o $(DJVULIBS) cre.o $(CRENGINELIBS)
all: kpdfview
kpdfview: kpdfview.o einkfb.o pdf.o blitbuffer.o drawcontext.o input.o $(POPENNSLIB) util.o ft.o lfs.o mupdfimg.o $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) djvu.o $(DJVULIBS) cre.o $(CRENGINELIBS)
$(CC) \
$(CFLAGS) \
kpdfview.o \
einkfb.o \
pdf.o \
blitbuffer.o \
drawcontext.o \
input.o \
$(POPENNSLIB) \
util.o \
ft.o \
lfs.o \
@@ -110,10 +123,14 @@ kpdfview: kpdfview.o einkfb.o pdf.o blitbuffer.o drawcontext.o input.o util.o ft
cre.o \
$(CRENGINELIBS) \
$(STATICLIBSTDCPP) \
-o kpdfview -lm -ldl -lpthread $(EMU_LDFLAGS) $(DYNAMICLIBSTDCPP)
$(LDFLAGS) \
-o $@ -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: slider_watcher.o $(POPENNSLIB)
$(CC) $(CFLAGS) slider_watcher.o $(POPENNSLIB) -o $@
ft.o: %.o: %.c $(THIRDPARTYLIBS)
$(CC) -c $(KPDFREADER_CFLAGS) -I$(FREETYPEDIR)/include -I$(MUPDFDIR)/fitz $< -o $@
@@ -131,7 +148,7 @@ lfs.o: $(LFSDIR)/src/lfs.c
$(CC) -c $(CFLAGS) -I$(LUADIR)/src -I$(LFSDIR)/src $(LFSDIR)/src/lfs.c -o $@
fetchthirdparty:
-rm -Rf mupdf/thirdparty
rm -rf mupdf/thirdparty
test -d mupdf && (cd mupdf; git checkout .) || echo warn: mupdf folder not found
test -d $(LUADIR) && (cd $(LUADIR); git checkout .) || echo warn: $(LUADIR) folder not found
git submodule init
@@ -153,58 +170,66 @@ fetchthirdparty:
patch -N -p0 < ../../../kpvcrlib/jpeg_decompress_struct_size.patch
# MuPDF patch: use external fonts
cd mupdf && patch -N -p1 < ../mupdf.patch
test -f popen-noshell/popen_noshell.c || svn co http://popen-noshell.googlecode.com/svn/trunk/ popen-noshell
# popen_noshell patch: Make it build on recent TCs, and implement a simple Makefile for building it as a static lib
cd popen-noshell && test -f Makefile || patch -N -p0 < popen_noshell-buildfix.patch
clean:
-rm -f *.o kpdfview slider_watcher
rm -f *.o kpdfview slider_watcher
cleanthirdparty:
-make -C $(LUADIR) clean
-make -C $(MUPDFDIR) build="release" clean
-make -C $(CRENGINEDIR)/thirdparty/antiword clean
test -d $(CRENGINEDIR)/thirdparty/chmlib && make -C $(CRENGINEDIR)/thirdparty/chmlib clean || echo warn: chmlib folder not found
test -d $(CRENGINEDIR)/thirdparty/libpng && (make -C $(CRENGINEDIR)/thirdparty/libpng clean) || echo warn: chmlib folder not found
test -d $(CRENGINEDIR)/crengine && (make -C $(CRENGINEDIR)/crengine clean) || echo warn: chmlib folder not found
test -d $(KPVCRLIBDIR) && (make -C $(KPVCRLIBDIR) clean) || echo warn: chmlib folder not found
-rm -rf $(DJVUDIR)/build
-rm -f $(MUPDFDIR)/fontdump.host
-rm -f $(MUPDFDIR)/cmapdump.host
$(MAKE) -C $(LUADIR) CC="$(HOSTCC)" HOST_CC="$(HOSTCC) -m32" CROSS="$(CHOST)-" clean
$(MAKE) -C $(MUPDFDIR) build="release" clean
$(MAKE) -C $(CRENGINEDIR)/thirdparty/antiword clean
test -d $(CRENGINEDIR)/thirdparty/chmlib && $(MAKE) -C $(CRENGINEDIR)/thirdparty/chmlib clean || echo warn: chmlib folder not found
test -d $(CRENGINEDIR)/thirdparty/libpng && ($(MAKE) -C $(CRENGINEDIR)/thirdparty/libpng clean) || echo warn: chmlib folder not found
test -d $(CRENGINEDIR)/crengine && ($(MAKE) -C $(CRENGINEDIR)/crengine clean) || echo warn: chmlib folder not found
test -d $(KPVCRLIBDIR) && ($(MAKE) -C $(KPVCRLIBDIR) clean) || echo warn: chmlib folder not found
rm -rf $(DJVUDIR)/build
rm -f $(MUPDFDIR)/fontdump.host
rm -f $(MUPDFDIR)/cmapdump.host
$(MAKE) -C $(POPENNSDIR) clean
$(MUPDFDIR)/fontdump.host:
make -C mupdf build="release" CC="$(HOSTCC)" $(MUPDFTARGET)/fontdump
$(MAKE) -C mupdf build="release" CC="$(HOSTCC)" CFLAGS="$(HOSTCFLAGS) -I../mupdf/fitz -I../mupdf/pdf" $(MUPDFTARGET)/fontdump
cp -a $(MUPDFLIBDIR)/fontdump $(MUPDFDIR)/fontdump.host
make -C mupdf clean
$(MAKE) -C mupdf clean
$(MUPDFDIR)/cmapdump.host:
make -C mupdf build="release" CC="$(HOSTCC)" $(MUPDFTARGET)/cmapdump
$(MAKE) -C mupdf build="release" CC="$(HOSTCC)" CFLAGS="$(HOSTCFLAGS) -I../mupdf/fitz -I../mupdf/pdf" $(MUPDFTARGET)/cmapdump
cp -a $(MUPDFLIBDIR)/cmapdump $(MUPDFDIR)/cmapdump.host
make -C mupdf clean
$(MAKE) -C mupdf clean
$(MUPDFLIBS) $(THIRDPARTYLIBS): $(MUPDFDIR)/cmapdump.host $(MUPDFDIR)/fontdump.host
# build only thirdparty libs, libfitz and pdf utils, which will care for libmupdf.a being built
CFLAGS="$(CFLAGS) -DNOBUILTINFONT" make -C mupdf build="release" CC="$(CC)" CMAPDUMP=cmapdump.host FONTDUMP=fontdump.host MUPDF= MU_APPS= BUSY_APP= XPS_APPS= verbose=1
CFLAGS="$(CFLAGS) -DNOBUILTINFONT" $(MAKE) -C mupdf build="release" CC="$(CC)" CMAPDUMP=cmapdump.host FONTDUMP=fontdump.host MUPDF= MU_APPS= BUSY_APP= XPS_APPS= verbose=1
$(DJVULIBS):
-mkdir $(DJVUDIR)/build
mkdir -p $(DJVUDIR)/build
ifdef EMULATE_READER
cd $(DJVUDIR)/build && ../configure --disable-desktopfiles --disable-shared --enable-static --disable-xmltools --disable-largefile
else
cd $(DJVUDIR)/build && ../configure --disable-desktopfiles --disable-shared --enable-static --host=$(HOST) --disable-xmltools --disable-largefile
cd $(DJVUDIR)/build && ../configure --disable-desktopfiles --disable-shared --enable-static --host=$(CHOST) --disable-xmltools --disable-largefile
endif
make -C $(DJVUDIR)/build
$(MAKE) -C $(DJVUDIR)/build
$(CRENGINELIBS):
cd $(KPVCRLIBDIR) && rm -rf CMakeCache.txt CMakeFiles && \
CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS)" cmake . && \
make
$(MAKE)
$(LUALIB):
ifdef EMULATE_READER
make -C $(LUADIR)
$(MAKE) -C $(LUADIR)
else
make -C $(LUADIR) CC="$(HOSTCC)" HOST_CC="$(HOSTCC) -m32" CROSS="$(HOST)-" TARGET_FLAGS="$(SYSROOT) -DLUAJIT_NO_LOG2 -DLUAJIT_NO_EXP2"
# To recap: build its TARGET_CC from CROSS+CC, so we need HOSTCC in CC. Build its HOST/TARGET_CFLAGS based on CFLAGS, so we need a neutral CFLAGS without arch
$(MAKE) -C $(LUADIR) CC="$(HOSTCC)" HOST_CC="$(HOSTCC) -m32" CFLAGS="$(BASE_CFLAGS)" HOST_CFLAGS="$(HOSTCFLAGS)" TARGET_CFLAGS="$(CFLAGS)" CROSS="$(CHOST)-" TARGET_FLAGS="-DLUAJIT_NO_LOG2 -DLUAJIT_NO_EXP2"
endif
thirdparty: $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) $(DJVULIBS) $(CRENGINELIBS)
$(POPENNSLIB):
$(MAKE) -C $(POPENNSDIR) CC="$(CC)" AR="$(AR)"
thirdparty: $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) $(DJVULIBS) $(CRENGINELIBS) $(POPENNSLIB)
INSTALL_DIR=kindlepdfviewer
@@ -215,8 +240,8 @@ customupdate: all
# ensure that build binary is for ARM
file kpdfview | grep ARM || exit 1
$(STRIP) --strip-unneeded kpdfview
-rm kindlepdfviewer-$(VERSION).zip
rm -Rf $(INSTALL_DIR)
rm -f kindlepdfviewer-$(VERSION).zip
rm -rf $(INSTALL_DIR)
mkdir -p $(INSTALL_DIR)/{history,screenshots}
echo $(VERSION) > $(INSTALL_DIR)/git-rev
cp -p README.md COPYING kpdfview $(LUA_FILES) $(INSTALL_DIR)
@@ -226,5 +251,5 @@ customupdate: all
cp -r resources $(INSTALL_DIR)
mkdir $(INSTALL_DIR)/fonts/host
zip -9 -r kindlepdfviewer-$(VERSION).zip $(INSTALL_DIR) launchpad/ kite/
rm -Rf $(INSTALL_DIR)
rm -rf $(INSTALL_DIR)
@echo "copy kindlepdfviewer-$(VERSION).zip to /mnt/us/customupdates and install with shift+shift+I"

76
input.c
View File

@@ -15,7 +15,11 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "popen-noshell/popen_noshell.h"
#include <err.h>
#include <stdio.h>
#include <signal.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
@@ -29,9 +33,7 @@
#include "input.h"
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#define OUTPUT_SIZE 21
#define CODE_IN_SAVER 10000
#define CODE_OUT_SAVER 10001
#define CODE_USB_PLUG_IN 10010
@@ -41,7 +43,17 @@
#define NUM_FDS 4
int inputfds[4] = { -1, -1, -1, -1 };
int slider_pid = -1;
pid_t slider_pid = -1;
struct popen_noshell_pass_to_pclose pclose_arg;
void slider_handler(int sig)
{
/* Kill lipc-wait-event properly on exit */
if(pclose_arg.pid != 0) {
// Be a little more gracious, lipc seems to handle SIGINT properly
kill(pclose_arg.pid, SIGINT);
}
}
int findFreeFdSlot() {
int i;
@@ -73,10 +85,13 @@ static int openInputDevice(lua_State *L) {
return luaL_error(L, "cannot fork() slider event listener");
}
if(childpid == 0) {
// We send a SIGTERM to this child on exit, trap it to kill lipc properly.
signal(SIGTERM, slider_handler);
FILE *fp;
char std_out[OUTPUT_SIZE] = "";
char std_out[256];
int status;
struct input_event ev;
int ret;
__u16 key_code = 10000;
close(pipefd[0]);
@@ -85,17 +100,22 @@ static int openInputDevice(lua_State *L) {
ev.code = key_code;
ev.value = 1;
/* listen power slider events */
while(1) {
fp = popen("exec lipc-wait-event com.lab126.powerd goingToScreenSaver,outOfScreenSaver,charging,notCharging", "r");
/* @TODO 07.06 2012 (houqp)
* plugin and out event can only be watched by:
lipc-wait-event com.lab126.hal usbPlugOut,usbPlugIn
*/
if(fgets(std_out, OUTPUT_SIZE, fp) == NULL) {
break;
}
pclose(fp);
/* listen power slider events (listen for ever for multiple events) */
char *argv[] = {"lipc-wait-event", "-m", "-s", "0", "com.lab126.powerd", "goingToScreenSaver,outOfScreenSaver,charging,notCharging", (char *) NULL};
/* @TODO 07.06 2012 (houqp)
* plugin and out event can only be watched by:
lipc-wait-event com.lab126.hal usbPlugOut,usbPlugIn
*/
fp = popen_noshell("lipc-wait-event", (const char * const *)argv, "r", &pclose_arg, 0);
if (!fp) {
err(EXIT_FAILURE, "popen_noshell()");
}
/* Flush to get rid of buffering issues? */
fflush(fp);
while(fgets(std_out, sizeof(std_out)-1, fp)) {
if(std_out[0] == 'g') {
ev.code = CODE_IN_SAVER;
} else if(std_out[0] == 'o') {
@@ -116,10 +136,26 @@ static int openInputDevice(lua_State *L) {
/* generate event */
if(write(pipefd[1], &ev, sizeof(struct input_event)) == -1) {
break;
printf("Failed to generate event.\n");
}
}
exit(0); /* cannot be reached?! */
status = pclose_noshell(&pclose_arg);
if (status == -1) {
err(EXIT_FAILURE, "pclose_noshell()");
} else {
printf("lipc-wait-event exited with status %d.\n", status);
if WIFEXITED(status) {
printf("lipc-wait-event exited normally with status: %d.\n", WEXITSTATUS(status));
}
if WIFSIGNALED(status) {
printf("lipc-wait-event terminated by signal: %d.\n", WTERMSIG(status));
}
}
// We're done, go away :).
_exit(EXIT_SUCCESS);
} else {
close(pipefd[1]);
inputfds[fd] = pipefd[0];
@@ -149,7 +185,7 @@ static int closeInputDevices(lua_State *L) {
for(i=0; i<NUM_FDS; i++) {
if(inputfds[i] != -1) {
ioctl(inputfds[i], EVIOCGRAB, 0);
close(i);
close(inputfds[i]);
}
}
if(slider_pid != -1) {
@@ -223,7 +259,7 @@ static int waitForInput(lua_State *L) {
SDL_WaitEvent(&event);
else {
while (SDL_GetTicks()-ticks <= usecs/1000) {
if (SDL_PollEvent(&event)) break;
if (SDL_PollEvent(&event)) break;
SDL_Delay(10);
}
if (SDL_GetTicks()-ticks > usecs/1000)

View File

@@ -39,7 +39,7 @@
lua_State *L;
int main(int argc, char **argv) {
int i, err;
int i;
if(argc < 2) {
fprintf(stderr, "needs config file as first argument.\n");

View File

@@ -31,7 +31,3 @@ fi
# always try to continue cvm
killall -cont cvm || /etc/init.d/framework start
# cleanup hanging process
killall lipc-wait-event

View File

@@ -0,0 +1,86 @@
Index: CREDITS
===================================================================
--- CREDITS (revision 0)
+++ CREDITS (working copy)
@@ -0,0 +1 @@
+Taken from http://code.google.com/p/popen-noshell/
Property changes on: CREDITS
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: Makefile
===================================================================
--- Makefile (revision 0)
+++ Makefile (working copy)
@@ -0,0 +1,17 @@
+SRCS=popen_noshell.c
+
+OBJS:=$(SRCS:%.c=%.o)
+
+%.o: %.c
+ $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<
+
+all: libpopen_noshell.a
+
+libpopen_noshell.a: $(OBJS)
+ $(AR) rcs $@ $(OBJS)
+
+clean:
+ rm -rf *.o
+ rm -rf libpopen_noshell.a
+
+.PHONY: clean
Property changes on: Makefile
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
Index: popen_noshell.c
===================================================================
--- popen_noshell.c (revision 8)
+++ popen_noshell.c (working copy)
@@ -16,6 +16,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses>.
*/
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
#include "popen_noshell.h"
#include <errno.h>
#include <unistd.h>
@@ -28,10 +32,6 @@
#include <sys/wait.h>
#include <stdlib.h>
#include <inttypes.h>
-
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
#include <sched.h>
/*
@@ -249,7 +249,7 @@
* The above malloc() + align implementation is taken from:
* http://stackoverflow.com/questions/227897/solve-the-memory-alignment-in-c-interview-question-that-stumped-me
*/
-
+
#ifndef POPEN_NOSHELL_VALGRIND_DEBUG
pid = clone(fn, stack_aligned, CLONE_VM | SIGCHLD, arg);
#else
@@ -358,7 +358,7 @@
pclose_arg->fp = fp;
pclose_arg->pid = pid;
-
+
return fp; // we should never end up here
}

View File

@@ -16,8 +16,11 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include "popen-noshell/popen_noshell.h"
#include <err.h>
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
@@ -25,18 +28,19 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <sys/wait.h>
#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,18 @@ 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 *argv[] = {"lipc-wait-event", "-m", "-s", "0", "com.lab126.powerd", "goingToScreenSaver,outOfScreenSaver", (char *) NULL};
fp = popen_noshell("lipc-wait-event", (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 +84,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);