Implemented pause/resume on SIGUSR2

This commit is contained in:
Antonio Bibiano 2016-07-12 18:51:26 +10:00 committed by Ivan Tham
parent 8e7bd4d2aa
commit 938cd77b94

18
spt.c
View File

@ -24,13 +24,14 @@ typedef struct {
#include "config.h"
static int i, timecount;
static int i, timecount, inc;
/* function declarations */
static void die(const char *errstr, ...);
static void spawn(char *cmd, char *cmt);
static void notify_send(char *cmt);
static void remaining_time(int sigint);
static void toggle(int sigint);
static void usage(void);
/* functions implementations */
@ -90,6 +91,13 @@ remaining_time(int sigint)
notify_send(buf);
}
void
toggle(int sigint) {
if (signal(SIGUSR2, SIG_IGN) != SIG_IGN)
signal(SIGUSR2, toggle);
inc ^= 1;
}
void
usage(void)
{
@ -99,6 +107,8 @@ usage(void)
int
main(int argc, char *argv[])
{
inc = 1;
ARGBEGIN {
case 'e':
notifyext = EARGF(usage());
@ -116,14 +126,16 @@ main(int argc, char *argv[])
if (signal(SIGUSR1, SIG_IGN) != SIG_IGN)
signal(SIGUSR1, remaining_time);
if (signal(SIGUSR2, SIG_IGN) != SIG_IGN)
signal(SIGUSR2, toggle);
run:
notify_send(timers[i].cmt);
for (timecount = 0; timecount < timers[i].tmr; timecount++)
for (timecount = 0; timecount < timers[i].tmr; timecount += inc)
sleep(1);
i < LEN(timers) ? i++ : i = 0; /* i infinal loop */
i = (i < LEN(timers)) ? i+1 : 0; /* i infinal loop */
goto run;
return 0;