Merge branch 'wrap_process'

This commit is contained in:
Andrew Wood
2026-04-04 13:30:50 +01:00
14 changed files with 847 additions and 87 deletions
+7
View File
@@ -51,3 +51,10 @@ typedef bool _Bool;
#define PV_REMOTE_CONTROL 1
# endif
#endif
#ifndef SPLINT
/* Remove __attribute__(()) if not using GCC. */
#ifndef __GNUC__
#define __attribute__(x) /* GCC-only feature */
#endif
#endif
+19 -2
View File
@@ -32,9 +32,22 @@ typedef enum {
PV_ACTION_STORE_AND_FORWARD, /* store to file, then output from it */
PV_ACTION_WATCHFD, /* watch process file descriptors */
PV_ACTION_REMOTE_CONTROL, /* remotely control another pv */
PV_ACTION_QUERY /* watch the state of another pv */
PV_ACTION_QUERY, /* watch the state of another pv */
PV_ACTION_MONITOR /* run a process, watch its stdin/out */
} pvaction_t;
/*
* 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 */
} pvside_t;
typedef /*@null@*/ const char * argv_string;
/*
* Structure describing run-time options.
*
@@ -46,14 +59,16 @@ struct opts_s {
/*@keep@*/ const char *program_name; /* name the program is running as */
/*@keep@*/ /*@null@*/ char *output; /* fd to write output to */
/*@keep@*/ /*@null@*/ char *name; /* display name, if any */
/*@keep@*/ /*@null@*/ char *name1; /* first name, if two were given */
/*@keep@*/ /*@null@*/ char *default_bar_style; /* default bar style */
/*@keep@*/ /*@null@*/ char *format; /* output format, if any */
/*@keep@*/ /*@null@*/ char *format1; /* first format, if two were given */
/*@keep@*/ /*@null@*/ char *pidfile; /* PID file, if any */
/*@keep@*/ /*@null@*/ char *store_and_forward_file; /* store and forward file, if any */
/*@keep@*/ /*@null@*/ char *extra_display; /* extra display specifier, if any */
/*@keep@*/ /*@null@*/ pid_t *watchfd_pid; /* array of processes to watch fds of */
/*@keep@*/ /*@null@*/ int *watchfd_fd; /* array of fds to watch in each one (0=all) */
/*@keep@*/ /*@null@*/ const char **argv; /* array of non-option arguments */
/*@keep@*/ /*@null@*/ argv_string *argv; /* array of non-option arguments */
size_t lastwritten; /* show N bytes last written */
off_t rate_limit; /* rate limit, in bytes per second */
size_t buffer_size; /* buffer size, in bytes (0=default) */
@@ -70,6 +85,7 @@ struct opts_s {
unsigned int watchfd_count; /* number of watchfd items */
unsigned int watchfd_length; /* allocated array size */
pvaction_t action; /* the program action to perform */
pvside_t side; /* which side of the monitored command to monitor */
bool progress; /* progress bar flag */
bool timer; /* timer flag */
bool eta; /* ETA flag */
@@ -77,6 +93,7 @@ struct opts_s {
bool rate; /* rate counter flag */
bool average_rate; /* average rate counter flag */
bool bytes; /* bytes transferred flag */
bool ratio; /* in:out ratio flag */
bool bits; /* report transfer size in bits */
bool decimal_units; /* decimal prefix flag */
bool bufpercent; /* transfer buffer percentage flag */
+9 -11
View File
@@ -26,6 +26,7 @@ extern "C" {
#define RATE_GRANULARITY 100000000 /* nsec between -L rate chunks */
#define RATE_BURST_WINDOW 5 /* rate burst window (multiples of rate) */
#define REMOTE_INTERVAL 100000000 /* nsec between checks for -R and -Q */
#define MONITOR_EXCHANGE_INTERVAL 100000000 /* nsec between "-M both" data exchanges */
#define BUFFER_SIZE (size_t) 409600 /* default transfer buffer size */
#define BUFFER_SIZE_MAX (size_t) 524288 /* max auto transfer buffer size */
#define MAX_READ_AT_ONCE (size_t) 524288 /* max to read() in one go */
@@ -201,22 +202,15 @@ struct pvstate_s {
off_t size; /* total size of data */
unsigned int skip_errors; /* skip read errors counter */
int output_fd; /* fd to write output to */
pid_t othermonitor_pid; /* pid of the other monitor, in "-M both" mode */
int othermonitor_read_fd; /* fd to read transfer counts from other monitor */
int othermonitor_write_fd; /* fd to write transfer counts to other monitor */
unsigned int average_rate_window; /* time window in seconds for average rate calculations */
unsigned int history_interval; /* seconds between each average rate calc history entry */
pvdisplay_width_t width; /* screen width */
unsigned int height; /* screen height */
unsigned int extra_displays; /* bitmask of extra display destinations */
struct { /* old-style format options (used by -R) */
size_t lastwritten; /* --last-written (amount) */
bool progress; /* --progress */
bool timer; /* --timer */
bool eta; /* --eta */
bool fineta; /* --fineta */
bool rate; /* --rate */
bool average_rate; /* --average-rate */
bool bytes; /* --bytes */
bool bufpercent; /* --buffer-percent */
} format_option;
pvformatoptions_s format_option; /* old-style format options (used by -R) */
bool force; /* display even if not on terminal */
bool cursor; /* use cursor positioning */
bool numeric; /* numeric output only */
@@ -324,6 +318,7 @@ struct pvstate_s {
bool showing_timer; /* set if showing timer */
bool showing_bytes; /* set if showing byte/line count */
bool showing_ratio; /* set if showing monitoring in:out ratio */
bool showing_rate; /* set if showing transfer rate */
bool showing_last_written; /* set if displaying the last few bytes written */
bool showing_previous_line; /* set if displaying the previously output line */
@@ -427,6 +422,8 @@ struct pvstate_s {
off_t total_written; /* total bytes or lines written */
off_t transferred; /* amount transferred (written - unconsumed) */
off_t otherside_transferred; /* amount transferred by the other side ("-M both") */
/* Keep track of line positions to backtrack written_but_not_consumed. */
/*@only@*/ /*@null@*/ off_t *line_positions; /* line separator write positions (circular buffer) */
size_t line_positions_capacity; /* total size of line position array */
@@ -606,6 +603,7 @@ pvdisplay_bytecount_t pv_formatter_fineta(pvformatter_args_t);
pvdisplay_bytecount_t pv_formatter_rate(pvformatter_args_t);
pvdisplay_bytecount_t pv_formatter_average_rate(pvformatter_args_t);
pvdisplay_bytecount_t pv_formatter_bytes(pvformatter_args_t);
pvdisplay_bytecount_t pv_formatter_ratio(pvformatter_args_t);
pvdisplay_bytecount_t pv_formatter_buffer_percent(pvformatter_args_t);
pvdisplay_bytecount_t pv_formatter_last_written(pvformatter_args_t);
pvdisplay_bytecount_t pv_formatter_previous_line(pvformatter_args_t);
+20 -8
View File
@@ -29,6 +29,7 @@ extern "C" {
*/
#define PV_ERROREXIT_REMOTE_OR_PID 1
#define PV_ERROREXIT_SAF 1 /* store and forward error */
#define PV_ERROREXIT_MONITOR 1 /* monitor mode error */
#define PV_ERROREXIT_ACCESS 2
#define PV_ERROREXIT_OUROBOROS 4
#define PV_ERROREXIT_TRANSITION 8
@@ -192,15 +193,24 @@ extern /*@null@*/ /*@only@*/ pvstate_t pv_state_alloc(void);
extern void pv_state_reset(pvstate_t state);
/*
* Set the formatting string, given a set of old-style formatting options.
* Set the format options and use them to build a default formatting string.
* The default string is used if no format string is explicitly set.
*/
extern void pv_state_set_format(pvstate_t state, bool progress,
bool timer, bool eta,
bool fineta, bool rate,
bool average_rate, bool bytes,
bool bufpercent,
size_t lastwritten,
/*@null@*/ const char *name);
typedef struct {
size_t lastwritten; /* --last-written (amount) */
bool progress; /* --progress */
bool timer; /* --timer */
bool eta; /* --eta */
bool fineta; /* --fineta */
bool rate; /* --rate */
bool average_rate; /* --average-rate */
bool bytes; /* --bytes */
bool bufpercent; /* --buffer-percent */
} pvformatoptions_s;
extern void pv_state_set_format_options(pvstate_t, pvformatoptions_s);
/* Append a string to the default format. */
void pv_state_append_to_default_format(pvstate_t, /*@null@ */ const char *);
/*
* Set the various options.
@@ -238,6 +248,8 @@ extern void pv_state_extra_display_set(pvstate_t, /*@null@*/ const char *);
extern void pv_state_output_set(pvstate_t, int, const char *);
extern void pv_state_average_rate_window_set(pvstate_t, unsigned int);
extern void pv_state_set_terminal_supports_utf8(pvstate_t, bool);
extern void pv_state_othermonitor_set(pvstate_t, pid_t, int, int);
extern void pv_state_cancel_output_if_empty_format_string(pvstate_t);
extern void pv_state_inputfiles(pvstate_t, unsigned int, const char **);
extern void pv_state_watchfds(pvstate_t, unsigned int, const pid_t *, const int *);