From a805cc2d7030694ae2ae38403452ac3b90a40cff Mon Sep 17 00:00:00 2001 From: paul Date: Thu, 1 May 2003 14:29:48 +0000 Subject: From: Sergiy Vyshnevetskiy Subject: [zebra 18941] Re: [PATCH] misc patch Program shouldn't terminate on pager execution failure. We can also use "PAGER" environment variable - it's very common. --- vtysh/vtysh.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index a3b21c7b..d1a5c5fd 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -349,6 +349,8 @@ void vtysh_pager_init () { vtysh_pager_name = getenv ("VTYSH_PAGER"); + if (! vtysh_pager_name) + vtysh_pager_name = getenv ("PAGER"); if (! vtysh_pager_name) vtysh_pager_name = "more"; } @@ -361,6 +363,7 @@ vtysh_execute_func (char *line, int pager) vector vline; struct cmd_element *cmd; FILE *fp = NULL; + int closepager=0; /* Split readline string up into the vector */ vline = cmd_make_strvec (line); @@ -394,9 +397,11 @@ vtysh_execute_func (char *line, int pager) fp = popen (vtysh_pager_name, "w"); if (fp == NULL) { - perror ("popen"); - exit (1); + perror ("popen failed for pager"); + fp = stdout; } + else + closepager=1; } else fp = stdout; @@ -425,12 +430,11 @@ vtysh_execute_func (char *line, int pager) if (vline == NULL) { - if (pager && vtysh_pager_name && fp) + if (pager && vtysh_pager_name && fp && closepager) { if (pclose (fp) == -1) { - perror ("pclose"); - exit (1); + perror ("pclose failed for pager"); } fp = NULL; } @@ -478,12 +482,11 @@ vtysh_execute_func (char *line, int pager) (*cmd->func) (cmd, vty, 0, NULL); } } - if (pager && vtysh_pager_name && fp) + if (pager && vtysh_pager_name && fp && closepager) { if (pclose (fp) == -1) { - perror ("pclose"); - exit (1); + perror ("pclose failed for pager"); } fp = NULL; } -- cgit v1.2.1