From eacf76b7b9074f4bb816be747e8d21c32d81cc84 Mon Sep 17 00:00:00 2001 From: Bjorn Andersson Date: Fri, 30 Nov 2018 11:32:34 -0800 Subject: [PATCH] cdba: Support inactivity timeout In addition to have a fixed timeout (-t) introduce a new inactivity timeout (-T) which allow us to provide a shorter timeout to quickly abort when the kernel fails to boot but still allow us to run lengthy test scripts without getting a timeout. Signed-off-by: Bjorn Andersson --- cdba.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/cdba.c b/cdba.c index 6045547..cd54857 100644 --- a/cdba.c +++ b/cdba.c @@ -459,12 +459,15 @@ static void usage(void) { extern const char *__progname; - fprintf(stderr, "usage: %s -b -h boot.img\n", __progname); + fprintf(stderr, "usage: %s -b -h [-t ] " + "[-T ] boot.img\n", + __progname); exit(1); } int main(int argc, char **argv) { + bool timeout_on_inactivity = false; struct termios *orig_tios; struct work *next; struct work *work; @@ -484,7 +487,7 @@ int main(int argc, char **argv) int opt; int ret; - while ((opt = getopt(argc, argv, "b:c:h:t:")) != -1) { + while ((opt = getopt(argc, argv, "b:c:h:t:T:")) != -1) { switch (opt) { case 'b': board = optarg; @@ -498,6 +501,10 @@ int main(int argc, char **argv) case 't': timeout = atoi(optarg); break; + case 'T': + timeout = atoi(optarg); + timeout_on_inactivity = true; + break; default: usage(); } @@ -568,7 +575,11 @@ int main(int argc, char **argv) if (ret < 0) { err(1, "select"); } else if (ret == 0) { - warnx("timeout reached"); + if (timeout_on_inactivity) + warnx("timeout due to inactivity"); + else + warnx("timeout reached"); + reached_timeout = true; } @@ -605,6 +616,12 @@ int main(int argc, char **argv) n = handle_message(&recv_buf); if (n < 0) break; + + /* Reset inactivity timeout on activity */ + if (timeout_on_inactivity) { + tv.tv_sec = timeout; + tv.tv_usec = 0; + } } if (FD_ISSET(ssh_fds[0], &wfds)) {