diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fdc9955..2d028621 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,8 @@ Users may have to change how they access the system ### Minor features +* Restconf internal start: fail early if clixon_restconf binary is not found + * If CLICON_BACKEND_RESTCONF_PROCESS is true * Added linenumbers to all YANG symbols for better debug and errors * Improved error messages for YANG identityref:s and leafref:s by adding original line numbers diff --git a/apps/backend/backend_plugin_restconf.c b/apps/backend/backend_plugin_restconf.c index fe39c8c5..aef1df7b 100644 --- a/apps/backend/backend_plugin_restconf.c +++ b/apps/backend/backend_plugin_restconf.c @@ -45,6 +45,7 @@ #include #include #include +#include /* cligen */ #include @@ -240,12 +241,14 @@ restconf_rpc_wrapper(clicon_handle h, static int restconf_pseudo_process_control(clicon_handle h) { - int retval = -1; - char **argv = NULL; - int i; - int nr; - cbuf *cb = NULL; - char *dir = NULL; + int retval = -1; + char **argv = NULL; + int i; + int nr; + cbuf *cb = NULL; + char *dir = NULL; + char *pgm; + struct stat fstat; nr = 10; if ((argv = calloc(nr, sizeof(char *))) == NULL){ @@ -269,7 +272,15 @@ restconf_pseudo_process_control(clicon_handle h) } } cprintf(cb, "%s/clixon_restconf", dir); - argv[i++] = cbuf_get(cb); + pgm = cbuf_get(cb); + /* Sanity check: program exists */ + if (stat(pgm, &fstat) < 0) { + clicon_err(OE_FATAL, errno, "%s, you may have set CLICON_BACKEND_RESTCONF_PROCESS but clixon_restconf is not found in %s. Try overriding with CLICON_RESTCONF_INSTALLDIR", + pgm, + CLIXON_CONFIG_SBINDIR); + goto done; + } + argv[i++] = pgm; argv[i++] = "-f"; argv[i++] = clicon_option_str(h, "CLICON_CONFIGFILE"); /* Add debug if backend has debug. diff --git a/lib/src/clixon_proc.c b/lib/src/clixon_proc.c index 8c51b6e1..812daed7 100644 --- a/lib/src/clixon_proc.c +++ b/lib/src/clixon_proc.c @@ -98,6 +98,7 @@ #ifdef HAVE_SETNS /* linux network namespaces */ #include /* setns / unshare */ #endif +#include #include #include #include @@ -271,6 +272,7 @@ clixon_proc_background(char **argv, sigfn_t oldhandler = NULL; sigset_t oset; struct rlimit rlim = {0, }; + struct stat fstat; clicon_debug(1, "%s", __FUNCTION__); if (argv == NULL){ @@ -284,6 +286,11 @@ clixon_proc_background(char **argv, i++; } } + /* Sanity check: program exists */ + if (stat(argv[0], &fstat) < 0) { + clicon_err(OE_FATAL, errno, "%s", argv[0]); + goto quit; + } /* Before here call quit on error */ sigprocmask(0, NULL, &oset); set_signal(SIGINT, clixon_proc_sigint, &oldhandler); diff --git a/test/lib.sh b/test/lib.sh index faee3d50..24288c48 100755 --- a/test/lib.sh +++ b/test/lib.sh @@ -147,7 +147,7 @@ fi #: ${OPENCONFIG=$(pwd)/public} # just skip if not set # Standard IETF RFC yang files. -: ${IETFRFC=../yang/standard} +: ${IETFRFC=../yang/mandatory} # Some restconf tests can run IPv6, but its complicated because: # - docker by default does not run IPv6 diff --git a/test/test_restconf_internal.sh b/test/test_restconf_internal.sh index 78382002..336c9452 100755 --- a/test/test_restconf_internal.sh +++ b/test/test_restconf_internal.sh @@ -485,6 +485,9 @@ new "kill restconf" sleep $DEMSLEEP stop_restconf +new "Start backend with wrong restconf bindir" +expectpart "$(sudo $clixon_backend -Fs init -f $cfg -l o -o CLICON_RESTCONF_INSTALLDIR=/usr/local/xxxx)" 255 "FATAL: /usr/local/xxxx/clixon_restconf" "No such file or directory" + new "endtest" endtest