]> git.neil.brown.name Git - susman.git/blob - alarm_test.c
wakealarmd: cope with delta between system time and RTC time.
[susman.git] / alarm_test.c
1
2
3 /* Test wakealarm.
4  * argv is a number of seconds to wait for.
5  *
6  * Copyright (C) 2011 Neil Brown <neilb@suse.de>
7  *
8  *    This program is free software; you can redistribute it and/or modify
9  *    it under the terms of the GNU General Public License as published by
10  *    the Free Software Foundation; either version 2 of the License, or
11  *    (at your option) any later version.
12  *
13  *    This program is distributed in the hope that it will be useful,
14  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *    GNU General Public License for more details.
17  *
18  *    You should have received a copy of the GNU General Public License along
19  *    with this program; if not, write to the Free Software Foundation, Inc.,
20  *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include "libsus.h"
26
27 void callback(int fd, short ev, void *data)
28 {
29         printf("Ping - got the event\n");
30         suspend_block(-1);
31         event_loopbreak();
32 }
33
34 int main(int argc, char *argv[])
35 {
36         time_t now;
37         time_t then;
38         int diff;
39         struct event *ev;
40
41         if (argc != 2) {
42                 fprintf(stderr, "Usage: alarm_test seconds\n");
43                 exit(1);
44         }
45         diff = atoi(argv[1]);
46         time(&now);
47         then = now + diff;
48         event_init();
49
50         ev = wakealarm_set(then, callback, NULL);
51
52         event_loop(0);
53         printf("Hold off suspend for a while...\n");
54         sleep(4);
55         printf("OK - done\n");
56         exit(0);
57 }