paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* Virtual terminal interface shell. |
| 2 | * Copyright (C) 2000 Kunihiro Ishiguro |
| 3 | * |
| 4 | * This file is part of GNU Zebra. |
| 5 | * |
| 6 | * GNU Zebra is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the |
| 8 | * Free Software Foundation; either version 2, or (at your option) any |
| 9 | * later version. |
| 10 | * |
| 11 | * GNU Zebra is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free |
| 18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 19 | * 02111-1307, USA. |
| 20 | */ |
| 21 | |
| 22 | #include <zebra.h> |
| 23 | |
| 24 | #include <sys/un.h> |
| 25 | #include <setjmp.h> |
| 26 | #include <sys/wait.h> |
| 27 | #include <pwd.h> |
| 28 | |
| 29 | #include <readline/readline.h> |
| 30 | #include <readline/history.h> |
| 31 | |
gdt | 5e4fa16 | 2004-03-16 14:38:36 +0000 | [diff] [blame] | 32 | #include <lib/version.h> |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 33 | #include "getopt.h" |
| 34 | #include "command.h" |
Andrew J. Schorr | f366ad3 | 2006-07-27 18:01:41 +0000 | [diff] [blame] | 35 | #include "memory.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 36 | |
| 37 | #include "vtysh/vtysh.h" |
| 38 | #include "vtysh/vtysh_user.h" |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 39 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 40 | /* VTY shell program name. */ |
| 41 | char *progname; |
| 42 | |
hasso | 67e29ab | 2004-08-26 22:21:31 +0000 | [diff] [blame] | 43 | /* Configuration file name and directory. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 44 | char config_default[] = SYSCONFDIR VTYSH_DEFAULT_CONFIG; |
Tomasz Pala | 3f4ab7f | 2009-06-24 22:23:11 +0100 | [diff] [blame] | 45 | char history_file[MAXPATHLEN]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 46 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 47 | /* Flag for indicate executing child command. */ |
| 48 | int execute_flag = 0; |
| 49 | |
| 50 | /* For sigsetjmp() & siglongjmp(). */ |
| 51 | static sigjmp_buf jmpbuf; |
| 52 | |
| 53 | /* Flag for avoid recursive siglongjmp() call. */ |
| 54 | static int jmpflag = 0; |
| 55 | |
| 56 | /* A static variable for holding the line. */ |
| 57 | static char *line_read; |
| 58 | |
| 59 | /* Master of threads. */ |
| 60 | struct thread_master *master; |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 61 | |
Stephen Hemminger | 57fb974 | 2008-07-28 12:19:04 -0700 | [diff] [blame] | 62 | /* Command logging */ |
| 63 | FILE *logfile; |
| 64 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 65 | /* SIGTSTP handler. This function care user's ^Z input. */ |
| 66 | void |
| 67 | sigtstp (int sig) |
| 68 | { |
| 69 | /* Execute "end" command. */ |
| 70 | vtysh_execute ("end"); |
| 71 | |
| 72 | /* Initialize readline. */ |
| 73 | rl_initialize (); |
| 74 | printf ("\n"); |
| 75 | |
| 76 | /* Check jmpflag for duplicate siglongjmp(). */ |
| 77 | if (! jmpflag) |
| 78 | return; |
| 79 | |
| 80 | jmpflag = 0; |
| 81 | |
| 82 | /* Back to main command loop. */ |
| 83 | siglongjmp (jmpbuf, 1); |
| 84 | } |
| 85 | |
| 86 | /* SIGINT handler. This function care user's ^Z input. */ |
| 87 | void |
| 88 | sigint (int sig) |
| 89 | { |
| 90 | /* Check this process is not child process. */ |
| 91 | if (! execute_flag) |
| 92 | { |
| 93 | rl_initialize (); |
| 94 | printf ("\n"); |
| 95 | rl_forced_update_display (); |
| 96 | } |
| 97 | } |
| 98 | |
hasso | e42f5a3 | 2004-08-28 17:04:33 +0000 | [diff] [blame] | 99 | /* Signale wrapper for vtysh. We don't use sigevent because |
| 100 | * vtysh doesn't use threads. TODO */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 101 | RETSIGTYPE * |
hasso | e42f5a3 | 2004-08-28 17:04:33 +0000 | [diff] [blame] | 102 | vtysh_signal_set (int signo, void (*func)(int)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 103 | { |
| 104 | int ret; |
| 105 | struct sigaction sig; |
| 106 | struct sigaction osig; |
| 107 | |
| 108 | sig.sa_handler = func; |
| 109 | sigemptyset (&sig.sa_mask); |
| 110 | sig.sa_flags = 0; |
| 111 | #ifdef SA_RESTART |
| 112 | sig.sa_flags |= SA_RESTART; |
| 113 | #endif /* SA_RESTART */ |
| 114 | |
| 115 | ret = sigaction (signo, &sig, &osig); |
| 116 | |
| 117 | if (ret < 0) |
| 118 | return (SIG_ERR); |
| 119 | else |
| 120 | return (osig.sa_handler); |
| 121 | } |
| 122 | |
| 123 | /* Initialization of signal handles. */ |
| 124 | void |
hasso | e42f5a3 | 2004-08-28 17:04:33 +0000 | [diff] [blame] | 125 | vtysh_signal_init () |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 126 | { |
hasso | e42f5a3 | 2004-08-28 17:04:33 +0000 | [diff] [blame] | 127 | vtysh_signal_set (SIGINT, sigint); |
| 128 | vtysh_signal_set (SIGTSTP, sigtstp); |
| 129 | vtysh_signal_set (SIGPIPE, SIG_IGN); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 130 | } |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 131 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 132 | /* Help information display. */ |
| 133 | static void |
| 134 | usage (int status) |
| 135 | { |
| 136 | if (status != 0) |
| 137 | fprintf (stderr, "Try `%s --help' for more information.\n", progname); |
| 138 | else |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 139 | printf ("Usage : %s [OPTION...]\n\n" \ |
Andrew J. Schorr | f366ad3 | 2006-07-27 18:01:41 +0000 | [diff] [blame] | 140 | "Integrated shell for Quagga routing software suite. \n\n" \ |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 141 | "-b, --boot Execute boot startup configuration\n" \ |
Andrew J. Schorr | f366ad3 | 2006-07-27 18:01:41 +0000 | [diff] [blame] | 142 | "-c, --command Execute argument as command\n" \ |
| 143 | "-d, --daemon Connect only to the specified daemon\n" \ |
| 144 | "-E, --echo Echo prompt and command in -c mode\n" \ |
Paul Jakma | 876b8be | 2006-10-15 23:35:57 +0000 | [diff] [blame] | 145 | "-C, --dryrun Check configuration for validity and exit\n" \ |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 146 | "-h, --help Display this help and exit\n\n" \ |
Andrew J. Schorr | f366ad3 | 2006-07-27 18:01:41 +0000 | [diff] [blame] | 147 | "Note that multiple commands may be executed from the command\n" \ |
| 148 | "line by passing multiple -c args, or by embedding linefeed\n" \ |
| 149 | "characters in one or more of the commands.\n\n" \ |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 150 | "Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS); |
| 151 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 152 | exit (status); |
| 153 | } |
| 154 | |
| 155 | /* VTY shell options, we use GNU getopt library. */ |
| 156 | struct option longopts[] = |
| 157 | { |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 158 | { "boot", no_argument, NULL, 'b'}, |
hasso | 4991f6c | 2004-04-06 11:36:17 +0000 | [diff] [blame] | 159 | /* For compatibility with older zebra/quagga versions */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 160 | { "eval", required_argument, NULL, 'e'}, |
hasso | 4991f6c | 2004-04-06 11:36:17 +0000 | [diff] [blame] | 161 | { "command", required_argument, NULL, 'c'}, |
Andrew J. Schorr | f366ad3 | 2006-07-27 18:01:41 +0000 | [diff] [blame] | 162 | { "daemon", required_argument, NULL, 'd'}, |
| 163 | { "echo", no_argument, NULL, 'E'}, |
Paul Jakma | 876b8be | 2006-10-15 23:35:57 +0000 | [diff] [blame] | 164 | { "dryrun", no_argument, NULL, 'C'}, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 165 | { "help", no_argument, NULL, 'h'}, |
Stephen Hemminger | 914131f | 2008-07-30 14:16:47 -0700 | [diff] [blame] | 166 | { "noerror", no_argument, NULL, 'n'}, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 167 | { 0 } |
| 168 | }; |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 169 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 170 | /* Read a string, and return a pointer to it. Returns NULL on EOF. */ |
| 171 | char * |
| 172 | vtysh_rl_gets () |
| 173 | { |
hasso | 4991f6c | 2004-04-06 11:36:17 +0000 | [diff] [blame] | 174 | HIST_ENTRY *last; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 175 | /* If the buffer has already been allocated, return the memory |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 176 | * to the free pool. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 177 | if (line_read) |
| 178 | { |
| 179 | free (line_read); |
| 180 | line_read = NULL; |
| 181 | } |
| 182 | |
| 183 | /* Get a line from the user. Change prompt according to node. XXX. */ |
| 184 | line_read = readline (vtysh_prompt ()); |
| 185 | |
hasso | 4991f6c | 2004-04-06 11:36:17 +0000 | [diff] [blame] | 186 | /* If the line has any text in it, save it on the history. But only if |
hasso | 95e735b | 2004-08-26 13:08:30 +0000 | [diff] [blame] | 187 | * last command in history isn't the same one. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 188 | if (line_read && *line_read) |
hasso | 4991f6c | 2004-04-06 11:36:17 +0000 | [diff] [blame] | 189 | { |
| 190 | using_history(); |
| 191 | last = previous_history(); |
Tomasz Pala | 3f4ab7f | 2009-06-24 22:23:11 +0100 | [diff] [blame] | 192 | if (!last || strcmp (last->line, line_read) != 0) { |
hasso | 4991f6c | 2004-04-06 11:36:17 +0000 | [diff] [blame] | 193 | add_history (line_read); |
Tomasz Pala | 3f4ab7f | 2009-06-24 22:23:11 +0100 | [diff] [blame] | 194 | append_history(1,history_file); |
| 195 | } |
hasso | 4991f6c | 2004-04-06 11:36:17 +0000 | [diff] [blame] | 196 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 197 | |
| 198 | return (line_read); |
| 199 | } |
hasso | b094d26 | 2004-08-25 12:22:00 +0000 | [diff] [blame] | 200 | |
Stephen Hemminger | 57fb974 | 2008-07-28 12:19:04 -0700 | [diff] [blame] | 201 | static void log_it(const char *line) |
| 202 | { |
| 203 | time_t t = time(NULL); |
| 204 | struct tm *tmp = localtime(&t); |
| 205 | char *user = getenv("USER") ? : "boot"; |
| 206 | char tod[64]; |
| 207 | |
| 208 | strftime(tod, sizeof tod, "%Y%m%d-%H:%M.%S", tmp); |
| 209 | |
| 210 | fprintf(logfile, "%s:%s %s\n", tod, user, line); |
| 211 | } |
| 212 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 213 | /* VTY shell main routine. */ |
| 214 | int |
| 215 | main (int argc, char **argv, char **env) |
| 216 | { |
| 217 | char *p; |
| 218 | int opt; |
Paul Jakma | 876b8be | 2006-10-15 23:35:57 +0000 | [diff] [blame] | 219 | int dryrun = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 220 | int boot_flag = 0; |
Andrew J. Schorr | f366ad3 | 2006-07-27 18:01:41 +0000 | [diff] [blame] | 221 | const char *daemon_name = NULL; |
| 222 | struct cmd_rec { |
| 223 | const char *line; |
| 224 | struct cmd_rec *next; |
| 225 | } *cmd = NULL; |
| 226 | struct cmd_rec *tail = NULL; |
| 227 | int echo_command = 0; |
Stephen Hemminger | 914131f | 2008-07-30 14:16:47 -0700 | [diff] [blame] | 228 | int no_error = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 229 | |
| 230 | /* Preserve name of myself. */ |
| 231 | progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]); |
| 232 | |
Stephen Hemminger | 57fb974 | 2008-07-28 12:19:04 -0700 | [diff] [blame] | 233 | /* if logging open now */ |
| 234 | if ((p = getenv("VTYSH_LOG")) != NULL) |
| 235 | logfile = fopen(p, "a"); |
| 236 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 237 | /* Option handling. */ |
| 238 | while (1) |
| 239 | { |
Stephen Hemminger | 914131f | 2008-07-30 14:16:47 -0700 | [diff] [blame] | 240 | opt = getopt_long (argc, argv, "be:c:d:nEhC", longopts, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 241 | |
| 242 | if (opt == EOF) |
| 243 | break; |
| 244 | |
| 245 | switch (opt) |
| 246 | { |
| 247 | case 0: |
| 248 | break; |
| 249 | case 'b': |
| 250 | boot_flag = 1; |
| 251 | break; |
| 252 | case 'e': |
hasso | 4991f6c | 2004-04-06 11:36:17 +0000 | [diff] [blame] | 253 | case 'c': |
Andrew J. Schorr | f366ad3 | 2006-07-27 18:01:41 +0000 | [diff] [blame] | 254 | { |
| 255 | struct cmd_rec *cr; |
| 256 | cr = XMALLOC(0, sizeof(*cr)); |
| 257 | cr->line = optarg; |
| 258 | cr->next = NULL; |
| 259 | if (tail) |
| 260 | tail->next = cr; |
| 261 | else |
| 262 | cmd = cr; |
| 263 | tail = cr; |
| 264 | } |
| 265 | break; |
| 266 | case 'd': |
| 267 | daemon_name = optarg; |
| 268 | break; |
Stephen Hemminger | 914131f | 2008-07-30 14:16:47 -0700 | [diff] [blame] | 269 | case 'n': |
| 270 | no_error = 1; |
| 271 | break; |
Andrew J. Schorr | f366ad3 | 2006-07-27 18:01:41 +0000 | [diff] [blame] | 272 | case 'E': |
| 273 | echo_command = 1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 274 | break; |
Paul Jakma | 876b8be | 2006-10-15 23:35:57 +0000 | [diff] [blame] | 275 | case 'C': |
| 276 | dryrun = 1; |
| 277 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 278 | case 'h': |
| 279 | usage (0); |
| 280 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 281 | default: |
| 282 | usage (1); |
| 283 | break; |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | /* Initialize user input buffer. */ |
| 288 | line_read = NULL; |
Stephen Hemminger | 0fbd62a | 2008-05-02 09:25:02 -0700 | [diff] [blame] | 289 | setlinebuf(stdout); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 290 | |
| 291 | /* Signal and others. */ |
hasso | e42f5a3 | 2004-08-28 17:04:33 +0000 | [diff] [blame] | 292 | vtysh_signal_init (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 293 | |
| 294 | /* Make vty structure and register commands. */ |
| 295 | vtysh_init_vty (); |
| 296 | vtysh_init_cmd (); |
| 297 | vtysh_user_init (); |
| 298 | vtysh_config_init (); |
| 299 | |
| 300 | vty_init_vtysh (); |
| 301 | |
Andrew J. Schorr | f366ad3 | 2006-07-27 18:01:41 +0000 | [diff] [blame] | 302 | /* Read vtysh configuration file before connecting to daemons. */ |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 303 | vtysh_read_config (config_default); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 304 | |
Paul Jakma | 876b8be | 2006-10-15 23:35:57 +0000 | [diff] [blame] | 305 | /* Start execution only if not in dry-run mode */ |
| 306 | if(dryrun) |
| 307 | return(0); |
| 308 | |
Stephen Hemminger | 914131f | 2008-07-30 14:16:47 -0700 | [diff] [blame] | 309 | /* Ignore error messages */ |
| 310 | if (no_error) |
| 311 | freopen("/dev/null", "w", stdout); |
| 312 | |
Andrew J. Schorr | f366ad3 | 2006-07-27 18:01:41 +0000 | [diff] [blame] | 313 | /* Make sure we pass authentication before proceeding. */ |
| 314 | vtysh_auth (); |
| 315 | |
| 316 | /* Do not connect until we have passed authentication. */ |
| 317 | if (vtysh_connect_all (daemon_name) <= 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 318 | { |
Andrew J. Schorr | f366ad3 | 2006-07-27 18:01:41 +0000 | [diff] [blame] | 319 | fprintf(stderr, "Exiting: failed to connect to any daemons.\n"); |
| 320 | exit(1); |
| 321 | } |
| 322 | |
| 323 | /* If eval mode. */ |
| 324 | if (cmd) |
| 325 | { |
| 326 | /* Enter into enable node. */ |
| 327 | vtysh_execute ("enable"); |
| 328 | |
| 329 | while (cmd != NULL) |
| 330 | { |
Stephen Hemminger | 57fb974 | 2008-07-28 12:19:04 -0700 | [diff] [blame] | 331 | int ret; |
Andrew J. Schorr | f366ad3 | 2006-07-27 18:01:41 +0000 | [diff] [blame] | 332 | char *eol; |
| 333 | |
| 334 | while ((eol = strchr(cmd->line, '\n')) != NULL) |
| 335 | { |
| 336 | *eol = '\0'; |
Stephen Hemminger | 57fb974 | 2008-07-28 12:19:04 -0700 | [diff] [blame] | 337 | |
Andrew J. Schorr | f366ad3 | 2006-07-27 18:01:41 +0000 | [diff] [blame] | 338 | if (echo_command) |
Stephen Hemminger | 57fb974 | 2008-07-28 12:19:04 -0700 | [diff] [blame] | 339 | printf("%s%s\n", vtysh_prompt(), cmd->line); |
| 340 | |
| 341 | if (logfile) |
| 342 | log_it(cmd->line); |
| 343 | |
| 344 | ret = vtysh_execute_no_pager(cmd->line); |
Stephen Hemminger | 914131f | 2008-07-30 14:16:47 -0700 | [diff] [blame] | 345 | if (!no_error && |
| 346 | ! (ret == CMD_SUCCESS || |
| 347 | ret == CMD_SUCCESS_DAEMON || |
| 348 | ret == CMD_WARNING)) |
Stephen Hemminger | 57fb974 | 2008-07-28 12:19:04 -0700 | [diff] [blame] | 349 | exit(1); |
| 350 | |
Andrew J. Schorr | f366ad3 | 2006-07-27 18:01:41 +0000 | [diff] [blame] | 351 | cmd->line = eol+1; |
| 352 | } |
Stephen Hemminger | 57fb974 | 2008-07-28 12:19:04 -0700 | [diff] [blame] | 353 | |
Andrew J. Schorr | f366ad3 | 2006-07-27 18:01:41 +0000 | [diff] [blame] | 354 | if (echo_command) |
| 355 | printf("%s%s\n", vtysh_prompt(), cmd->line); |
Stephen Hemminger | 57fb974 | 2008-07-28 12:19:04 -0700 | [diff] [blame] | 356 | |
| 357 | if (logfile) |
| 358 | log_it(cmd->line); |
| 359 | |
| 360 | ret = vtysh_execute_no_pager(cmd->line); |
Stephen Hemminger | 914131f | 2008-07-30 14:16:47 -0700 | [diff] [blame] | 361 | if (!no_error && |
| 362 | ! (ret == CMD_SUCCESS || |
| 363 | ret == CMD_SUCCESS_DAEMON || |
| 364 | ret == CMD_WARNING)) |
Stephen Hemminger | 57fb974 | 2008-07-28 12:19:04 -0700 | [diff] [blame] | 365 | exit(1); |
Andrew J. Schorr | f366ad3 | 2006-07-27 18:01:41 +0000 | [diff] [blame] | 366 | |
| 367 | { |
| 368 | struct cmd_rec *cr; |
| 369 | cr = cmd; |
| 370 | cmd = cmd->next; |
| 371 | XFREE(0, cr); |
| 372 | } |
| 373 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 374 | exit (0); |
| 375 | } |
| 376 | |
| 377 | /* Boot startup configuration file. */ |
| 378 | if (boot_flag) |
| 379 | { |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 380 | if (vtysh_read_config (integrate_default)) |
| 381 | { |
| 382 | fprintf (stderr, "Can't open configuration file [%s]\n", |
| 383 | integrate_default); |
| 384 | exit (1); |
| 385 | } |
| 386 | else |
| 387 | exit (0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | vtysh_pager_init (); |
| 391 | |
| 392 | vtysh_readline_init (); |
| 393 | |
| 394 | vty_hello (vty); |
| 395 | |
hasso | e7168df | 2004-10-03 20:11:32 +0000 | [diff] [blame] | 396 | /* Enter into enable node. */ |
| 397 | vtysh_execute ("enable"); |
| 398 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 399 | /* Preparation for longjmp() in sigtstp(). */ |
| 400 | sigsetjmp (jmpbuf, 1); |
| 401 | jmpflag = 1; |
| 402 | |
Tomasz Pala | 3f4ab7f | 2009-06-24 22:23:11 +0100 | [diff] [blame] | 403 | snprintf(history_file, sizeof(history_file), "%s/.history_quagga", getenv("HOME")); |
| 404 | read_history(history_file); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 405 | /* Main command loop. */ |
| 406 | while (vtysh_rl_gets ()) |
| 407 | vtysh_execute (line_read); |
| 408 | |
Tomasz Pala | 3f4ab7f | 2009-06-24 22:23:11 +0100 | [diff] [blame] | 409 | history_truncate_file(history_file,1000); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 410 | printf ("\n"); |
| 411 | |
| 412 | /* Rest in peace. */ |
| 413 | exit (0); |
| 414 | } |