#include "monotonic.h"
#include "nls.h"
#include "pathnames.h"
+#include "strutils.h"
#include "ttyutils.h"
#include "xalloc.h"
WINDOW *win;
int cols;
int rows;
- long delay;
+ struct timeval delay;
int (*sort_func)(const struct irq_info *, const struct irq_info *);
long smp_num_cpus;
unsigned int
+ request_exit:1,
run_once:1;
};
static struct irqtop_ctl *gctl;
static void sigint_handler(int unused __attribute__((__unused__)))
{
- gctl->delay = 0;
+ gctl->request_exit = 1;
}
static void __attribute__((__noreturn__)) usage(void)
break;
case 'q':
case 'Q':
- ctl->delay = 0;
+ ctl->request_exit = 1;
break;
}
}
struct timeval uptime_tv;
int retval = EXIT_SUCCESS;
struct termios saved_tty;
- struct irqtop_ctl ctl = { .delay = 3 };
+ struct irqtop_ctl ctl = { .delay.tv_sec = 3 };
static const struct option longopts[] = {
{"delay", required_argument, NULL, 'd'},
while ((o = getopt_long(argc, argv, "d:os:hV", longopts, NULL)) != -1) {
switch (o) {
case 'd':
- errno = 0;
- ctl.delay = atol(optarg);
- if (ctl.delay < 1)
- errx(EXIT_FAILURE, _("delay must be positive integer"));
+ strtotimeval_or_err(optarg, &ctl.delay,
+ _("failed to parse delay argument"));
break;
case 's':
ctl.sort_func = (int (*)(const struct irq_info *, const struct irq_info *))
break;
case 'o':
ctl.run_once = 1;
- ctl.delay = 0;
+ ctl.request_exit = 1;
break;
case 'V':
print_version(EXIT_SUCCESS);
gettime_monotonic(&uptime_tv);
do {
- struct timeval tv;
struct irq_info *result, *curr;
size_t size;
fd_set readfds;
if (ctl.run_once) {
break;
} else {
+ /* copy timeval, select will overwrite the value */
+ struct timeval tv = ctl.delay;
+
refresh();
FD_ZERO(&readfds);
FD_SET(STDIN_FILENO, &readfds);
- tv.tv_sec = ctl.delay;
- tv.tv_usec = 0;
if (select(STDOUT_FILENO, &readfds, NULL, NULL, &tv) > 0) {
if (read(STDIN_FILENO, &c, 1) != 1)
break;
parse_input(&ctl, c);
}
}
- } while (ctl.delay);
+ } while (!ctl.request_exit);
put_irqinfo(last_stat);