From 40dbe97f6138705369c30b4ad95014bd07c6913d Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 2 Mar 2009 11:46:00 +1000 Subject: syndaemon: move shm code into shm_init(). Signed-off-by: Peter Hutterer Signed-off-by: Henrik Rydberg Acked-by: Julien Cristau --- tools/syndaemon.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'tools/syndaemon.c') diff --git a/tools/syndaemon.c b/tools/syndaemon.c index 65112ab..515a132 100644 --- a/tools/syndaemon.c +++ b/tools/syndaemon.c @@ -438,6 +438,28 @@ void record_main_loop(Display* display, double idle_time) { } #endif /* HAVE_XRECORD */ +static int +shm_init() +{ + int shmid; + + /* Connect to the shared memory area */ + if ((shmid = shmget(SHM_SYNAPTICS, sizeof(SynapticsSHM), 0)) == -1) { + if ((shmid = shmget(SHM_SYNAPTICS, 0, 0)) == -1) { + fprintf(stderr, "Can't access shared memory area. SHMConfig disabled?\n"); + return 0; + } else { + fprintf(stderr, "Incorrect size of shared memory area. Incompatible driver version?\n"); + return 0; + } + } + if ((synshm = (SynapticsSHM*) shmat(shmid, NULL, 0)) == NULL) { + perror("shmat"); + return 0; + } + return 1; +} + int main(int argc, char *argv[]) { @@ -445,7 +467,6 @@ main(int argc, char *argv[]) int poll_delay = 200000; /* 200 ms */ Display *display; int c; - int shmid; int use_xrecord = 1; @@ -492,20 +513,8 @@ main(int argc, char *argv[]) exit(2); } - /* Connect to the shared memory area */ - if ((shmid = shmget(SHM_SYNAPTICS, sizeof(SynapticsSHM), 0)) == -1) { - if ((shmid = shmget(SHM_SYNAPTICS, 0, 0)) == -1) { - fprintf(stderr, "Can't access shared memory area. SHMConfig disabled?\n"); - exit(2); - } else { - fprintf(stderr, "Incorrect size of shared memory area. Incompatible driver version?\n"); - exit(2); - } - } - if ((synshm = (SynapticsSHM*) shmat(shmid, NULL, 0)) == NULL) { - perror("shmat"); + if (!shm_init()) exit(2); - } /* Install a signal handler to restore synaptics parameters on exit */ install_signal_handler(); -- cgit v1.2.3