vty_out(vty, "%s", vty->frame);
}
- if (vty_shell(vty)) {
- va_start(args, format);
- vprintf(format, args);
- va_end(args);
- } else {
- /* Try to write to initial buffer. */
- va_start(args, format);
- len = vsnprintf(buf, sizeof(buf), format, args);
- va_end(args);
-
- /* Initial buffer is not enough. */
- if (len < 0 || len >= size) {
- while (1) {
- if (len > -1)
- size = len + 1;
- else
- size = size * 2;
-
- p = XREALLOC(MTYPE_VTY_OUT_BUF, p, size);
- if (!p)
- return -1;
-
- va_start(args, format);
- len = vsnprintf(p, size, format, args);
- va_end(args);
-
- if (len > -1 && len < size)
- break;
- }
- }
+ /* Try to write to initial buffer. */
+ va_start(args, format);
+ len = vsnprintf(buf, sizeof(buf), format, args);
+ va_end(args);
- /* When initial buffer is enough to store all output. */
- if (!p)
- p = buf;
-
- /* filter buffer */
- if (vty->filter) {
- vector lines = frrstr_split_vec(buf, "\n");
- frrstr_filter_vec(lines, &vty->include);
- if (buf[strlen(buf) - 1] == '\n' && vector_active(lines) > 0)
- vector_set(lines, XSTRDUP(MTYPE_TMP, ""));
- filtered = frrstr_join_vec(lines, "\n");
- frrstr_strvec_free(lines);
- } else {
- filtered = p;
+ /* Initial buffer is not enough. */
+ if (len < 0 || len >= size) {
+ while (1) {
+ if (len > -1)
+ size = len + 1;
+ else
+ size = size * 2;
+
+ p = XREALLOC(MTYPE_VTY_OUT_BUF, p, size);
+ if (!p)
+ return -1;
+
+ va_start(args, format);
+ len = vsnprintf(p, size, format, args);
+ va_end(args);
+
+ if (len > -1 && len < size)
+ break;
}
+ }
- /* Pointer p must point out buffer. */
- if (vty->type != VTY_TERM)
- buffer_put(vty->obuf, (uint8_t *)filtered,
- strlen(filtered));
- else
- buffer_put_crlf(vty->obuf, (uint8_t *)filtered,
- strlen(filtered));
+ /* When initial buffer is enough to store all output. */
+ if (!p)
+ p = buf;
- if (vty->filter)
- XFREE(MTYPE_TMP, filtered);
+ /* filter buffer */
+ if (vty->filter) {
+ vector lines = frrstr_split_vec(buf, "\n");
+ frrstr_filter_vec(lines, &vty->include);
+ if (buf[strlen(buf) - 1] == '\n' && vector_active(lines) > 0)
+ vector_set(lines, XSTRDUP(MTYPE_TMP, ""));
+ filtered = frrstr_join_vec(lines, "\n");
+ frrstr_strvec_free(lines);
+ } else {
+ filtered = p;
+ }
- /* If p is not different with buf, it is allocated buffer. */
- if (p != buf)
- XFREE(MTYPE_VTY_OUT_BUF, p);
+ switch (vty->type) {
+ case VTY_TERM:
+ /* print with crlf replacement */
+ buffer_put_crlf(vty->obuf, (uint8_t *)filtered,
+ strlen(filtered));
+ break;
+ case VTY_SHELL:
+ fprintf(vty->of, "%s", filtered);
+ fflush(vty->of);
+ break;
+ case VTY_SHELL_SERV:
+ case VTY_FILE:
+ default:
+ /* print without crlf replacement */
+ buffer_put(vty->obuf, (uint8_t *)filtered, strlen(filtered));
+ break;
}
+ if (vty->filter)
+ XFREE(MTYPE_TMP, filtered);
+
+ /* If p is not different with buf, it is allocated buffer. */
+ if (p != buf)
+ XFREE(MTYPE_VTY_OUT_BUF, p);
+
return len;
}
}
#endif /* 0 */
-/* Allocate new vty struct. */
-struct vty *vty_new()
-{
- struct vty *new = XCALLOC(MTYPE_VTY, sizeof(struct vty));
-
- new->fd = new->wfd = -1;
- new->obuf = buffer_new(0); /* Use default buffer size. */
- new->buf = XCALLOC(MTYPE_VTY, VTY_BUFSIZ);
- new->error_buf = XCALLOC(MTYPE_VTY, VTY_BUFSIZ);
- new->max = VTY_BUFSIZ;
-
- return new;
-}
-
/* Authentication of vty */
static void vty_auth(struct vty *vty, char *buf)
{
return 0;
}
+/* Allocate new vty struct. */
+struct vty *vty_new()
+{
+ struct vty *new = XCALLOC(MTYPE_VTY, sizeof(struct vty));
+
+ new->fd = new->wfd = -1;
+ new->obuf = buffer_new(0); /* Use default buffer size. */
+ new->buf = XCALLOC(MTYPE_VTY, VTY_BUFSIZ);
+ new->error_buf = XCALLOC(MTYPE_VTY, VTY_BUFSIZ);
+ new->max = VTY_BUFSIZ;
+
+ return new;
+}
+
+
/* allocate and initialise vty */
static struct vty *vty_new_init(int vty_sock)
{
#include "vrf.h"
#include "libfrr.h"
#include "command_graph.h"
+#include "frrstr.h"
DEFINE_MTYPE_STATIC(MVTYSH, VTYSH_CMD, "Vtysh cmd copy")
-/* Destination for vtysh output */
-FILE *outputfile;
-
/* Struct VTY. */
struct vty *vty;
/* VTY shell pager name. */
char *vtysh_pager_name = NULL;
-/* VTY shell client structure. */
+/* VTY shell client structure */
struct vtysh_client {
int fd;
const char *name;
struct vtysh_client *next;
};
+/* Some utility functions for working on vtysh-specific vty tasks */
+
+static FILE *vty_open_pager(struct vty *vty)
+{
+ if (vty->is_paged)
+ return vty->of;
+
+ vty->of_saved = vty->of;
+ vty->of = popen(vtysh_pager_name, "w");
+ if (vty->of == NULL) {
+ vty->of = vty->of_saved;
+ perror("popen");
+ exit(1);
+ }
+
+ vty->is_paged = true;
+
+ return vty->of;
+}
+
+static int vty_close_pager(struct vty *vty)
+{
+ if (!vty->is_paged)
+ return 0;
+
+ fflush(vty->of);
+ if (pclose(vty->of) == -1) {
+ perror("pclose");
+ exit(1);
+ }
+
+ vty->of = vty->of_saved;
+ vty->is_paged = false;
+
+ return 0;
+}
+
+void vtysh_pager_init(void)
+{
+ char *pager_defined;
+
+ pager_defined = getenv("VTYSH_PAGER");
+
+ if (pager_defined)
+ vtysh_pager_name = strdup(pager_defined);
+ else
+ vtysh_pager_name = strdup(VTYSH_PAGER);
+}
+
+/* --- */
+
struct vtysh_client vtysh_client[] = {
{.fd = -1, .name = "zebra", .flag = VTYSH_ZEBRA, .next = NULL},
{.fd = -1, .name = "ripd", .flag = VTYSH_RIPD, .next = NULL},
static void vclient_close(struct vtysh_client *vclient)
{
if (vclient->fd >= 0) {
- fprintf(stderr,
+ vty_out(vty,
"Warning: closing connection to %s because of an I/O error!\n",
vclient->name);
close(vclient->fd);
}
}
-/* Return true if str begins with prefix, else return false */
-static int begins_with(const char *str, const char *prefix)
-{
- if (!str || !prefix)
- return 0;
- size_t lenstr = strlen(str);
- size_t lenprefix = strlen(prefix);
- if (lenprefix > lenstr)
- return 0;
- return strncmp(str, prefix, lenprefix) == 0;
-}
-
+/*
+ * Send a CLI command to a client and read the response.
+ *
+ * Output will be printed to vty->of. If you want to suppress output, set that
+ * to NULL.
+ *
+ * vclient
+ * the client to send the command to
+ *
+ * line
+ * the command to send
+ *
+ * callback
+ * if non-null, this will be called with each line of output received from
+ * the client passed in the second parameter
+ *
+ * cbarg
+ * optional first argument to pass to callback
+ *
+ * Returns:
+ * a status code
+ */
static int vtysh_client_run(struct vtysh_client *vclient, const char *line,
- FILE *fp, void (*callback)(void *, const char *),
- void *cbarg)
+ void (*callback)(void *, const char *), void *cbarg)
{
int ret;
char stackbuf[4096];
continue;
if (nread <= 0) {
- fprintf(stderr, "vtysh: error reading from %s: %s (%d)",
+ vty_out(vty, "vtysh: error reading from %s: %s (%d)",
vclient->name, safe_strerror(errno), errno);
goto out_err;
}
/* eol is at line end now, either \n => \0 or \0\0\0 */
assert(eol && eol <= bufvalid);
- if (fp) {
- fputs(buf, fp);
- fputc('\n', fp);
- }
- if (callback)
- callback(cbarg, buf);
+ if (vty->of)
+ vty_out(vty, "%s\n", buf);
+
+ callback(cbarg, buf);
/* shift back data and adjust bufvalid */
memmove(buf, eol, bufvalid - eol);
/* else if no callback, dump raw */
if (!callback) {
- if (fp)
- fwrite(buf, 1, textlen, fp);
+ if (vty->of)
+ vty_out(vty, "%s", buf);
memmove(buf, buf + textlen, bufvalid - buf - textlen);
bufvalid -= textlen;
if (end)
}
static int vtysh_client_run_all(struct vtysh_client *head_client,
- const char *line, int continue_on_err, FILE *fp,
+ const char *line, int continue_on_err,
void (*callback)(void *, const char *),
void *cbarg)
{
int correct_instance = 0, wrong_instance = 0;
for (client = head_client; client; client = client->next) {
- rc = vtysh_client_run(client, line, fp, callback, cbarg);
+ rc = vtysh_client_run(client, line, callback, cbarg);
if (rc == CMD_NOT_MY_INSTANCE) {
wrong_instance++;
continue;
rc_all = rc;
}
}
- if (wrong_instance && !correct_instance && fp) {
- fprintf(fp,
+ if (wrong_instance && !correct_instance) {
+ vty_out(vty,
"%% [%s]: command ignored as it targets an instance that is not running\n",
head_client->name);
rc_all = CMD_WARNING_CONFIG_FAILED;
return rc_all;
}
+/*
+ * Execute command against all daemons.
+ *
+ * head_client
+ * where to start walking in the daemon list
+ *
+ * line
+ * the specific command to execute
+ *
+ * Returns:
+ * a status code
+ */
static int vtysh_client_execute(struct vtysh_client *head_client,
- const char *line, FILE *fp)
+ const char *line)
{
- return vtysh_client_run_all(head_client, line, 0, fp, NULL, NULL);
+ return vtysh_client_run_all(head_client, line, 0, NULL, NULL);
}
+/*
+ * Retrieve all running config from daemons and parse it with the vtysh config
+ * parser. Returned output is not displayed to the user.
+ *
+ * head_client
+ * where to start walking in the daemon list
+ *
+ * line
+ * the specific command to execute
+ */
static void vtysh_client_config(struct vtysh_client *head_client, char *line)
{
/* watchfrr currently doesn't load any config, and has some hardcoded
if (head_client->flag == VTYSH_WATCHFRR)
return;
- vtysh_client_run_all(head_client, line, 1, NULL,
- vtysh_config_parse_line, NULL);
-}
-
-void vtysh_pager_init(void)
-{
- char *pager_defined;
-
- pager_defined = getenv("VTYSH_PAGER");
-
- if (pager_defined)
- vtysh_pager_name = strdup(pager_defined);
- else
- vtysh_pager_name = strdup(VTYSH_PAGER);
+ /* suppress output to user */
+ vty->of_saved = vty->of;
+ vty->of = NULL;
+ vtysh_client_run_all(head_client, line, 1, vtysh_config_parse_line,
+ NULL);
+ vty->of = vty->of_saved;
}
/* Command execution over the vty interface. */
unsigned int i;
vector vline;
const struct cmd_element *cmd;
- FILE *fp = NULL;
- int closepager = 0;
int tried = 0;
int saved_ret, saved_node;
if (user_mode) {
if (strncmp("en", vector_slot(vline, 0), 2) == 0) {
cmd_free_strvec(vline);
- fprintf(stdout, "%% Command not allowed: enable\n");
+ vty_out(vty, "%% Command not allowed: enable\n");
return CMD_WARNING;
}
}
- saved_ret = ret = cmd_execute_command(vline, vty, &cmd, 1);
+ saved_ret = ret = cmd_execute(vty, line, &cmd, 1);
saved_node = vty->node;
/*
&& ret != CMD_WARNING && ret != CMD_WARNING_CONFIG_FAILED
&& vty->node > CONFIG_NODE) {
vty->node = node_parent(vty->node);
- ret = cmd_execute_command(vline, vty, &cmd, 1);
+ ret = cmd_execute(vty, line, &cmd, 1);
tried++;
}
case CMD_WARNING:
case CMD_WARNING_CONFIG_FAILED:
if (vty->type == VTY_FILE)
- fprintf(stdout, "Warning...\n");
+ vty_out(vty, "Warning...\n");
break;
case CMD_ERR_AMBIGUOUS:
- fprintf(stdout, "%% Ambiguous command: %s\n", line);
+ vty_out(vty, "%% Ambiguous command: %s\n", line);
break;
case CMD_ERR_NO_MATCH:
- fprintf(stdout, "%% Unknown command: %s\n", line);
+ vty_out(vty, "%% Unknown command: %s\n", line);
break;
case CMD_ERR_INCOMPLETE:
- fprintf(stdout, "%% Command incomplete: %s\n", line);
+ vty_out(vty, "%% Command incomplete: %s\n", line);
break;
case CMD_SUCCESS_DAEMON: {
/*
* problems if exited from vtysh at all. This hack shouldn't
* cause any problem but is really ugly.
*/
- fp = outputfile;
- if (pager && vtysh_pager_name && outputfile == stdout
- && (strncmp(line, "exit", 4) != 0)) {
- fp = popen(vtysh_pager_name, "w");
- if (fp == NULL) {
- perror("popen failed for pager");
- fp = outputfile;
- } else
- closepager = 1;
- }
+ if (pager && strncmp(line, "exit", 4))
+ vty_open_pager(vty);
if (!strcmp(cmd->string, "configure terminal")) {
for (i = 0; i < array_size(vtysh_client); i++) {
cmd_stat = vtysh_client_execute(
- &vtysh_client[i], line, fp);
+ &vtysh_client[i], line);
if (cmd_stat == CMD_WARNING)
break;
}
line = "end";
vline = cmd_make_strvec(line);
- if (vline == NULL) {
- if (pager && vtysh_pager_name && fp
- && fp != outputfile && closepager) {
- if (pclose(fp) == -1) {
- perror("pclose failed for pager");
- }
- fp = NULL;
- }
+ if (vline == NULL && vty->is_paged) {
+ vty_close_pager(vty);
return CMD_SUCCESS;
}
}
}
cmd_stat = vtysh_client_execute(
- &vtysh_client[i], line, fp);
+ &vtysh_client[i], line);
if (cmd_stat != CMD_SUCCESS)
break;
}
(*cmd->func)(cmd, vty, 0, NULL);
}
}
- if (pager && vtysh_pager_name && fp && closepager && fp != outputfile) {
- if (pclose(fp) == -1) {
- perror("pclose failed for pager");
- }
- fp = NULL;
- }
+ if (vty->is_paged)
+ vty_close_pager(vty);
+
return cmd_stat;
}
switch (vty->node) {
case LDP_IPV4_IFACE_NODE:
if (strncmp(vty_buf_copy, " ", 3)) {
- fprintf(outputfile, " end\n");
+ vty_out(vty, " end\n");
vty->node = LDP_IPV4_NODE;
}
break;
case LDP_IPV6_IFACE_NODE:
if (strncmp(vty_buf_copy, " ", 3)) {
- fprintf(outputfile, " end\n");
+ vty_out(vty, " end\n");
vty->node = LDP_IPV6_NODE;
}
break;
case LDP_PSEUDOWIRE_NODE:
if (strncmp(vty_buf_copy, " ", 2)) {
- fprintf(outputfile, " end\n");
+ vty_out(vty, " end\n");
vty->node = LDP_L2VPN_NODE;
}
break;
}
if (vty_buf_trimmed[0] == '!' || vty_buf_trimmed[0] == '#') {
- fprintf(outputfile, "%s", vty->buf);
+ vty_out(vty, "%s", vty->buf);
continue;
}
vline = cmd_make_strvec(vty->buf);
if (vline == NULL) {
- fprintf(outputfile, "%s", vty->buf);
+ vty_out(vty, "%s", vty->buf);
continue;
}
|| prev_node == BGP_IPV6M_NODE
|| prev_node == BGP_EVPN_NODE)
&& (tried == 1)) {
- fprintf(outputfile, "exit-address-family\n");
+ vty_out(vty, "exit-address-family\n");
} else if ((prev_node == BGP_EVPN_VNI_NODE)
&& (tried == 1)) {
- fprintf(outputfile, "exit-vni\n");
+ vty_out(vty, "exit-vni\n");
} else if ((prev_node == KEYCHAIN_KEY_NODE)
&& (tried == 1)) {
- fprintf(outputfile, "exit\n");
+ vty_out(vty, "exit\n");
} else if (tried) {
- fprintf(outputfile, "end\n");
+ vty_out(vty, "end\n");
}
}
/*
XFREE(MTYPE_VTYSH_CMD, vty_buf_copy);
return CMD_ERR_INCOMPLETE;
case CMD_SUCCESS:
- fprintf(stdout, "%s", vty->buf);
+ vty_out(vty, "%s", vty->buf);
break;
case CMD_SUCCESS_DAEMON: {
- unsigned int i;
int cmd_stat = CMD_SUCCESS;
- fprintf(outputfile, "%s", vty->buf);
- for (i = 0; i < array_size(vtysh_client); i++) {
- if (cmd->daemon & vtysh_client[i].flag) {
- cmd_stat = vtysh_client_execute(
- &vtysh_client[i], vty->buf,
- outputfile);
- if (cmd_stat != CMD_SUCCESS)
- break;
- }
- }
+ vty_out(vty, "%s", vty->buf);
+ cmd_stat = vtysh_client_execute(&vtysh_client[0],
+ vty->buf);
if (cmd_stat != CMD_SUCCESS)
break;
}
}
/* This is the end */
- fprintf(outputfile, "\nend\n");
+ vty_out(vty, "\nend\n");
vty_close(vty);
XFREE(MTYPE_VTYSH_CMD, vty_buf_copy);
for (i = 0; i < array_size(vtysh_client); i++) {
if (cmd->daemon & vtysh_client[i].flag) {
cmd_stat = vtysh_client_execute(
- &vtysh_client[i], vty->buf,
- outputfile);
+ &vtysh_client[i], vty->buf);
/*
* CMD_WARNING - Can mean that the
* command was parsed successfully but
case CMD_ERR_AMBIGUOUS:
cmd_free_strvec(vline);
vector_free(describe);
- fprintf(stdout, "%% Ambiguous command.\n");
+ vty_out(vty, "%% Ambiguous command.\n");
+ rl_on_new_line();
return 0;
break;
case CMD_ERR_NO_MATCH:
cmd_free_strvec(vline);
if (describe)
vector_free(describe);
- fprintf(stdout, "%% There is no matched command.\n");
+ vty_out(vty, "%% There is no matched command.\n");
+ rl_on_new_line();
return 0;
break;
}
for (i = 0; i < vector_active(describe); i++)
if ((token = vector_slot(describe, i)) != NULL) {
if (!token->desc)
- fprintf(stdout, " %-s\n", token->text);
+ vty_out(vty, " %-s\n", token->text);
else
- fprintf(stdout, " %-*s %s\n", width,
- token->text, token->desc);
+ vty_out(vty, " %-*s %s\n", width, token->text,
+ token->desc);
if (IS_VARYING_TOKEN(token->type)) {
const char *ref = vector_slot(
char *ac = cmd_variable_comp2str(
varcomps, cols);
- fprintf(stdout, "%s\n", ac);
+ vty_out(vty, "%s\n", ac);
XFREE(MTYPE_TMP, ac);
}
{
int ret;
- fprintf(stdout, "\n");
+ vty_out(vty, "\n");
ret = vtysh_process_questionmark(rl_line_buffer, rl_end);
rl_on_new_line();
snprintf(line, sizeof(line), "do show thread cpu %s\n", filter);
for (i = 0; i < array_size(vtysh_client); i++)
if (vtysh_client[i].fd >= 0) {
- fprintf(stdout, "Thread statistics for %s:\n",
+ vty_out(vty, "Thread statistics for %s:\n",
vtysh_client[i].name);
- ret = vtysh_client_execute(&vtysh_client[i], line,
- outputfile);
- fprintf(stdout, "\n");
+ ret = vtysh_client_execute(&vtysh_client[i], line);
+ vty_out(vty, "\n");
}
return ret;
}
for (i = 0; i < array_size(vtysh_client); i++)
if (vtysh_client[i].fd >= 0) {
- fprintf(stdout, "Work queue statistics for %s:\n",
+ vty_out(vty, "Work queue statistics for %s:\n",
vtysh_client[i].name);
- ret = vtysh_client_execute(&vtysh_client[i], line,
- outputfile);
- fprintf(stdout, "\n");
+ ret = vtysh_client_execute(&vtysh_client[i], line);
+ vty_out(vty, "\n");
}
return ret;
break;
}
- ret = vtysh_client_execute(&vtysh_client[i], "show work-queues\n",
- outputfile);
+ ret = vtysh_client_execute(&vtysh_client[i], "show work-queues\n");
return ret;
}
for (i = 0; i < array_size(vtysh_client); i++)
if (vtysh_client[i].fd >= 0) {
- fprintf(outputfile, headline, vtysh_client[i].name);
- ret = vtysh_client_execute(&vtysh_client[i], line,
- outputfile);
- fprintf(stdout, "\n");
+ vty_out(vty, headline, vtysh_client[i].name);
+ ret = vtysh_client_execute(&vtysh_client[i], line);
+ vty_out(vty, "\n");
}
return ret;
"Statistics about hash tables\n"
"Statistics about hash tables\n")
{
- fprintf(stdout, "\n");
- fprintf(stdout,
+ vty_out(vty, "\n");
+ vty_out(vty,
"Load factor (LF) - average number of elements across all buckets\n");
- fprintf(stdout,
+ vty_out(vty,
"Full load factor (FLF) - average number of elements across full buckets\n\n");
- fprintf(stdout,
+ vty_out(vty,
"Standard deviation (SD) is calculated for both the LF and FLF\n");
- fprintf(stdout,
+ vty_out(vty,
"and indicates the typical deviation of bucket chain length\n");
- fprintf(stdout, "from the value in the corresponding load factor.\n\n");
+ vty_out(vty, "from the value in the corresponding load factor.\n\n");
return show_per_daemon("do show debugging hashtable\n",
"Hashtable statistics for %s:\n");
{
unsigned int i;
char line[] = "do write terminal\n";
- FILE *fp = outputfile;
-
- if (fp == stdout && vtysh_pager_name) {
- fp = popen(vtysh_pager_name, "w");
- if (fp == NULL) {
- perror("popen");
- exit(1);
- }
- }
- fprintf(outputfile, "Building configuration...\n");
- fprintf(outputfile, "\nCurrent configuration:\n");
- fprintf(outputfile, "!\n");
+ vty_out(vty, "Building configuration...\n");
+ vty_out(vty, "\nCurrent configuration:\n");
+ vty_out(vty, "!\n");
for (i = 0; i < array_size(vtysh_client); i++)
if ((argc < 3)
vtysh_client_config(&vtysh_client[i], line);
/* Integrate vtysh specific configuration. */
+ vty_open_pager(vty);
vtysh_config_write();
+ vtysh_config_dump();
+ vty_close_pager(vty);
+ vty_out(vty, "end\n");
- vtysh_config_dump(fp);
-
- if (vtysh_pager_name && fp != outputfile) {
- fflush(fp);
- if (pclose(fp) == -1) {
- perror("pclose");
- exit(1);
- }
- fp = NULL;
- }
-
- fprintf(outputfile, "end\n");
return CMD_SUCCESS;
}
struct stat st;
int err = 0;
- fprintf(stdout, "Building Configuration...\n");
+ vty_out(vty, "Building Configuration...\n");
backup_config_file(frr_config);
fp = fopen(frr_config, "w");
if (fp == NULL) {
- fprintf(stdout,
+ vty_out(vty,
"%% Error: failed to open configuration file %s: %s\n",
frr_config, safe_strerror(errno));
return CMD_WARNING_CONFIG_FAILED;
vtysh_client_config(&vtysh_client[i], line);
vtysh_config_write();
- vtysh_config_dump(fp);
+ vtysh_config_dump();
if (fchmod(fd, CONFIGFILE_MASK) != 0) {
printf("%% Warning: can't chmod configuration file %s: %s\n",
char line[] = "do write memory\n";
unsigned int i;
- fprintf(outputfile,
- "Note: this version of vtysh never writes vtysh.conf\n");
+ vty_out(vty, "Note: this version of vtysh never writes vtysh.conf\n");
/* If integrated frr.conf explicitely set. */
if (want_config_integrated()) {
if (i < array_size(vtysh_client) && vtysh_client[i].fd != -1) {
used_watchfrr = true;
ret = vtysh_client_execute(&vtysh_client[i],
- "do write integrated",
- outputfile);
+ "do write integrated");
}
/*
return ret;
}
- fprintf(outputfile, "Building Configuration...\n");
+ vty_out(vty, "Building Configuration...\n");
for (i = 0; i < array_size(vtysh_client); i++)
- ret = vtysh_client_execute(&vtysh_client[i], line, outputfile);
+ ret = vtysh_client_execute(&vtysh_client[i], line);
return ret;
}
lines = strtol(argv[idx_number]->arg, &endptr, 10);
if (lines < 0 || lines > 512 || *endptr != '\0') {
- fprintf(outputfile, "length is malformed\n");
+ vty_out(vty, "length is malformed\n");
return CMD_WARNING;
}
for (i = 0; i < array_size(vtysh_client); i++)
if (vtysh_client[i].fd >= 0)
- fprintf(outputfile, " %s", vtysh_client[i].name);
- fprintf(outputfile, "\n");
+ vty_out(vty, " %s", vtysh_client[i].name);
+ vty_out(vty, "\n");
return CMD_SUCCESS;
}
"Path to dump output to\n")
{
const char *path = argv[argc - 1]->arg;
- outputfile = fopen(path, "a");
- if (!outputfile) {
- fprintf(stdout, "Failed to open file '%s': %s\n", path,
+ vty->of = fopen(path, "a");
+ if (!vty->of) {
+ vty_out(vty, "Failed to open file '%s': %s\n", path,
safe_strerror(errno));
- outputfile = stdout;
+ vty->of = stdout;
}
return CMD_SUCCESS;
}
"Direct vtysh output to file\n"
"Path to dump output to\n")
{
- if (outputfile != stdout) {
- fclose(outputfile);
- outputfile = stdout;
+ if (vty->of != stdout) {
+ fclose(vty->of);
+ vty->of = stdout;
}
return CMD_SUCCESS;
}
for (unsigned int j = 0; j < vector_active(clis); j++) {
cli = vector_slot(clis, j);
if (strcasestr(cli->string, text))
- fprintf(stdout, " (%s) %s\n",
+ vty_out(vty, " (%s) %s\n",
node_names[node->node], cli->string);
}
}
return ret;
}
fprintf(stderr, "success!\n");
- if (vtysh_client_execute(vclient, "enable", NULL) < 0)
+ if (vtysh_client_execute(vclient, "enable") < 0)
return -1;
return vtysh_execute_no_pager("end");
}
token->text, token->varname ? token->varname : "-");
for (i = 0; i < array_size(vtysh_client); i++)
- vtysh_client_run_all(&vtysh_client[i], accmd, 1, NULL,
- vtysh_ac_line, comps);
+ vtysh_client_run_all(&vtysh_client[i], accmd, 1, vtysh_ac_line,
+ comps);
}
static const struct cmd_variable_handler vtysh_var_handler[] = {
void vtysh_uninit()
{
- if (outputfile != stdout)
- fclose(outputfile);
+ if (vty->of != stdout)
+ fclose(vty->of);
}
void vtysh_init_vty(void)
vty->node = VIEW_NODE;
/* set default output */
- outputfile = stdout;
+ vty->of = stdout;
/* Initialize commands. */
cmd_init(0);