* CLI reconnects to backend if backend restarts with a warning

* Note that edits to the candidate database or locks will be lost
  * To force the CLI to exit if backend restarts, undef `PROTO_RESTART_RECONNECT`
  * This is an effect of the fix of [Broken pipe error seen in client (cli) when backend restarts and CLICON_SOCK is recreated](https://github.com/clicon/clixon/issues/312), the CLI behavior on backend restart is changed.
* Added `eof` parameter to `clicon_rpc()` and `clicon_rpc1()` and error handling modified
This commit is contained in:
Olof hagsand 2022-03-16 18:30:21 +01:00
parent 03f667e2ea
commit dfeb7cef75
10 changed files with 176 additions and 56 deletions

View file

@ -204,11 +204,23 @@ cli_sig_term(int arg)
/*! Setup signal handlers
*/
static void
static int
cli_signal_init (clicon_handle h)
{
cli_signal_block(h);
set_signal(SIGTERM, cli_sig_term, NULL);
int retval = -1;
cli_signal_block(h);
if (set_signal(SIGTERM, cli_sig_term, NULL) < 0){
clicon_err(OE_UNIX, errno, "Setting SIGTERM signal");
goto done;
}
if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){
clicon_err(OE_UNIX, errno, "Setting DIGPIPE signal");
goto done;
}
retval = 0;
done:
return retval;
}
/*! Interactive CLI command loop
@ -653,7 +665,8 @@ main(int argc,
clicon_log_string_limit_set(nr);
/* Setup signal handlers */
cli_signal_init(h);
if (cli_signal_init(h) < 0)
goto done;
/* Backward compatible mode, do not include keys in cgv-arrays in callbacks.
Should be 0 but default is 1 since all legacy apps use 1

View file

@ -606,8 +606,11 @@ clicon_parse(clicon_handle h,
cli_output_reset();
if (!cligen_exiting(ch)) {
clicon_err_reset();
if ((ret = cligen_eval(ch, match_obj, cvv, callbacks)) < 0)
if ((ret = cligen_eval(ch, match_obj, cvv, callbacks)) < 0) {
cli_handler_err(stdout);
if (clicon_suberrno == ESHUTDOWN)
goto done;
}
}
else
ret = 0;

View file

@ -602,6 +602,23 @@ netconf_terminate(clicon_handle h)
return 0;
}
/*! Setup signal handlers
*/
static int
netconf_signal_init (clicon_handle h)
{
int retval = -1;
if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){
clicon_err(OE_UNIX, errno, "Setting DIGPIPE signal");
goto done;
}
retval = 0;
done:
return retval;
}
static int
timeout_fn(int s,
void *arg)
@ -804,6 +821,10 @@ main(int argc,
if (netconf_module_features(h) < 0)
goto done;
/* Setup signal handlers, int particular PIPE that occurs if backend closes / restarts */
if (netconf_signal_init(h) < 0)
goto done;
/* Initialize plugin module by creating a handle holding plugin and callback lists */
if (clixon_plugin_module_init(h) < 0)
goto done;