FD.io VPP  v20.05.1-6-gf53edbc3b
Vector Packet Processing
unix.h
Go to the documentation of this file.
1 /*
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 
43 #include <vppinfra/file.h>
44 #include <vppinfra/socket.h>
45 #include <termios.h>
46 
47 typedef struct
48 {
52 
53 typedef struct
54 {
55  /* Back pointer to main structure. */
57 
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 
64 
65  /* CLI listen socket. */
67 
68  /* Circular buffer of last unix errors. */
69  unix_error_history_t error_history[128];
72 
73  /* startup-config filename */
75 
76  /* runtime directory path */
78 
79  /* pidfile filename */
81 
82  /* unix config complete */
83  volatile int unix_config_complete;
84 
85  /* CLI log file. GIGO. */
87  int log_fd;
88 
89  /* Don't put CLI connections into character mode */
91 
92  /* Maximum amount of command line history to keep per session */
94 
95  /* Suppress the welcome banner at CLI session start */
97 
98  /* Maximum pager buffer size */
100 
101  /* Suppress the pager */
103 
104  /* Store the original state of stdin when it's a tty */
105  struct termios tio_stdin;
107 
109 
110 } unix_main_t;
111 
112 /* Global main structure. */
113 extern unix_main_t unix_main;
115 
116 always_inline void
118 {
121  eh->error = error;
122  eh->time = vlib_time_now (um->vlib_main);
123  um->n_total_errors += 1;
124  if (++um->error_history_index >= ARRAY_LEN (um->error_history))
125  um->error_history_index = 0;
126 }
127 
128 /* Main function for Unix VLIB. */
129 int vlib_unix_main (int argc, char *argv[]);
130 
131 /* Set prompt for CLI. */
132 void vlib_unix_cli_set_prompt (char *prompt);
133 
134 static inline unix_main_t *
136 {
137  return &unix_main;
138 }
139 
140 static inline char *
142 {
143  return (char *) unix_main.runtime_dir;
144 }
145 
146 /* thread stack array; vec_len = max number of threads */
147 extern u8 **vlib_thread_stacks;
148 
149 /* utils */
150 
151 clib_error_t *foreach_directory_file (char *dir_name,
152  clib_error_t * (*f) (void *arg,
153  u8 * path_name,
154  u8 * file_name),
155  void *arg, int scan_dirs);
156 
158 
160  const char *path,
161  u8 ** full_path);
162 
163 #endif /* included_unix_unix_h */
164 
165 /*
166  * fd.io coding-style-patch-verification: ON
167  *
168  * Local Variables:
169  * eval: (c-set-style "gnu")
170  * End:
171  */
u32 error_history_index
Definition: unix.h:70
unix_main_t unix_main
Definition: main.c:62
int vlib_unix_main(int argc, char *argv[])
Definition: main.c:682
u8 ** vlib_thread_stacks
Definition: main.c:648
u32 flags
Definition: unix.h:58
volatile int unix_config_complete
Definition: unix.h:83
unsigned long u64
Definition: types.h:89
u32 poll_sleep_usec
Definition: unix.h:108
u32 cli_pager_buffer_limit
Definition: unix.h:99
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:291
clib_file_main_t file_main
Definition: main.c:63
vl_api_fib_path_t path
Definition: mfib_types.api:34
clib_socket_t cli_listen_socket
Definition: unix.h:66
unsigned char u8
Definition: types.h:56
int log_fd
Definition: unix.h:87
double f64
Definition: types.h:142
u8 * pidfile
Definition: unix.h:80
static char * vlib_unix_get_runtime_dir(void)
Definition: unix.h:141
static unix_main_t * vlib_unix_get_main(void)
Definition: unix.h:135
unsigned int u32
Definition: types.h:88
vlib_main_t * vlib_main
Definition: unix.h:56
void * clib_error_free_vector(clib_error_t *errors)
Definition: error.c:182
int cli_line_mode
Definition: unix.h:90
int cli_no_banner
Definition: unix.h:96
u8 * startup_config_filename
Definition: unix.h:74
#define always_inline
Definition: ipsec.h:28
u32 cli_history_limit
Definition: unix.h:93
unix_error_history_t error_history[128]
Definition: unix.h:69
int cli_no_pager
Definition: unix.h:102
#define ARRAY_LEN(x)
Definition: clib.h:66
int tio_isset
Definition: unix.h:106
struct _socket_t clib_socket_t
clib_error_t * vlib_unix_recursive_mkdir(char *path)
Definition: util.c:103
clib_error_t * error
Definition: unix.h:50
clib_error_t * foreach_directory_file(char *dir_name, clib_error_t *(*f)(void *arg, u8 *path_name, u8 *file_name), void *arg, int scan_dirs)
Definition: util.c:49
clib_error_t * vlib_unix_validate_runtime_file(unix_main_t *um, const char *path, u8 **full_path)
Definition: util.c:138
static void unix_save_error(unix_main_t *um, clib_error_t *error)
Definition: unix.h:117
u8 * runtime_dir
Definition: unix.h:77
void vlib_unix_cli_set_prompt(char *prompt)
Set the CLI prompt.
Definition: cli.c:3231
u8 * log_filename
Definition: unix.h:86
u64 n_total_errors
Definition: unix.h:71