/* * ***** BEGIN LICENSE BLOCK ***** Copyright (C) 2009-2019 Olof Hagsand and Benny Holmgren This file is part of CLIXON. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Alternatively, the contents of this file may be used under the terms of the GNU General Public License Version 3 or later (the "GPL"), in which case the provisions of the GPL are applicable instead of those above. If you wish to allow use of your version of this file only under the terms of the GPL, and not to allow others to use your version of this file under the terms of Apache License version 2, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL. If you do not delete the provisions above, a recipient may use your version of this file under the terms of any one of the Apache License version 2 or the GPL. ***** END LICENSE BLOCK ***** */ #ifdef HAVE_CONFIG_H #include "clixon_config.h" /* generated by config & autoconf */ #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* cligen */ #include /* clicon */ #include #include "clixon_backend_handle.h" #include "backend_socket.h" #include "backend_client.h" #include "backend_commit.h" #include "backend_plugin.h" #include "backend_handle.h" /* Command line options to be passed to getopt(3) */ #define BACKEND_OPTS "hD:f:l:d:p:b:Fza:u:P:1s:c:g:y:x:o:" #define BACKEND_LOGFILE "/usr/local/var/clixon_backend.log" /*! Clean and close all state of backend (but dont exit). * Cannot use h after this * @param[in] h Clixon handle */ static int backend_terminate(clicon_handle h) { yang_spec *yspec; char *pidfile = clicon_backend_pidfile(h); int sockfamily = clicon_sock_family(h); char *sockpath = clicon_sock(h); cxobj *x; struct stat st; int ss; clicon_debug(1, "%s", __FUNCTION__); if ((ss = clicon_socket_get(h)) != -1) close(ss); modules_state_cache_set(h, NULL); if ((yspec = clicon_dbspec_yang(h)) != NULL) yspec_free(yspec); if ((yspec = clicon_config_yang(h)) != NULL) yspec_free(yspec); if ((x = clicon_nacm_ext(h)) != NULL) xml_free(x); if ((x = clicon_conf_xml(h)) != NULL) xml_free(x); stream_publish_exit(); clixon_plugin_exit(h); /* Delete all backend plugin RPC callbacks */ rpc_callback_delete_all(); if (pidfile) unlink(pidfile); if (sockfamily==AF_UNIX && lstat(sockpath, &st) == 0) unlink(sockpath); xmldb_plugin_unload(h); /* unload storage plugin */ backend_handle_exit(h); /* Also deletes streams. Cannot use h after this. */ event_exit(); clicon_debug(1, "%s done", __FUNCTION__); clicon_log_exit(); return 0; } /*! Unlink pidfile and quit */ static void backend_sig_term(int arg) { static int i=0; if (i++ == 0) clicon_log(LOG_NOTICE, "%s: %s: pid: %u Signal %d", __PROGRAM__, __FUNCTION__, getpid(), arg); clicon_exit_set(); /* checked in event_loop() */ } /*! usage */ static void usage(clicon_handle h, char *argv0) { char *plgdir = clicon_backend_dir(h); char *confsock = clicon_sock(h); char *confpid = clicon_backend_pidfile(h); char *group = clicon_sock_group(h); fprintf(stderr, "usage:%s *\n" "where options are\n" "\t-h\t\tHelp\n" "\t-D \tDebug level\n" "\t-f \tCLICON config file\n" "\t-l (s|e|o|f) Log on (s)yslog, std(e)rr or std(o)ut (stderr is default) Only valid if -F, if background syslog is on syslog.\n" "\t-d \tSpecify backend plugin directory (default: %s)\n" "\t-p \tYang directory path (see CLICON_YANG_DIR)\n" "\t-b \tSpecify XMLDB database directory\n" "\t-F\t\tRun in foreground, do not run as daemon\n" "\t-z\t\tKill other config daemon and exit\n" "\t-a UNIX|IPv4|IPv6 Internal backend socket family\n" "\t-u \tInternal socket domain path or IP addr (see -a)(default: %s)\n" "\t-P \tPid filename (default: %s)\n" "\t-1\t\tRun once and then quit (dont wait for events)\n" "\t-s \tSpecify backend startup mode: none|startup|running|init)\n" "\t-c \tLoad extra xml configuration, but don't commit.\n" "\t-g \tClient membership required to this group (default: %s)\n" "\t-y \tLoad yang spec file (override yang main module)\n" "\t-x \tXMLDB plugin\n" "\t-o \"