2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 * unix.h: Unix specific main state
18 * Copyright (c) 2008 Eliot Dresselhaus
20 * Permission is hereby granted, free of charge, to any person obtaining
21 * a copy of this software and associated documentation files (the
22 * "Software"), to deal in the Software without restriction, including
23 * without limitation the rights to use, copy, modify, merge, publish,
24 * distribute, sublicense, and/or sell copies of the Software, and to
25 * permit persons to whom the Software is furnished to do so, subject to
26 * the following conditions:
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 #ifndef included_unix_unix_h
41 #define included_unix_unix_h
43 #include <vppinfra/file.h>
44 #include <vppinfra/socket.h>
51 } unix_error_history_t;
55 /* Back pointer to main structure. */
56 vlib_main_t *vlib_main;
59 /* Run interactively or as daemon (background process). */
60 #define UNIX_FLAG_INTERACTIVE (1 << 0)
61 #define UNIX_FLAG_NODAEMON (1 << 1)
62 #define UNIX_FLAG_NOSYSLOG (1 << 2)
63 #define UNIX_FLAG_NOCOLOR (1 << 3)
64 #define UNIX_FLAG_NOBANNER (1 << 4)
67 /* CLI listen socket. */
68 clib_socket_t cli_listen_socket;
70 /* Circular buffer of last unix errors. */
71 unix_error_history_t error_history[128];
72 u32 error_history_index;
75 /* startup-config filename */
76 u8 *startup_config_filename;
78 /* runtime directory path */
81 /* pidfile filename */
84 /* unix config complete */
85 volatile int unix_config_complete;
87 /* CLI log file. GIGO. */
91 /* Don't put CLI connections into character mode */
94 /* Maximum amount of command line history to keep per session */
95 u32 cli_history_limit;
97 /* Suppress the welcome banner at CLI session start */
100 /* Maximum pager buffer size */
101 u32 cli_pager_buffer_limit;
103 /* Suppress the pager */
106 /* Store the original state of stdin when it's a tty */
107 struct termios tio_stdin;
114 /** CLI session events. */
117 UNIX_CLI_PROCESS_EVENT_READ_READY, /**< A file descriptor has data to be
119 UNIX_CLI_PROCESS_EVENT_QUIT, /**< A CLI session wants to close. */
120 } unix_cli_process_event_type_t;
122 /* Global main structure. */
123 extern unix_main_t unix_main;
124 extern clib_file_main_t file_main;
127 unix_save_error (unix_main_t * um, clib_error_t * error)
129 unix_error_history_t *eh = um->error_history + um->error_history_index;
130 clib_error_free_vector (eh->error);
132 eh->time = vlib_time_now (um->vlib_main);
133 um->n_total_errors += 1;
134 if (++um->error_history_index >= ARRAY_LEN (um->error_history))
135 um->error_history_index = 0;
138 /* Main function for Unix VLIB. */
139 int vlib_unix_main (int argc, char *argv[]);
141 /* Set prompt for CLI. */
142 void vlib_unix_cli_set_prompt (char *prompt);
144 static inline unix_main_t *
145 vlib_unix_get_main (void)
151 vlib_unix_get_runtime_dir (void)
153 return (char *) unix_main.runtime_dir;
156 /* thread stack array; vec_len = max number of threads */
157 extern u8 **vlib_thread_stacks;
161 clib_error_t *foreach_directory_file (char *dir_name,
162 clib_error_t * (*f) (void *arg,
165 void *arg, int scan_dirs);
167 clib_error_t *vlib_unix_recursive_mkdir (char *path);
169 clib_error_t *vlib_unix_validate_runtime_file (unix_main_t * um,
173 #endif /* included_unix_unix_h */
176 * fd.io coding-style-patch-verification: ON
179 * eval: (c-set-style "gnu")