Add a batch mode, where the commands are taken from the command line instead of the standard input.
Signed-off-by: Ethel <ethel.nils...@est.tech> --- nsm.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/nsm.c b/nsm.c index 0fb73fb..36b0872 100644 --- a/nsm.c +++ b/nsm.c @@ -490,7 +490,7 @@ static void usage(char *progname) int main(int argc, char *argv[]) { char *cmd = NULL, *config = NULL, line[1024], *progname; - int c, cnt, err = 0, index, length, tmo = -1; + int c, cnt, err = 0, index, length, tmo = -1, batch_mode = 0; struct pollfd pollfd[NSM_NFD]; struct nsm *nsm = &the_nsm; struct ptp_message *msg; @@ -559,14 +559,31 @@ int main(int argc, char *argv[]) if (err) { goto out; } + + if (optind < argc) { + batch_mode = 1; + } + pollfd[0].fd = nsm->fda.fd[0]; pollfd[1].fd = nsm->fda.fd[1]; - pollfd[2].fd = STDIN_FILENO; + pollfd[2].fd = batch_mode ? -1 : STDIN_FILENO; pollfd[0].events = POLLIN | POLLPRI; pollfd[1].events = POLLIN | POLLPRI; - pollfd[2].events = POLLIN | POLLPRI; + pollfd[2].events = batch_mode ? 0 : POLLIN | POLLPRI; while (is_running()) { + if (batch_mode) { + if (optind < argc && !nsm->nsm_delay_req) { + cmd = argv[optind++]; + if (nsm_command(nsm, cmd)) { + pr_err("command failed"); + continue; + } + } + /* Wait a bit for any outstanding replies. */ + tmo = 100; + } + cnt = poll(pollfd, NSM_NFD, tmo); if (cnt < 0) { if (EINTR == errno) { @@ -576,6 +593,11 @@ int main(int argc, char *argv[]) err = -1; break; } + } else if (!cnt && optind < argc) { + /* For batch mode. No response received from target node, + * continue with next command. */ + nsm_reset(nsm); + continue; } else if (!cnt) { break; } -- 1.8.3.1 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel