From e42a2c9c85e200a59aa82b47768bb8cbbc740565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Myl=C3=A8ne=20Josserand?= Date: Fri, 16 Oct 2020 10:38:11 +0200 Subject: [PATCH] console: Add 'k' option to exit on console-down MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit is adding an option 'k' to make the console application exits when the console is down. This can be useful in some cases such as an integration to LAVA infrastructure. Console can be used to open a terminal on different boards to be able to run some tests. In some cases, the console is down and without this commit, the tests will be timed-out because it can't talk to the device. Adding this option will allow us to exit the console directly, without waiting for a timeout. The benefit will be time saving. Signed-off-by: Mylène Josserand --- console/console.c | 22 +++++++++++++++++++--- console/readconf.h | 1 + 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/console/console.c b/console/console.c index 224f1a8..905eba6 100644 --- a/console/console.c +++ b/console/console.c @@ -1471,8 +1471,13 @@ CallUp(CONSFILE *pcf, char *pcMaster, char *pcMach, char *pcHow, /* try to grok the state of the console */ FilePrint(pcf, FLAGFALSE, "%c%c=", chAttn, chEsc); r = ReadReply(pcf, FLAGFALSE); - if (strncmp(r, "[unknown", 8) != 0 && strncmp(r, "[up]", 4) != 0) - FileWrite(cfstdout, FLAGFALSE, r, -1); + if (strncmp(r, "[unknown", 8) != 0 && strncmp(r, "[up]", 4) != 0) { + FileWrite(cfstdout, FLAGFALSE, r, -1); + if (config->exitdown == FLAGTRUE) { + printf("Device is down. Will exit with option 'k'\n"); + kill(thepid, SIGTERM); + } + } /* try to grok the version of the server */ FilePrint(pcf, FLAGFALSE, "%c%c%c", chAttn, chEsc, 0xD6); @@ -1905,7 +1910,7 @@ main(int argc, char **argv) int fLocal; static STRING *acPorts = (STRING *)0; static char acOpts[] = - "7aAb:B:c:C:d:De:EfFhiIl:M:np:PqQrRsSt:uUvVwWxz:Z:"; + "7aAb:B:c:C:d:De:EfFhikIl:M:np:PqQrRsSt:uUvVwWxz:Z:"; extern int optind; extern int optopt; extern char *optarg; @@ -2035,6 +2040,10 @@ main(int argc, char **argv) pcCmd = "info"; break; + case 'k': + optConf->exitdown = FLAGTRUE; + break; + case 'l': if ((optConf->username = StrDup(optarg)) == (char *)0) OutOfMem(); @@ -2232,6 +2241,13 @@ main(int argc, char **argv) else config->striphigh = FLAGFALSE; + if (optConf->exitdown != FLAGUNKNOWN) + config->exitdown = optConf->exitdown; + else if (pConfig->exitdown != FLAGUNKNOWN) + config->exitdown = pConfig->exitdown; + else + config->exitdown = FLAGFALSE; + if (optConf->escape != (char *)0) ParseEsc(optConf->escape); else if (pConfig->escape != (char *)0) diff --git a/console/readconf.h b/console/readconf.h index 1e9d65d..81f0550 100644 --- a/console/readconf.h +++ b/console/readconf.h @@ -12,6 +12,7 @@ typedef struct config { char *port; char *escape; FLAG striphigh; + FLAG exitdown; unsigned short replay; unsigned short playback; #if HAVE_OPENSSL