long interval = 0;
char timestamp[TIMESTAMP_LEN];
-struct sigaction alrm_act;
+struct sigaction alrm_act, int_act;
+int sigint_caught = 0;
/*
***************************************************************************
alarm(interval);
}
+/*
+ ***************************************************************************
+ * SIGINT signal handler.
+ *
+ * IN:
+ * @sig Signal number.
+ **************************************************************************
+ */
+void int_handler(int sig)
+{
+ sigint_caught = 1;
+}
+
/*
***************************************************************************
* Initialize stats common structures.
skip = 1;
}
+ /* Set a handler for SIGALRM */
+ memset(&alrm_act, 0, sizeof(alrm_act));
+ alrm_act.sa_handler = alarm_handler;
+ sigaction(SIGALRM, &alrm_act, NULL);
+ alarm(interval);
+
+ /* Set a handler for SIGINT */
+ memset(&int_act, 0, sizeof(int_act));
+ int_act.sa_handler = int_handler;
+ sigaction(SIGINT, &int_act, NULL);
+
/* Don't buffer data if redirected to a pipe */
setbuf(stdout, NULL);
if (count) {
curr ^= 1;
pause();
+
+ if (sigint_caught) {
+ /* SIGINT signal caught => Terminate JSON output properly */
+ count = 0;
+ printf("\n"); /* Skip "^C" displayed on screen */
+ }
}
}
while (count);
printf("\n");
}
- /* Set a handler for SIGALRM */
- memset(&alrm_act, 0, sizeof(alrm_act));
- alrm_act.sa_handler = alarm_handler;
- sigaction(SIGALRM, &alrm_act, NULL);
- alarm(interval);
-
/* Main loop */
rw_io_stat_loop(count, &rectime);