summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2015-05-12 21:56:18 +0200
committerDonald Sharp <sharpd@cumulusnetworks.com>2016-06-08 21:09:53 +0200
commitdbf78092dae5717334dbb0f20fa540a47fbebb70 (patch)
tree22936f002b3e42682c494cbd4ba82d99e75b83c9
parentlib/vty: put stdin in raw mode for vty (diff)
downloadfrr-dbf78092dae5717334dbb0f20fa540a47fbebb70.tar.xz
frr-dbf78092dae5717334dbb0f20fa540a47fbebb70.zip
lib/vty: add vty_stdio at-close hook
This is intended to be used for either "exit on close", "fork on close" or "reopen vty on close" functionality for the stdio vty. Which of these options to take depends on the context, the use case right now is test programs exiting on EOF. Signed-off-by: David Lamparter <equinox@opensourcerouting.org> (cherry picked from commit 464ccf36b4aa1b942cad413ea30267b4bf9e6315)
-rw-r--r--lib/vty.c8
-rw-r--r--lib/vty.h2
2 files changed, 8 insertions, 2 deletions
diff --git a/lib/vty.c b/lib/vty.c
index d202f72fa..65bb28bb2 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -1704,6 +1704,7 @@ vty_create (int vty_sock, union sockunion *su)
/* create vty for stdio */
static struct termios stdio_orig_termios;
static struct vty *stdio_vty = NULL;
+static void (*stdio_vty_atclose)(void);
static void
vty_stdio_reset (void)
@@ -1712,11 +1713,15 @@ vty_stdio_reset (void)
{
tcsetattr (0, TCSANOW, &stdio_orig_termios);
stdio_vty = NULL;
+
+ if (stdio_vty_atclose)
+ stdio_vty_atclose ();
+ stdio_vty_atclose = NULL;
}
}
struct vty *
-vty_stdio (void)
+vty_stdio (void (*atclose)())
{
struct vty *vty;
struct termios termios;
@@ -1726,6 +1731,7 @@ vty_stdio (void)
return NULL;
vty = stdio_vty = vty_new_init (0);
+ stdio_vty_atclose = atclose;
vty->wfd = 1;
/* always have stdio vty in a known _unchangeable_ state, don't want config
diff --git a/lib/vty.h b/lib/vty.h
index a248680db..81251e07b 100644
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -273,7 +273,7 @@ extern void vty_init_vtysh (void);
extern void vty_terminate (void);
extern void vty_reset (void);
extern struct vty *vty_new (void);
-extern struct vty *vty_stdio (void);
+extern struct vty *vty_stdio (void (*atclose)(void));
extern int vty_out (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
extern void vty_read_config (char *, char *);
extern void vty_time_print (struct vty *, int);