Merge branch 'master' into feature_openconfig_compress

This commit is contained in:
Olof Hagsand 2021-10-22 09:23:48 +02:00 committed by GitHub
commit 9d8d9ac042
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
43 changed files with 997 additions and 139 deletions

View file

@ -171,7 +171,7 @@ cli_xml2file(cxobj *xn,
if (xn == NULL)
goto ok;
/* Look for autocli-op defined in clixon-lib.yang */
if (yang_extension_value(xml_spec(xn), "autocli-op", CLIXON_LIB_NS, &opext) < 0) {
if (yang_extension_value(xml_spec(xn), "autocli-op", CLIXON_LIB_NS, NULL, &opext) < 0) {
goto ok;
}
if ((opext != NULL) && ((strcmp(opext, "hide-database") == 0) || (strcmp(opext, "hide-database-auto-completion") == 0))){
@ -273,13 +273,13 @@ cli_xml2txt(cxobj *xn,
clicon_err(OE_XML, EINVAL, "xn or fn is NULL");
goto done;
}
/* Look for autocli-op defined in clixon-lib.yang */
if (yang_extension_value(xml_spec(xn), "autocli-op", CLIXON_LIB_NS, &opext) < 0) {
goto ok;
}
if ((opext != NULL) && ((strcmp(opext, "hide-database") == 0) || (strcmp(opext, "hide-database-auto-completion") == 0))){
goto ok;
}
/* Look for autocli-op defined in clixon-lib.yang */
if (yang_extension_value(xml_spec(xn), "autocli-op", CLIXON_LIB_NS, NULL, &opext) < 0) {
goto ok;
}
if ((opext != NULL) && ((strcmp(opext, "hide-database") == 0) || (strcmp(opext, "hide-database-auto-completion") == 0))){
goto ok;
}
xc = NULL; /* count children (elements and bodies, not attributes) */
while ((xc = xml_child_each(xn, xc, -1)) != NULL)
if (xml_type(xc) == CX_ELMNT || xml_type(xc) == CX_BODY)
@ -342,7 +342,7 @@ cli_xml2cli(cxobj *xn,
if ((ys = xml_spec(xn)) == NULL)
goto ok;
/* Look for autocli-op defined in clixon-lib.yang */
if (yang_extension_value(xml_spec(xn), "autocli-op", CLIXON_LIB_NS, &opext) < 0) {
if (yang_extension_value(xml_spec(xn), "autocli-op", CLIXON_LIB_NS, NULL, &opext) < 0) {
goto ok;
}
if ((opext != NULL) && ((strcmp(opext, "hide-database") == 0) || (strcmp(opext, "hide-database-auto-completion") == 0))){

View file

@ -165,17 +165,17 @@ cli_signal_flush(clicon_handle h)
sigfn_t h1, h2, h3, h4;
set_signal (SIGTSTP, SIG_IGN, &h1);
set_signal (SIGQUIT, SIG_IGN, &h2);
set_signal (SIGCHLD, SIG_IGN, &h3);
set_signal (SIGINT, SIG_IGN, &h4);
set_signal(SIGTSTP, SIG_IGN, &h1);
set_signal(SIGQUIT, SIG_IGN, &h2);
set_signal(SIGCHLD, SIG_IGN, &h3);
set_signal(SIGINT, SIG_IGN, &h4);
cli_signal_unblock (h);
set_signal (SIGTSTP, h1, NULL);
set_signal (SIGQUIT, h2, NULL);
set_signal (SIGCHLD, h3, NULL);
set_signal (SIGINT, h4, NULL);
set_signal(SIGTSTP, h1, NULL);
set_signal(SIGQUIT, h2, NULL);
set_signal(SIGCHLD, h3, NULL);
set_signal(SIGINT, h4, NULL);
cli_signal_block (h);
}
@ -562,9 +562,10 @@ cli_start_shell(clicon_handle h,
int retval = -1;
char bcmd[128];
cg_var *cv1 = cvec_i(vars, 1);
sigset_t oldsigset;
struct sigaction oldsigaction[32] = {0,};
cmd = (cvec_len(vars)>1 ? cv_string_get(cv1) : NULL);
if ((pw = getpwuid(getuid())) == NULL){
clicon_err(OE_UNIX, errno, "getpwuid");
goto done;
@ -575,6 +576,9 @@ cli_start_shell(clicon_handle h,
goto done;
}
endpwent();
if (clixon_signal_save(&oldsigset, oldsigaction) < 0)
goto done;
cli_signal_flush(h);
cli_signal_unblock(h);
if (cmd){
@ -598,6 +602,8 @@ cli_start_shell(clicon_handle h,
goto done;
}
#endif
if (clixon_signal_restore(&oldsigset, oldsigaction) < 0)
goto done;
retval = 0;
done:
return retval;

View file

@ -78,6 +78,7 @@ You can see which CLISPEC it generates via clixon_cli -D 2:
#include <errno.h>
#include <fcntl.h>
#include <syslog.h>
#include <signal.h>
#include <sys/param.h>
/* cligen */
@ -120,7 +121,7 @@ cli_expand_var_generate(clicon_handle h,
int retval = -1;
char *api_path_fmt = NULL, *opext = NULL;
if (yang_extension_value(ys, "autocli-op", CLIXON_LIB_NS, &opext) < 0)
if (yang_extension_value(ys, "autocli-op", CLIXON_LIB_NS, NULL, &opext) < 0)
goto done;
if (opext && strcmp(opext, "hide-database") == 0) {
retval = 1;
@ -761,7 +762,7 @@ yang2cli_leaf(clicon_handle h,
}
cprintf(cb, "%*s", level*3, "");
/* Look for autocli-op defined in clixon-lib.yang */
if (yang_extension_value(ys, "autocli-op", CLIXON_LIB_NS, &opext) < 0)
if (yang_extension_value(ys, "autocli-op", CLIXON_LIB_NS, NULL, &opext) < 0)
goto done;
if (gt == GT_VARS || gt == GT_ALL || gt == GT_HIDE || gt == GT_OC_COMPRESS){
cprintf(cb, "%s", yang_argument_get(ys));
@ -866,14 +867,14 @@ yang2cli_container(clicon_handle h,
if (cli_callback_generate(h, ys, cb) < 0)
goto done;
/* Look for autocli-op defined in clixon-lib.yang */
if (yang_extension_value(ys, "autocli-op", CLIXON_LIB_NS, &opext) < 0)
goto done;
if (opext != NULL && strcmp(opext, "hide") == 0){
cprintf(cb, ",hide");
}
/* Look for autocli-op defined in clixon-lib.yang */
if (yang_extension_value(ys, "autocli-op", CLIXON_LIB_NS, NULL, &opext) < 0)
goto done;
if (opext != NULL && strcmp(opext, "hide") == 0){
cprintf(cb, ",hide");
}
if (opext != NULL && strcmp(opext, "hide-database-auto-completion") == 0){
cprintf(cb, ",hide-database-auto-completion");
cprintf(cb, ",hide-database-auto-completion");
}
cprintf(cb, ";{\n");
}
@ -882,10 +883,10 @@ yang2cli_container(clicon_handle h,
while ((yc = yn_each(ys, yc)) != NULL)
if (yang2cli_stmt(h, yc, gt, level+1, state, show_tree, cb) < 0)
goto done;
if (hide == 0 && hide_oc == 0)
cprintf(cb, "%*s}\n", level*3, "");
retval = 0;
done:
if (hide == 0 && hide_oc == 0)
cprintf(cb, "%*s}\n", level*3, "");
retval = 0;
done:
if (helptext)
free(helptext);
return retval;
@ -933,7 +934,7 @@ yang2cli_list(clicon_handle h,
yang2cli_helptext(cb, helptext);
}
/* Look for autocli-op defined in clixon-lib.yang */
if (yang_extension_value(ys, "autocli-op", CLIXON_LIB_NS, &opext) < 0)
if (yang_extension_value(ys, "autocli-op", CLIXON_LIB_NS, NULL, &opext) < 0)
goto done;
if (opext != NULL && strcmp(opext, "hide") == 0){
cprintf(cb, ",hide");

View file

@ -51,6 +51,7 @@
#include <dlfcn.h>
#include <dirent.h>
#include <grp.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>

View file

@ -52,6 +52,7 @@
#include <dirent.h>
#include <libgen.h>
#include <grp.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
@ -69,7 +70,6 @@
#include "cli_handle.h"
#include "cli_generate.h"
/*
* Constants
*/
@ -522,6 +522,53 @@ cli_handler_err(FILE *f)
return 0;
}
/*! Variant of eval for context checking
* @see cligen_eval
*/
int
cligen_clixon_eval(cligen_handle h,
cg_obj *co,
cvec *cvv)
{
struct cg_callback *cc;
int retval = 0;
cvec *argv;
plugin_context_t *pc = NULL;
if (h)
cligen_co_match_set(h, co);
for (cc = co->co_callbacks; cc; cc=cc->cc_next){
/* Vector cvec argument to callback */
if (cc->cc_fn_vec){
argv = cc->cc_cvec ? cvec_dup(cc->cc_cvec) : NULL;
cligen_fn_str_set(h, cc->cc_fn_str);
if ((pc = plugin_context_get()) == NULL)
break;
if ((retval = (*cc->cc_fn_vec)(
cligen_userhandle(h)?cligen_userhandle(h):h,
cvv,
argv)) < 0){
if (argv != NULL)
cvec_free(argv);
cligen_fn_str_set(h, NULL);
break;
}
if (plugin_context_check(pc, "CLIgen", cc->cc_fn_str) < 0)
break;
if (pc){
free(pc);
pc = NULL;
}
if (argv != NULL)
cvec_free(argv);
cligen_fn_str_set(h, NULL);
}
}
if (pc)
free(pc);
return retval;
}
/*! Evaluate a matched command
* @param[in] h Clicon handle
* @param[in] cmd The command string
@ -541,7 +588,8 @@ clicon_eval(clicon_handle h,
cli_output_reset();
if (!cligen_exiting(cli_cligen(h))) {
clicon_err_reset();
if ((retval = cligen_eval(cli_cligen(h), match_obj, cvv)) < 0) {
if ((retval = cligen_clixon_eval(cli_cligen(h), match_obj, cvv)) < 0) {
#if 0 /* This is removed since we get two error messages on failure.
But maybe only sometime?
Both a real log when clicon_err is called, and the here again.

View file

@ -919,6 +919,7 @@ cli_pagination(clicon_handle h,
uint32_t limit = 0;
cxobj **xvec = NULL;
size_t xlen;
int locked = 0;
if (cvec_len(argv) != 5){
clicon_err(OE_PLUGIN, 0, "Expected usage: <xpath> <prefix> <namespace> <format> <limit>");
@ -950,6 +951,7 @@ cli_pagination(clicon_handle h,
goto done;
if (clicon_rpc_lock(h, "running") < 0)
goto done;
locked++;
for (i = 0;; i++){
if (clicon_rpc_get_pageable_list(h, "running", xpath, nsc,
CONTENT_ALL,
@ -1000,10 +1002,10 @@ cli_pagination(clicon_handle h,
xvec = NULL;
}
} /* for i */
if (clicon_rpc_unlock(h, "running") < 0)
goto done;
retval = 0;
done:
if (locked)
clicon_rpc_unlock(h, "running");
if (xvec)
free(xvec);
if (xret)