summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2021-09-16 18:07:43 -0700
committerVito Caputo <vcaputo@pengaru.com>2021-09-16 18:07:43 -0700
commitf579e3c386adf82fa1454999332edf9f0e2706a4 (patch)
treef88f9e1dcab4a2dfb9bc98c2b6c41c54991fb7b8
parent112fd7fc5dde4ccd9caa7cdf98b84be914d380b5 (diff)
vmon: save snapshots on SIGUSR1 as well
This adds an externally triggered means of snapshotting, which is always available, not only with --snapshot.
-rw-r--r--src/vmon.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/vmon.c b/src/vmon.c
index 9a32031..5f865ab 100644
--- a/src/vmon.c
+++ b/src/vmon.c
@@ -63,7 +63,7 @@ typedef struct vmon_t {
#define WIDTH_MIN 200
#define HEIGHT_MIN 28
-static volatile int got_sigchld;
+static volatile int got_sigchld, got_sigusr1;
/* return if arg == flag or altflag if provided */
static int is_flag(const char *arg, const char *flag, const char *altflag)
@@ -225,6 +225,12 @@ static void handle_sigchld(int signum)
}
+static void handle_sigusr1(int signum)
+{
+ got_sigusr1 = 1;
+}
+
+
/* parse and apply argv, implementing an strace-like cli, mutates vmon. */
static int vmon_handle_argv(vmon_t *vmon, int argc, char * const argv[])
{
@@ -400,6 +406,11 @@ static vmon_t * vmon_startup(int argc, char * const argv[])
goto _err_charts;
}
+ if (signal(SIGUSR1, handle_sigusr1) == SIG_ERR) {
+ VWM_PERROR("unable to set SIGUSR1 handler");
+ goto _err_charts;
+ }
+
vmon->chart = vwm_chart_create(vmon->charts, vmon->pid, vmon->width, vmon->height, vmon->name);
if (!vmon->chart) {
VWM_ERROR("unable to create chart");
@@ -667,6 +678,13 @@ int main(int argc, char * const argv[])
vmon->done = 1;
}
}
+
+ if (got_sigusr1) {
+ if (vmon_snapshot(vmon) < 0)
+ VWM_ERROR("error saving snapshot");
+
+ got_sigusr1 = 0;
+ }
}
vmon_shutdown(vmon);
© 2021 All Rights Reserved