From 46066385674ae65d016979c84f4ef0a5e523dbc3 Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Sat, 14 Mar 2026 17:20:30 +0000 Subject: [PATCH] Constrain the options so that -M cannot be used with -U (as it is a different action) and -M will report the right error message if mixed with -R or -Q (#67). --- docs/pv.1 | 2 ++ src/include/options.h | 1 + src/main/options.c | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/docs/pv.1 b/docs/pv.1 index 37d98c0..c2df1a1 100644 --- a/docs/pv.1 +++ b/docs/pv.1 @@ -439,6 +439,8 @@ the latter can't show the input:output ratio. The values \*(lq\fB0\fR\*(rq, \*(lq\fB1\fR\*(rq, and \*(lq\fB2\fR\*(rq may be used as synonyms for \*(lq\fBin\fR\*(rq, \*(lq\fBout\fR\*(rq, and \*(lq\fBboth\fR\*(rq. +.IP +This option cannot be used with \*(lq\fB\-\-store\-and\-forward\*(rq. .\"TODO: formatting option for input:output ratio .\" .SS "Other options" diff --git a/src/include/options.h b/src/include/options.h index 491851f..bf07871 100644 --- a/src/include/options.h +++ b/src/include/options.h @@ -40,6 +40,7 @@ typedef enum { * Sides of a monitored command to monitor with PV_ACTION_MONITOR. */ typedef enum { + PV_SIDE_NONE, /* don't monitor a command */ PV_SIDE_IN, /* monitor only the input side */ PV_SIDE_OUT, /* monitor only the output side */ PV_SIDE_BOTH /* monitor both sides */ diff --git a/src/main/options.c b/src/main/options.c index 43177a6..c6e691c 100644 --- a/src/main/options.c +++ b/src/main/options.c @@ -762,6 +762,7 @@ opts_t opts_parse(unsigned int argc, char **argv) numopts = 0; opts->action = PV_ACTION_TRANSFER; + opts->side = PV_SIDE_NONE; opts->interval = 1; opts->delay_start = 0; opts->average_rate_window = 30; @@ -1293,6 +1294,31 @@ opts_t opts_parse(unsigned int argc, char **argv) if (opts->error_skip_block > 0 && 0 == opts->skip_errors) opts->skip_errors = 1; + /* + * Don't allow -R or -Q with -M. + */ + if ((PV_ACTION_MONITOR == opts->action) && ((0 != opts->remote) || (0 != opts->query))) { + /*@-mustfreefresh@ *//* see above */ + fprintf(stderr, "%s: %s: %s\n", opts->program_name, 0 != opts->remote ? "-R" : "-Q", + _("monitor mode cannot be specified with this option")); + opts_free(opts); + return NULL; + /*@+mustfreefresh@ */ + } + + /* + * Don't allow -U with -M. + */ + if ((PV_ACTION_STORE_AND_FORWARD == opts->action && PV_SIDE_NONE != opts->side) + || (PV_ACTION_MONITOR == opts->action && NULL != opts->store_and_forward_file)) { + /*@-mustfreefresh@ *//* see above */ + fprintf(stderr, "%s: %s\n", opts->program_name, + _("monitor mode cannot be used with store-and-forward")); + opts_free(opts); + return NULL; + /*@+mustfreefresh@ */ + } + /* * Don't allow any non-option arguments with -R or -Q. */