From d239b1669bbc466c00cbf48e074fd35d0c7be46d Mon Sep 17 00:00:00 2001 From: Felicity Tarnell Date: Fri, 7 Mar 2014 23:50:13 +0000 Subject: [PATCH] Clean up power code. --- tts.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/tts.c b/tts.c index 9ae691f..af44462 100644 --- a/tts.c +++ b/tts.c @@ -109,13 +109,10 @@ static io_object_t notifier; static mach_port_t ioport; static io_connect_t root_port; -static volatile sig_atomic_t donesleep; -static time_t sleeptime; - -static void power_setup(struct kevent *); -static void power_handle(struct kevent *); -static void power_event(void *, io_service_t, natural_t, void *); -static void prompt_sleep(void); +static void power_setup (struct kevent *); +static void power_handle (struct kevent *); +static void power_event (void *, io_service_t, natural_t, void *); +static void prompt_sleep (time_t); static void power_setup(ev) @@ -175,7 +172,6 @@ power_event(ref, service, msgtype, arg) natural_t msgtype; { static time_t sleep_started; -time_t diff; switch (msgtype) { case kIOMessageSystemWillSleep: @@ -188,10 +184,7 @@ time_t diff; /* System has finished wake-up; calculate the sleep time and * prompt the user. */ - time(&diff); - diff -= sleep_started; - sleeptime += diff; - prompt_sleep(); + prompt_sleep(time(NULL) - sleep_started); break; } } @@ -765,7 +758,8 @@ char input[1024]; #ifdef USE_DARWIN_POWER static void -prompt_sleep() +prompt_sleep(sleeptime) + time_t sleeptime; { /* * We woke from sleep. If there's a running entry, prompt the user to @@ -775,8 +769,6 @@ prompt_sleep() WCHAR pr[128]; int h, m, s = 0; - donesleep = 0; - /* Only prompt if an entry is running */ if (!running) return; @@ -793,17 +785,14 @@ int h, m, s = 0; WIDE("Remove %02d:%02d:%02d time asleep from running entry?"), h, m, s); - if (!yesno(pr)) { - sleeptime = 0; + if (!yesno(pr)) return; - } /* * This is a bit of a fudge, but it has the desired effect. Alternatively * we could merge en_started into en_secs, then subtract that. */ running->en_started += sleeptime; - sleeptime = 0; } #endif /* USE_DARWIN_POWER */