common-cli.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #include <zebra.h>
  23. #include "thread.h"
  24. #include "vty.h"
  25. #include "command.h"
  26. #include "memory.h"
  27. #include "log.h"
  28. #include "common-cli.h"
  29. struct thread_master *master;
  30. int dump_args(struct vty *vty, const char *descr,
  31. int argc, const char **argv)
  32. {
  33. int i;
  34. vty_out (vty, "%s with %d args.%s", descr, argc, VTY_NEWLINE);
  35. for (i = 0; i < argc; i++)
  36. {
  37. vty_out (vty, "[%02d]: %s%s", i, argv[i], VTY_NEWLINE);
  38. }
  39. return CMD_SUCCESS;
  40. }
  41. static void vty_do_exit(void)
  42. {
  43. printf ("\nend.\n");
  44. exit (0);
  45. }
  46. /* main routine. */
  47. int
  48. main (int argc, char **argv)
  49. {
  50. /* Set umask before anything for security */
  51. umask (0027);
  52. /* master init. */
  53. master = thread_master_create ();
  54. zlog_default = openzlog ("common-cli", ZLOG_NONE,
  55. LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
  56. zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED);
  57. zlog_set_level (NULL, ZLOG_DEST_STDOUT, ZLOG_DISABLED);
  58. zlog_set_level (NULL, ZLOG_DEST_MONITOR, LOG_DEBUG);
  59. /* Library inits. */
  60. cmd_init (1);
  61. host.name = strdup ("test");
  62. vty_init (master);
  63. memory_init ();
  64. test_init ();
  65. vty_stdio (vty_do_exit);
  66. /* Fetch next active thread. */
  67. thread_main (master);
  68. /* Not reached. */
  69. exit (0);
  70. }