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>
diff --git a/lib/vty.c b/lib/vty.c
index a3f1a3c..3477f63 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -1703,6 +1703,7 @@
/* 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)
@@ -1711,11 +1712,15 @@
{
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;
@@ -1725,6 +1730,7 @@
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