ospf6d: fix warnings from recent prefix bit commit
[jleu-quagga.git] / tests / main.c
blobe0fbb4d51530b786aabb39a88a0a5c2c741ee016
1 /*
2 * $Id: main.c,v 1.1 2005/04/25 16:42:24 paul Exp $
4 * This file is part of Quagga.
6 * Quagga 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.
11 * Quagga 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.
16 * You should have received a copy of the GNU General Public License
17 * along with Quagga; 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.
22 #include <zebra.h>
24 #include <lib/version.h>
25 #include "getopt.h"
26 #include "thread.h"
27 #include "vty.h"
28 #include "command.h"
29 #include "memory.h"
31 extern void test_init();
33 struct thread_master *master;
35 struct option longopts[] =
37 { "daemon", no_argument, NULL, 'd'},
38 { "config_file", required_argument, NULL, 'f'},
39 { "help", no_argument, NULL, 'h'},
40 { "vty_addr", required_argument, NULL, 'A'},
41 { "vty_port", required_argument, NULL, 'P'},
42 { "version", no_argument, NULL, 'v'},
43 { 0 }
46 DEFUN (daemon_exit,
47 daemon_exit_cmd,
48 "daemon-exit",
49 "Make the daemon exit\n")
51 exit(0);
54 static int timer_count;
55 int
56 test_timer (struct thread *thread)
58 int *count = THREAD_ARG(thread);
60 printf ("run %d of timer\n", (*count)++);
61 thread_add_timer (master, test_timer, count, 5);
62 return 0;
65 static void
66 test_timer_init()
68 thread_add_timer (master, test_timer, &timer_count, 10);
71 static void
72 test_vty_init()
74 install_element (VIEW_NODE, &daemon_exit_cmd);
77 /* Help information display. */
78 static void
79 usage (char *progname, int status)
81 if (status != 0)
82 fprintf (stderr, "Try `%s --help' for more information.\n", progname);
83 else
85 printf ("Usage : %s [OPTION...]\n\
86 Daemon which does 'slow' things.\n\n\
87 -d, --daemon Runs in daemon mode\n\
88 -f, --config_file Set configuration file name\n\
89 -A, --vty_addr Set vty's bind address\n\
90 -P, --vty_port Set vty's port number\n\
91 -v, --version Print program version\n\
92 -h, --help Display this help and exit\n\
93 \n\
94 Report bugs to %s\n", progname, ZEBRA_BUG_ADDRESS);
96 exit (status);
100 /* main routine. */
102 main (int argc, char **argv)
104 char *p;
105 char *vty_addr = NULL;
106 int vty_port = 4000;
107 int daemon_mode = 0;
108 char *progname;
109 struct thread thread;
110 char *config_file = NULL;
112 /* Set umask before anything for security */
113 umask (0027);
115 /* get program name */
116 progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);
118 /* master init. */
119 master = thread_master_create ();
121 while (1)
123 int opt;
125 opt = getopt_long (argc, argv, "dhf:A:P:v", longopts, 0);
127 if (opt == EOF)
128 break;
130 switch (opt)
132 case 0:
133 break;
134 case 'f':
135 config_file = optarg;
136 break;
137 case 'd':
138 daemon_mode = 1;
139 break;
140 case 'A':
141 vty_addr = optarg;
142 break;
143 case 'P':
144 /* Deal with atoi() returning 0 on failure */
145 if (strcmp(optarg, "0") == 0)
147 vty_port = 0;
148 break;
150 vty_port = atoi (optarg);
151 vty_port = (vty_port ? vty_port : 4000);
152 break;
153 case 'v':
154 print_version (progname);
155 exit (0);
156 break;
157 case 'h':
158 usage (progname, 0);
159 break;
160 default:
161 usage (progname, 1);
162 break;
166 /* Library inits. */
167 cmd_init (1);
168 vty_init (master);
169 memory_init ();
171 /* OSPF vty inits. */
172 test_vty_init ();
174 sort_node ();
176 /* Change to the daemon program. */
177 if (daemon_mode && daemon (0, 0) < 0)
179 fprintf(stderr, "daemon failed: %s", strerror(errno));
180 exit (1);
183 /* Create VTY socket */
184 vty_serv_sock (vty_addr, vty_port, "/tmp/.heavy.sock");
186 /* Configuration file read*/
187 if (!config_file)
188 usage (progname, 1);
189 vty_read_config (config_file, NULL);
191 test_timer_init();
193 test_init();
195 /* Fetch next active thread. */
196 while (thread_fetch (master, &thread))
197 thread_call (&thread);
199 /* Not reached. */
200 exit (0);