]> git.neil.brown.name Git - susman.git/blob - event_test.c
wakealarmd: cope with delta between system time and RTC time.
[susman.git] / event_test.c
1
2 /*
3  * test handling wakeup events on fd.
4  * You will need to strace things and watch to get any real
5  * feedback as this only does anything interesting when there
6  * is a race.
7  *
8  * Copyright (C) 2011 Neil Brown <neilb@suse.de>
9  *
10  *    This program is free software; you can redistribute it and/or modify
11  *    it under the terms of the GNU General Public License as published by
12  *    the Free Software Foundation; either version 2 of the License, or
13  *    (at your option) any later version.
14  *
15  *    This program is distributed in the hope that it will be useful,
16  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *    GNU General Public License for more details.
19  *
20  *    You should have received a copy of the GNU General Public License along
21  *    with this program; if not, write to the Free Software Foundation, Inc.,
22  *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 #include <stdlib.h>
26 #include <event.h>
27 #include <stdio.h>
28 #include <fcntl.h>
29 #include "libsus.h"
30
31 void read_event(int fd, short ev, void *data)
32 {
33         char buf[80];
34         int n;
35         int i;
36
37         printf("Can read now .. give it a moment though\n");
38         sleep(5);
39         n = read(fd, buf, 80);
40         if (n < 0)
41                 exit(1);
42
43         for (i = 0; i < n ; i++)
44                 printf(" %02x", buf[i] & 0xff);
45         printf("\n");
46 }
47
48 main(int argc, char *argv[])
49 {
50         int fd;
51         struct event *ev;
52
53         if (argc != 2) {
54                 fprintf(stderr, "Usage: event_test devicename\n");
55                 exit(1);
56         }
57         fd = open(argv[1], O_RDONLY);
58         if (fd < 0) {
59                 perror(argv[1]);
60                 exit(1);
61         }
62
63         event_init();
64         event_priority_init(3);
65         ev = wake_set(fd, read_event, NULL, 1);
66
67         event_loop(0);
68         exit(0);
69 }