blob: 44dcf712e8d3a820aec490aa704bf25de4e98c04 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
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:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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.
14 */
15/*
16 * unix.h: Unix specific main state
17 *
18 * Copyright (c) 2008 Eliot Dresselhaus
19 *
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:
27 *
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
30 *
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.
38 */
39
40#ifndef included_unix_unix_h
41#define included_unix_unix_h
42
Damjan Marion56dd5432017-09-08 19:52:02 +020043#include <vppinfra/file.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070044#include <vppinfra/socket.h>
Chris Luke0aca5eb2016-04-25 13:48:54 -040045#include <termios.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070046
Dave Barach9b8ffd92016-07-08 08:13:45 -040047typedef struct
48{
Ed Warnickecb9cada2015-12-08 15:45:58 -070049 f64 time;
Dave Barach9b8ffd92016-07-08 08:13:45 -040050 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -070051} unix_error_history_t;
52
Dave Barach9b8ffd92016-07-08 08:13:45 -040053typedef struct
54{
Ed Warnickecb9cada2015-12-08 15:45:58 -070055 /* Back pointer to main structure. */
Dave Barach9b8ffd92016-07-08 08:13:45 -040056 vlib_main_t *vlib_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070057
58 u32 flags;
59 /* Run interactively or as daemon (background process). */
60#define UNIX_FLAG_INTERACTIVE (1 << 0)
61#define UNIX_FLAG_NODAEMON (1 << 1)
Ruslan Babayeve31820a2020-02-14 17:45:02 -080062#define UNIX_FLAG_NOSYSLOG (1 << 2)
Damjan Marion06d82262020-10-21 12:43:40 +020063#define UNIX_FLAG_NOCOLOR (1 << 3)
64#define UNIX_FLAG_NOBANNER (1 << 4)
Ruslan Babayeve31820a2020-02-14 17:45:02 -080065
Ed Warnickecb9cada2015-12-08 15:45:58 -070066
Ed Warnickecb9cada2015-12-08 15:45:58 -070067 /* CLI listen socket. */
68 clib_socket_t cli_listen_socket;
69
Ed Warnickecb9cada2015-12-08 15:45:58 -070070 /* Circular buffer of last unix errors. */
71 unix_error_history_t error_history[128];
72 u32 error_history_index;
73 u64 n_total_errors;
74
75 /* startup-config filename */
76 u8 *startup_config_filename;
77
Damjan Marion57d963f2017-07-20 19:17:06 +020078 /* runtime directory path */
79 u8 *runtime_dir;
80
Pierre Pfister9a244bb2017-07-27 22:57:34 -040081 /* pidfile filename */
82 u8 *pidfile;
83
Ed Warnickecb9cada2015-12-08 15:45:58 -070084 /* unix config complete */
85 volatile int unix_config_complete;
86
87 /* CLI log file. GIGO. */
88 u8 *log_filename;
89 int log_fd;
Chris Luke572d8122016-04-25 13:49:07 -040090
Chris Luke0aca5eb2016-04-25 13:48:54 -040091 /* Don't put CLI connections into character mode */
Ed Warnickecb9cada2015-12-08 15:45:58 -070092 int cli_line_mode;
Chris Luke0aca5eb2016-04-25 13:48:54 -040093
94 /* Maximum amount of command line history to keep per session */
Ed Warnickecb9cada2015-12-08 15:45:58 -070095 u32 cli_history_limit;
Chris Luke0aca5eb2016-04-25 13:48:54 -040096
Chris Luke572d8122016-04-25 13:49:07 -040097 /* Suppress the welcome banner at CLI session start */
98 int cli_no_banner;
99
Chris Luke7afda3a2016-04-25 13:49:22 -0400100 /* Maximum pager buffer size */
101 u32 cli_pager_buffer_limit;
102
103 /* Suppress the pager */
104 int cli_no_pager;
105
Chris Luke0aca5eb2016-04-25 13:48:54 -0400106 /* Store the original state of stdin when it's a tty */
107 struct termios tio_stdin;
108 int tio_isset;
Dave Barach85aa4902018-06-14 18:52:46 -0400109
110 u32 poll_sleep_usec;
111
Ed Warnickecb9cada2015-12-08 15:45:58 -0700112} unix_main_t;
113
114/* Global main structure. */
115extern unix_main_t unix_main;
Damjan Marion56dd5432017-09-08 19:52:02 +0200116extern clib_file_main_t file_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700117
118always_inline void
119unix_save_error (unix_main_t * um, clib_error_t * error)
120{
Dave Barach9b8ffd92016-07-08 08:13:45 -0400121 unix_error_history_t *eh = um->error_history + um->error_history_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700122 clib_error_free_vector (eh->error);
123 eh->error = error;
124 eh->time = vlib_time_now (um->vlib_main);
125 um->n_total_errors += 1;
126 if (++um->error_history_index >= ARRAY_LEN (um->error_history))
127 um->error_history_index = 0;
128}
129
130/* Main function for Unix VLIB. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400131int vlib_unix_main (int argc, char *argv[]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700132
Ed Warnickecb9cada2015-12-08 15:45:58 -0700133/* Set prompt for CLI. */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400134void vlib_unix_cli_set_prompt (char *prompt);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700135
Dave Barach9b8ffd92016-07-08 08:13:45 -0400136static inline unix_main_t *
137vlib_unix_get_main (void)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700138{
139 return &unix_main;
140}
141
Damjan Marion57d963f2017-07-20 19:17:06 +0200142static inline char *
143vlib_unix_get_runtime_dir (void)
144{
145 return (char *) unix_main.runtime_dir;
146}
147
Ed Warnickecb9cada2015-12-08 15:45:58 -0700148/* thread stack array; vec_len = max number of threads */
Damjan Marion6a7acc22016-12-19 16:28:36 +0100149extern u8 **vlib_thread_stacks;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700150
Damjan Mariona42cd342016-04-13 18:03:20 +0200151/* utils */
152
Dave Barach9b8ffd92016-07-08 08:13:45 -0400153clib_error_t *foreach_directory_file (char *dir_name,
154 clib_error_t * (*f) (void *arg,
155 u8 * path_name,
156 u8 * file_name),
157 void *arg, int scan_dirs);
Damjan Mariona42cd342016-04-13 18:03:20 +0200158
Damjan Marion57d963f2017-07-20 19:17:06 +0200159clib_error_t *vlib_unix_recursive_mkdir (char *path);
Chris Luke475674e2017-07-05 18:02:53 -0400160
Pierre Pfister9a244bb2017-07-27 22:57:34 -0400161clib_error_t *vlib_unix_validate_runtime_file (unix_main_t * um,
162 const char *path,
163 u8 ** full_path);
164
Ed Warnickecb9cada2015-12-08 15:45:58 -0700165#endif /* included_unix_unix_h */
Dave Barach9b8ffd92016-07-08 08:13:45 -0400166
167/*
168 * fd.io coding-style-patch-verification: ON
169 *
170 * Local Variables:
171 * eval: (c-set-style "gnu")
172 * End:
173 */