From 62af39cb7181118d3d9c32e12aa0bcb7d273f4ee Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sun, 25 Aug 2024 19:11:55 -0700 Subject: 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. --- src/vmon.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'src') 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 #include #include +#include #include #include #include @@ -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+"); -- cgit v1.2.3