commit 6bf8a6799faea4ff85fe7a83c7941e9c01a04097
parent fe27962fac30d17f0a43f3074c4e8206567aa370
Author: sin <sin@2f30.org>
Date: Fri, 5 Aug 2016 11:26:33 +0100
Move printrxtx() logic outside of signal handler
Diffstat:
M | sbm.c | | | 16 | ++++++++++++++-- |
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/sbm.c b/sbm.c
@@ -34,10 +34,18 @@ char *argv0;
char *ifname;
uint64_t origrxbytes, origtxbytes, rxbytes, txbytes;
struct timeval begin;
+volatile sig_atomic_t interrupted;
int Bflag;
int tflag;
void
+sighdlr(int signo)
+{
+ (void)signo;
+ interrupted = 1;
+}
+
+void
scan(void)
{
struct ifaddrs *ifas, *ifa;
@@ -224,7 +232,7 @@ print(uint64_t rxbits, uint64_t txbits, uint64_t rxpps, uint64_t txpps)
}
void
-printrxtx(int sig)
+printrxtx(void)
{
struct timeval now, uptime;
char *rxsuffix, *txsuffix;
@@ -274,6 +282,10 @@ loop(long count, struct timeval *delay)
origrxbytes = oldrxbytes, origtxbytes = oldtxbytes;
for (;;) {
tvsleep(delay);
+ if (interrupted) {
+ printrxtx();
+ interrupted = 0;
+ }
sample(&rxbytes, &txbytes, &rxpps, &txpps);
getmonotime(&now);
timersub(&now, &old, &diff);
@@ -336,7 +348,7 @@ main(int argc, char *argv[])
getmonotime(&begin);
ifname = ifn;
- signal(SIGINFO, printrxtx);
+ signal(SIGINFO, sighdlr);
ms2tv(&tv, delay);
scan();
loop(count, &tv);