diff options
author | Xiaoming Jiang <jiangxiaoming@outlook.com> | 2022-12-08 07:54:06 +0000 |
---|---|---|
committer | Damjan Marion <dmarion@0xa5.net> | 2023-03-06 17:09:01 +0000 |
commit | 4d830d2142af5aa545bcabf5dc3facc4e4344cbe (patch) | |
tree | febe3d849de59bea57b14f063540b6b833eff800 /src/vlib/unix | |
parent | 4646cd4e20db0cd593dc5964c9cac70cf73f7652 (diff) |
vlib: fix macro define command not work in startup config exec script
Type: fix
Signed-off-by: Xiaoming Jiang <jiangxiaoming@outlook.com>
Change-Id: Idb34490199a78d5b0c1fe2382b6483a6e3a6fd1f
Diffstat (limited to 'src/vlib/unix')
-rw-r--r-- | src/vlib/unix/main.c | 89 |
1 files changed, 8 insertions, 81 deletions
diff --git a/src/vlib/unix/main.c b/src/vlib/unix/main.c index 3991566ee01..74ad19ebbc2 100644 --- a/src/vlib/unix/main.c +++ b/src/vlib/unix/main.c @@ -273,98 +273,25 @@ startup_config_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f) { unix_main_t *um = &unix_main; - u8 *buf = 0; - uword l, n = 1; + unformat_input_t in; vlib_process_suspend (vm, 2.0); while (um->unix_config_complete == 0) vlib_process_suspend (vm, 0.1); - if (um->startup_config_filename) + if (!um->startup_config_filename) { - unformat_input_t sub_input; - int fd; - struct stat s; - char *fn = (char *) um->startup_config_filename; + return 0; + } - fd = open (fn, O_RDONLY); - if (fd < 0) - { - clib_warning ("failed to open `%s'", fn); - return 0; - } + unformat_init_vector (&in, + format (0, "exec %s", um->startup_config_filename)); - if (fstat (fd, &s) < 0) - { - clib_warning ("failed to stat `%s'", fn); - bail: - close (fd); - return 0; - } + vlib_cli_input (vm, &in, 0, 0); - if (!(S_ISREG (s.st_mode) || S_ISLNK (s.st_mode))) - { - clib_warning ("not a regular file: `%s'", fn); - goto bail; - } + unformat_free (&in); - while (n > 0) - { - l = vec_len (buf); - vec_resize (buf, 4096); - n = read (fd, buf + l, 4096); - if (n > 0) - { - vec_set_len (buf, l + n); - if (n < 4096) - break; - } - else - break; - } - if (um->log_fd && vec_len (buf)) - { - u8 *lv = 0; - lv = format (lv, "%U: ***** Startup Config *****\n%v", - format_timeval, NULL /* current bat-format */, - 0 /* current bat-time */, buf); - { - int rv __attribute__ ((unused)) = - write (um->log_fd, lv, vec_len (lv)); - } - vec_reset_length (lv); - lv = - format (lv, "%U: ***** End Startup Config *****\n", format_timeval, - NULL /* current bat-format */, 0 /* current bat-time */); - { - int rv __attribute__ ((unused)) = - write (um->log_fd, lv, vec_len (lv)); - } - vec_free (lv); - } - - if (vec_len (buf)) - { - unformat_input_t in; - unformat_init_vector (&sub_input, buf); - - while (unformat_user (&sub_input, unformat_vlib_cli_line, &in)) - { - if (vlib_cli_input (vm, &in, 0, 0) != 0) - { - /* cli failed - stop */ - unformat_free (&in); - break; - } - unformat_free (&in); - } - - /* frees buf for us */ - unformat_free (&sub_input); - } - close (fd); - } return 0; } |