diff options
Diffstat (limited to 'src/vmon.c')
-rw-r--r-- | src/vmon.c | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -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); |