summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2024-08-25 19:11:55 -0700
committerVito Caputo <vcaputo@pengaru.com>2024-08-25 19:11:55 -0700
commit62af39cb7181118d3d9c32e12aa0bcb7d273f4ee (patch)
treece02941ec71aad2f6c33b19d6460277a68a23adf
parentd1f3f4f07ab0cfa2a7f58c911e34a15c73ae5048 (diff)
vmon: add --wip-name commandline argument
--wip-name sets a constant name to use for the pre-rename temp name of snapshots. Otherwise a dynamic dot-filename augmented from the destination name is used. The impetus for this is to simplify garbage collection of produced PNGs. We'll ignore dot-files to never step on the WIP file during GC, but would like vmon to truncate and reuse the same WIP name so it's not potentially accumulating the dot-files in weird failure modes where the snapshots repeatedly fail to complete and get renamed. So in such a scenario we'll pass a dot-file for --wip-name and vmon will keep reusing that name, never leaking more than the single WIP file in even a persistent a failure mode.
-rw-r--r--src/vmon.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/vmon.c b/src/vmon.c
index a3067f5..576aebc 100644
--- a/src/vmon.c
+++ b/src/vmon.c
@@ -21,6 +21,7 @@
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <sys/prctl.h>
#include <time.h>
#include <sys/stat.h>
@@ -52,6 +53,7 @@ typedef struct vmon_t {
int hertz;
char *output_dir;
char *name;
+ char *wip_name;
unsigned n_snapshots;
const char * const *execv;
unsigned n_execv;
@@ -193,6 +195,7 @@ static void print_help(void)
" -p --pid PID of the top-level process to monitor (1 if unspecified)\n"
" -i --snapshots Save a PNG snapshot every N seconds (SIGUSR1 also snapshots)\n"
" -s --snapshot Save a PNG snapshot upon receiving SIGCHLD\n"
+ " -w --wip-name Name to use for work-in-progress snapshot filename\n"
" -v --version Print version\n"
" -W --width Chart width\n"
" -z --hertz Sample rate in hertz\n"
@@ -431,6 +434,16 @@ static int vmon_handle_argv(vmon_t *vmon, int argc, const char * const *argv)
} else if (is_flag(*argv, "-s", "--snapshot")) {
vmon->snapshot = 1;
last = argv;
+ } else if (is_flag(*argv, "-w", "--wip-name")) {
+ if (!parse_flag_str(argv, end, argv + 1, 1, &vmon->wip_name))
+ return 0;
+
+ if (strchr(vmon->wip_name, '/')) {
+ VWM_ERROR("invalid --wip-name: \"%s\"", vmon->wip_name);
+ return 0;
+ }
+
+ last = ++argv;
} else if (is_flag(*argv, "-f", "--fullscreen")) {
if (!set_fullscreen(vmon)) {
VWM_ERROR("unable to set fullscreen dimensions");
@@ -723,12 +736,16 @@ static int vmon_snapshot(vmon_t *vmon)
name ? "-" : "",
t_str,
vmon->n_snapshots++);
- snprintf(tmp_path, sizeof(tmp_path), "%s/.%s%s%s-%u.png-WIP",
- vmon->output_dir,
- name ? name : "",
- name ? "-" : "",
- t_str,
- vmon->n_snapshots);
+ if (vmon->wip_name) {
+ snprintf(tmp_path, sizeof(tmp_path), "%s/%s", vmon->output_dir, vmon->wip_name);
+ } else {
+ snprintf(tmp_path, sizeof(tmp_path), "%s/.%s%s%s-%u.png-WIP",
+ vmon->output_dir,
+ name ? name : "",
+ name ? "-" : "",
+ t_str,
+ vmon->n_snapshots);
+ }
free(name);
output = fopen(tmp_path, "w+");
© All Rights Reserved