Replace watch_pid, watch_fd with arrays, though for now only use the first item in the arrays (#12).
This commit is contained in:
@@ -59,8 +59,6 @@ struct opts_s {
|
||||
off_t error_skip_block; /* skip block size, 0 for adaptive */
|
||||
pid_t remote; /* PID of pv to update settings of */
|
||||
unsigned int skip_errors; /* skip read errors counter */
|
||||
pid_t watch_pid; /* process to watch fds of */
|
||||
int watch_fd; /* fd to watch */
|
||||
unsigned int average_rate_window; /* time window in seconds for average rate calculations */
|
||||
unsigned int width; /* screen width */
|
||||
unsigned int height; /* screen height */
|
||||
|
||||
@@ -185,10 +185,7 @@ struct pvstate_s {
|
||||
off_t rate_limit; /* rate limit, in bytes per second */
|
||||
size_t target_buffer_size; /* buffer size (0=default) */
|
||||
off_t size; /* total size of data */
|
||||
/* TODO: replace watch_pid, watch_fd with arrays (#12) */
|
||||
pid_t watch_pid; /* process to watch fds of */
|
||||
unsigned int skip_errors; /* skip read errors counter */
|
||||
int watch_fd; /* fd to watch */
|
||||
int output_fd; /* fd to write output to */
|
||||
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 */
|
||||
|
||||
@@ -233,8 +233,6 @@ extern void pv_state_name_set(pvstate_t, /*@null@*/ const char *);
|
||||
extern void pv_state_default_bar_style_set(pvstate_t, /*@null@ */ const char *);
|
||||
extern void pv_state_format_string_set(pvstate_t, /*@null@*/ const char *);
|
||||
extern void pv_state_extra_display_set(pvstate_t, /*@null@*/ const char *);
|
||||
extern void pv_state_watch_pid_set(pvstate_t, pid_t);
|
||||
extern void pv_state_watch_fd_set(pvstate_t, int);
|
||||
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);
|
||||
|
||||
+2
-4
@@ -518,8 +518,6 @@ int main(int argc, char **argv)
|
||||
pv_state_default_bar_style_set(state, opts->default_bar_style);
|
||||
pv_state_format_string_set(state, opts->format);
|
||||
pv_state_extra_display_set(state, opts->extra_display);
|
||||
pv_state_watch_pid_set(state, opts->watch_pid);
|
||||
pv_state_watch_fd_set(state, opts->watch_fd);
|
||||
pv_state_average_rate_window_set(state, opts->average_rate_window);
|
||||
|
||||
pv_state_set_format(state, opts->progress, opts->timer, can_have_eta ? opts->eta : false,
|
||||
@@ -549,10 +547,10 @@ int main(int argc, char **argv)
|
||||
pv_remote_fini();
|
||||
break;
|
||||
case PV_ACTION_WATCHFD:
|
||||
if (-1 == opts->watch_fd) {
|
||||
if ((opts->watchfd_count > 0) && (NULL != opts->watchfd_fd) && (-1 == opts->watchfd_fd[0])) {
|
||||
/* "Watch all file descriptors of another process" mode. */
|
||||
retcode = pv_watchpid_loop(state);
|
||||
} else if (-1 != opts->watch_fd) {
|
||||
} else if ((opts->watchfd_count > 0) && (NULL != opts->watchfd_fd) && (-1 != opts->watchfd_fd[0])) {
|
||||
/* "Watch a specific file descriptor of another process" mode. */
|
||||
retcode = pv_watchfd_loop(state);
|
||||
}
|
||||
|
||||
@@ -413,8 +413,6 @@ opts_t opts_parse(unsigned int argc, char **argv)
|
||||
opts->action = PV_ACTION_TRANSFER;
|
||||
opts->interval = 1;
|
||||
opts->delay_start = 0;
|
||||
opts->watch_pid = 0;
|
||||
opts->watch_fd = -1;
|
||||
opts->average_rate_window = 30;
|
||||
|
||||
opts->width_set_manually = false;
|
||||
@@ -714,8 +712,6 @@ opts_t opts_parse(unsigned int argc, char **argv)
|
||||
parse_fd = -1;
|
||||
/* No syntax check here, already done earlier */
|
||||
(void) sscanf(optarg, "%u:%d", &parse_pid, &parse_fd);
|
||||
opts->watch_pid = (pid_t) parse_pid;
|
||||
opts->watch_fd = parse_fd;
|
||||
if (!opts_add_watchfd(opts, (pid_t) parse_pid, parse_fd)) {
|
||||
opts_free(opts);
|
||||
return NULL;
|
||||
|
||||
+28
-14
@@ -584,9 +584,9 @@ int pv_main_loop(pvstate_t state)
|
||||
|
||||
|
||||
/*
|
||||
* Watch the progress of file descriptor state->control.watch_fd in process
|
||||
* state->control.watch_pid and show details about the transfer on standard error
|
||||
* according to the given options.
|
||||
* Watch the progress of file descriptor state->watchfd.fd[0] in process
|
||||
* state->watch_fd.pid[0] and show details about the transfer on standard
|
||||
* error according to the given options.
|
||||
*
|
||||
* Returns nonzero on error.
|
||||
*
|
||||
@@ -601,9 +601,17 @@ int pv_watchfd_loop(pvstate_t state)
|
||||
bool ended, first_check;
|
||||
int rc;
|
||||
|
||||
/* If there's nothing to watch - do nothing. */
|
||||
if (state->watchfd.count < 1)
|
||||
return 0;
|
||||
if (NULL == state->watchfd.pid)
|
||||
return PV_ERROREXIT_MEMORY;
|
||||
if (NULL == state->watchfd.fd)
|
||||
return PV_ERROREXIT_MEMORY;
|
||||
|
||||
memset(&info, 0, sizeof(info));
|
||||
info.watch_pid = state->control.watch_pid;
|
||||
info.watch_fd = state->control.watch_fd;
|
||||
info.watch_pid = state->watchfd.pid[0];
|
||||
info.watch_fd = state->watchfd.fd[0];
|
||||
pv_reset_watchfd(&info);
|
||||
rc = pv_watchfd_info(state, &info, false);
|
||||
if (0 != rc) {
|
||||
@@ -748,9 +756,9 @@ int pv_watchfd_loop(pvstate_t state)
|
||||
|
||||
|
||||
/*
|
||||
* Watch the progress of all file descriptors in process state->control.watch_pid
|
||||
* and show details about the transfers on standard error according to the
|
||||
* given options.
|
||||
* Watch the progress of all file descriptors in process
|
||||
* state->watchfd.pid[0] and show details about the transfers on standard
|
||||
* error according to the given options.
|
||||
*
|
||||
* Replaces format_string in "state" so that starts with "%N " if it doesn't
|
||||
* already do so.
|
||||
@@ -775,12 +783,18 @@ int pv_watchpid_loop(pvstate_t state)
|
||||
* explicitly terminated with \0.
|
||||
*/
|
||||
|
||||
/* If there's nothing to watch - do nothing. */
|
||||
if (state->watchfd.count < 1)
|
||||
return 0;
|
||||
if (NULL == state->watchfd.pid)
|
||||
return PV_ERROREXIT_MEMORY;
|
||||
|
||||
/*
|
||||
* Make sure the process exists first, so we can give an error if
|
||||
* it's not there at the start.
|
||||
*/
|
||||
if (kill(state->control.watch_pid, 0) != 0) {
|
||||
pv_error("%s %u: %s", _("pid"), state->control.watch_pid, strerror(errno));
|
||||
if (kill(state->watchfd.pid[0], 0) != 0) {
|
||||
pv_error("%s %u: %s", _("pid"), state->watchfd.pid[0], strerror(errno));
|
||||
state->status.exit_status |= PV_ERROREXIT_ACCESS;
|
||||
return PV_ERROREXIT_ACCESS;
|
||||
}
|
||||
@@ -837,9 +851,9 @@ int pv_watchpid_loop(pvstate_t state)
|
||||
|
||||
pv_elapsedtime_read(&cur_time);
|
||||
|
||||
if (kill(state->control.watch_pid, 0) != 0) {
|
||||
if (kill(state->watchfd.pid[0], 0) != 0) {
|
||||
if (first_pass) {
|
||||
pv_error("%s %u: %s", _("pid"), state->control.watch_pid, strerror(errno));
|
||||
pv_error("%s %u: %s", _("pid"), state->watchfd.pid[0], strerror(errno));
|
||||
state->status.exit_status |= PV_ERROREXIT_ACCESS;
|
||||
if (NULL != info_array)
|
||||
free(info_array);
|
||||
@@ -887,10 +901,10 @@ int pv_watchpid_loop(pvstate_t state)
|
||||
}
|
||||
}
|
||||
|
||||
rc = pv_watchpid_scanfds(state, state->control.watch_pid, &array_length, &info_array, fd_to_idx);
|
||||
rc = pv_watchpid_scanfds(state, state->watchfd.pid[0], &array_length, &info_array, fd_to_idx);
|
||||
if (rc != 0) {
|
||||
if (first_pass) {
|
||||
pv_error("%s %u: %s", _("pid"), state->control.watch_pid, strerror(errno));
|
||||
pv_error("%s %u: %s", _("pid"), state->watchfd.pid[0], strerror(errno));
|
||||
state->status.exit_status |= PV_ERROREXIT_ACCESS;
|
||||
if (NULL != info_array)
|
||||
free(info_array);
|
||||
|
||||
+1
-12
@@ -187,8 +187,7 @@ pvstate_t pv_state_alloc(void)
|
||||
return NULL;
|
||||
memset(state, 0, sizeof(*state));
|
||||
|
||||
state->control.watch_pid = 0;
|
||||
state->control.watch_fd = -1;
|
||||
state->watchfd.count = 0;
|
||||
state->control.output_fd = -1;
|
||||
#ifdef HAVE_IPC
|
||||
state->cursor.shmid = -1;
|
||||
@@ -619,16 +618,6 @@ void pv_state_extra_display_set(pvstate_t state, /*@null@ */ const char *val)
|
||||
}
|
||||
}
|
||||
|
||||
void pv_state_watch_pid_set(pvstate_t state, pid_t val)
|
||||
{
|
||||
state->control.watch_pid = val;
|
||||
}
|
||||
|
||||
void pv_state_watch_fd_set(pvstate_t state, int val)
|
||||
{
|
||||
state->control.watch_fd = val;
|
||||
}
|
||||
|
||||
void pv_state_output_set(pvstate_t state, int fd, const char *name)
|
||||
{
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user