David Lamparter | db93eec | 2015-05-05 11:04:59 +0200 | [diff] [blame] | 1 | /* |
| 2 | * generic CLI test helper functions |
| 3 | * |
| 4 | * Copyright (C) 2015 by David Lamparter, |
| 5 | * for Open Source Routing / NetDEF, Inc. |
| 6 | * |
| 7 | * Quagga is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2, or (at your option) any |
| 10 | * later version. |
| 11 | * |
| 12 | * Quagga is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with Quagga; see the file COPYING. If not, write to the Free |
| 19 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 20 | * 02111-1307, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <zebra.h> |
| 24 | |
| 25 | #include "thread.h" |
| 26 | #include "vty.h" |
| 27 | #include "command.h" |
| 28 | #include "memory.h" |
| 29 | #include "log.h" |
| 30 | |
| 31 | #include "common-cli.h" |
| 32 | |
| 33 | struct thread_master *master; |
| 34 | |
| 35 | int dump_args(struct vty *vty, const char *descr, |
| 36 | int argc, const char **argv) |
| 37 | { |
| 38 | int i; |
| 39 | vty_out (vty, "%s with %d args.%s", descr, argc, VTY_NEWLINE); |
| 40 | for (i = 0; i < argc; i++) |
| 41 | { |
| 42 | vty_out (vty, "[%02d]: %s%s", i, argv[i], VTY_NEWLINE); |
| 43 | } |
| 44 | |
| 45 | return CMD_SUCCESS; |
| 46 | } |
| 47 | |
| 48 | static void vty_do_exit(void) |
| 49 | { |
| 50 | printf ("\nend.\n"); |
| 51 | exit (0); |
| 52 | } |
| 53 | |
| 54 | /* main routine. */ |
| 55 | int |
| 56 | main (int argc, char **argv) |
| 57 | { |
| 58 | struct thread thread; |
| 59 | |
| 60 | /* Set umask before anything for security */ |
| 61 | umask (0027); |
| 62 | |
| 63 | /* master init. */ |
| 64 | master = thread_master_create (); |
| 65 | |
| 66 | zlog_default = openzlog ("common-cli", ZLOG_NONE, |
| 67 | LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); |
| 68 | zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED); |
| 69 | zlog_set_level (NULL, ZLOG_DEST_STDOUT, ZLOG_DISABLED); |
| 70 | zlog_set_level (NULL, ZLOG_DEST_MONITOR, LOG_DEBUG); |
| 71 | |
| 72 | /* Library inits. */ |
| 73 | cmd_init (1); |
| 74 | host.name = strdup ("test"); |
| 75 | |
| 76 | vty_init (master); |
| 77 | memory_init (); |
| 78 | |
| 79 | test_init (); |
| 80 | |
| 81 | vty_stdio (vty_do_exit); |
| 82 | |
| 83 | /* Fetch next active thread. */ |
| 84 | while (thread_fetch (master, &thread)) |
| 85 | thread_call (&thread); |
| 86 | |
| 87 | /* Not reached. */ |
| 88 | exit (0); |
| 89 | } |
| 90 | |