Skip to content

Commit

Permalink
move itimerspec to create_timer since its local to the function
Browse files Browse the repository at this point in the history
  • Loading branch information
falconindy committed Dec 6, 2011
1 parent 726b044 commit 8b82eb6
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions wakeup.c
Expand Up @@ -180,26 +180,29 @@ parse_timespec(int optind, int argc, char **argv, struct timespec_t *ts)
} }


static int static int
create_alarm(struct itimerspec *wakeup, struct timespec_t *ts) create_alarm(struct timespec_t *ts)
{ {
struct itimerspec wakeup;
timer_t timerid; timer_t timerid;


memset(&wakeup, 0, sizeof(struct itimerspec));

/* init timer */ /* init timer */
if(timer_create(CLOCK_REALTIME_ALARM, NULL, &timerid) != 0) { if(timer_create(CLOCK_REALTIME_ALARM, NULL, &timerid) != 0) {
perror("error: failed to create timer"); perror("error: failed to create timer");
return 1; return 1;
} }


/* init itimerspec */ /* init itimerspec */
if(clock_gettime(CLOCK_REALTIME_ALARM, &wakeup->it_value)) { if(clock_gettime(CLOCK_REALTIME_ALARM, &wakeup.it_value)) {
perror("error: failed to get time from RTC"); perror("error: failed to get time from RTC");
return 1; return 1;
} }


/* set itimerspec to some future time */ /* set itimerspec to some future time */
wakeup->it_value.tv_sec += timespec_to_seconds(ts); wakeup.it_value.tv_sec += timespec_to_seconds(ts);


if(timer_settime(timerid, TIMER_ABSTIME, wakeup, NULL)) { if(timer_settime(timerid, TIMER_ABSTIME, &wakeup, NULL)) {
perror("error: failed to set wakeup time"); perror("error: failed to set wakeup time");
return 1; return 1;
} }
Expand All @@ -213,7 +216,6 @@ create_alarm(struct itimerspec *wakeup, struct timespec_t *ts)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
struct itimerspec wakeup;
struct timespec_t ts; struct timespec_t ts;


if(argc <= 1) { if(argc <= 1) {
Expand All @@ -222,7 +224,6 @@ main(int argc, char *argv[])
} }


memset(&ts, 0, sizeof(struct timespec)); memset(&ts, 0, sizeof(struct timespec));
memset(&wakeup, 0, sizeof(struct itimerspec));


if(parse_options(argc, argv) != 0) { if(parse_options(argc, argv) != 0) {
return 1; return 1;
Expand All @@ -232,7 +233,7 @@ main(int argc, char *argv[])
return 2; return 2;
} }


if(create_alarm(&wakeup, &ts) != 0) { if(create_alarm(&ts) != 0) {
return 3; return 3;
} }


Expand Down

0 comments on commit 8b82eb6

Please sign in to comment.