Add an action type for query mode, and more TODOs to plan how it will work (#101).
This commit is contained in:
@@ -30,7 +30,8 @@ typedef enum {
|
||||
PV_ACTION_NOTHING, /* do nothing, and exit */
|
||||
PV_ACTION_TRANSFER, /* transfer data */
|
||||
PV_ACTION_STORE_AND_FORWARD, /* store to file, then output from it */
|
||||
PV_ACTION_WATCHFD /* watch process file descriptors */
|
||||
PV_ACTION_WATCHFD, /* watch process file descriptors */
|
||||
PV_ACTION_QUERY /* watch the state of another pv */
|
||||
} pvaction_t;
|
||||
|
||||
/*
|
||||
|
||||
+33
-5
@@ -26,6 +26,8 @@
|
||||
int pv_remote_set(opts_t, pvstate_t);
|
||||
void pv_remote_init(void);
|
||||
void pv_remote_fini(void);
|
||||
// TODO
|
||||
// int pv_remote_transferstate_fetch(pvstate_t, pid_t, /*@null@ */ off_t *);
|
||||
|
||||
/*
|
||||
* Write a PID file, returning nonzero on error. Write it atomically, such
|
||||
@@ -368,8 +370,6 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: add logic for --query mode. */
|
||||
|
||||
/*
|
||||
* If no files were given, pretend "-" was given (stdin).
|
||||
*/
|
||||
@@ -492,6 +492,31 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialise the signal handling. */
|
||||
pv_sig_init(state);
|
||||
|
||||
/*
|
||||
* Get the total size, in query mode.
|
||||
*
|
||||
* Note that this uses signals, so signal handling has to have been
|
||||
* set up first.
|
||||
*/
|
||||
if (PV_ACTION_QUERY == opts->action) {
|
||||
opts->size = 0;
|
||||
// TODO retcode = pv_remote_transferstate_fetch(state, opts->query, &(opts->size));
|
||||
if (0 != retcode) {
|
||||
pv_sig_fini(state);
|
||||
pv_state_free(state);
|
||||
opts_free(opts);
|
||||
return retcode;
|
||||
}
|
||||
/* As above - no ETA if the size is unknown. */
|
||||
if (opts->size < 1) {
|
||||
can_have_eta = false;
|
||||
debug("%s", "size unknown - ETA disabled");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy the remaining parameters from the options into the main
|
||||
* state.
|
||||
@@ -534,9 +559,6 @@ int main(int argc, char **argv)
|
||||
debug("%s: %s", "terminal_supports_utf8", terminal_supports_utf8 ? "true" : "false");
|
||||
pv_state_set_terminal_supports_utf8(state, terminal_supports_utf8);
|
||||
|
||||
/* Initialise the signal handling. */
|
||||
pv_sig_init(state);
|
||||
|
||||
/* Run the appropriate main loop. */
|
||||
switch (opts->action) {
|
||||
case PV_ACTION_NOTHING:
|
||||
@@ -557,6 +579,12 @@ int main(int argc, char **argv)
|
||||
/* "Watch file descriptor(s) of another process" mode. */
|
||||
retcode = pv_watchfd_loop(state);
|
||||
break;
|
||||
case PV_ACTION_QUERY:
|
||||
/* "Watch progress of another pv" mode. */
|
||||
pv_remote_init();
|
||||
/* TODO: loop watching transfer progress until finished. */
|
||||
pv_remote_fini();
|
||||
break;
|
||||
}
|
||||
|
||||
/* Clear up the PID file, if one was written. */
|
||||
|
||||
@@ -999,6 +999,7 @@ opts_t opts_parse(unsigned int argc, char **argv)
|
||||
break;
|
||||
case 'Q':
|
||||
opts->query = (pid_t) pv_getnum_count(optarg, false);
|
||||
opts->action = PV_ACTION_QUERY;
|
||||
break;
|
||||
case 'P':
|
||||
opts->pidfile = pv_strdup(optarg);
|
||||
|
||||
Reference in New Issue
Block a user