--- libaitcli/src/aitcli.c 2013/11/20 16:40:02 1.11 +++ libaitcli/src/aitcli.c 2013/11/22 15:17:22 1.12 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitcli.c,v 1.11 2013/11/20 16:40:02 misho Exp $ +* $Id: aitcli.c,v 1.12 2013/11/22 15:17:22 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -1267,11 +1267,10 @@ cliInitLine(linebuffer_t * __restrict cli_buffer) * * @cli_buffer = CLI buffer * @timeout = Session timeout (-1 infinit) - * @cmd_name = If timeout reached, we should call with this cmd_name (default name is "exit") * return: NULL if error or !=NULL readed line, must be e_free after use! */ char * -cliReadLine(linebuffer_t * __restrict cli_buffer, int timeout, const char *cmd_name) +cliReadLine(linebuffer_t * __restrict cli_buffer, int timeout) { int code, readLen, ret; register int i; @@ -1292,9 +1291,11 @@ cliReadLine(linebuffer_t * __restrict cli_buffer, int while (42) { if ((ret = poll(&fds, 1, timeout)) < 1) { if (!ret) { - if (str) + cli_buffer->line_kill = 1; + if (str) { e_free(str); - str = e_strdup(cmd_name ? cmd_name : "exit"); + str = NULL; + } } else LOGERR; return str; @@ -1352,12 +1353,11 @@ recheck: * @csHistFile = History file name * @sock = client socket * @timeout = Session timeout (-1 infinit) - * @cmd_name = If timeout reached, we should call with this cmd_name (default name is "exit") * return: RETCODE_ERR error, RETCODE_OK ok */ int cliNetLoop(linebuffer_t * __restrict cli_buffer, const char *csHistFile, - int sock, int timeout, const char *cmd_name) + int sock, int timeout) { u_char buf[BUFSIZ]; int pid, stat, pty, r, s, alen, flg, attrlen = 0, ret = 0; @@ -1376,7 +1376,7 @@ cliNetLoop(linebuffer_t * __restrict cli_buffer, const } else close(sock); - ret = cliLoop(cli_buffer, csHistFile, timeout, cmd_name) < 0 ? 1 : 0; + ret = cliLoop(cli_buffer, csHistFile, timeout) < 0 ? 1 : 0; cliEnd(cli_buffer); _exit(ret); @@ -1470,12 +1470,10 @@ cliNetLoop(linebuffer_t * __restrict cli_buffer, const * @cli_buffer = CLI buffer * @csHistFile = History file name * @timeout = Session timeout (-1 infinit) - * @cmd_name = If timeout reached, we should call with this cmd_name (default name is "exit") * return: RETCODE_ERR error, RETCODE_OK ok */ int -cliLoop(linebuffer_t * __restrict cli_buffer, const char *csHistFile, - int timeout, const char *cmd_name) +cliLoop(linebuffer_t * __restrict cli_buffer, const char *csHistFile, int timeout) { char *line, *s, *t, **app, *items[MAX_PROMPT_ITEMS]; register int i; @@ -1489,7 +1487,7 @@ cliLoop(linebuffer_t * __restrict cli_buffer, const ch return RETCODE_ERR; do { - line = cliReadLine(cli_buffer, timeout, cmd_name); + line = cliReadLine(cli_buffer, timeout); if (!line) { printfNL(cli_buffer, 0); break; @@ -1535,7 +1533,7 @@ cliLoop(linebuffer_t * __restrict cli_buffer, const ch cli_freeLine(cli_buffer); cli_resetHistory(cli_buffer); e_free(line); - } while (ret < 1); + } while (cli_buffer->line_kill || ret < 1); cli_saveHistory(cli_buffer, csHistFile, HISTORY_LINES); return ret;