]>
git.proxmox.com Git - mirror_frr.git/blob - tests/helpers/c/main.c
9bf56dde14d5dcccf6c9c72225a92c97751aa55b
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
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 along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <lib/version.h>
29 #include "memory_vty.h"
31 extern void test_init();
33 struct thread_master
*master
;
35 struct option longopts
[] = {{"daemon", no_argument
, NULL
, 'd'},
36 {"config_file", required_argument
, NULL
, 'f'},
37 {"help", no_argument
, NULL
, 'h'},
38 {"vty_addr", required_argument
, NULL
, 'A'},
39 {"vty_port", required_argument
, NULL
, 'P'},
40 {"version", no_argument
, NULL
, 'v'},
46 "Make the daemon exit\n")
51 static int timer_count
;
52 static int test_timer(struct thread
*thread
)
54 int *count
= THREAD_ARG(thread
);
56 printf("run %d of timer\n", (*count
)++);
57 thread_add_timer(master
, test_timer
, count
, 5, NULL
);
61 static void test_timer_init()
63 thread_add_timer(master
, test_timer
, &timer_count
, 10, NULL
);
66 static void test_vty_init()
68 install_element(VIEW_NODE
, &daemon_exit_cmd
);
71 /* Help information display. */
72 static void usage(char *progname
, int status
)
75 fprintf(stderr
, "Try `%s --help' for more information.\n",
78 printf("Usage : %s [OPTION...]\n\
79 Daemon which does 'slow' things.\n\n\
80 -d, --daemon Runs in daemon mode\n\
81 -f, --config_file Set configuration file name\n\
82 -A, --vty_addr Set vty's bind address\n\
83 -P, --vty_port Set vty's port number\n\
84 -v, --version Print program version\n\
85 -h, --help Display this help and exit\n\
88 progname
, FRR_BUG_ADDRESS
);
95 int main(int argc
, char **argv
)
98 char *vty_addr
= NULL
;
102 struct thread thread
;
103 char *config_file
= NULL
;
105 /* Set umask before anything for security */
108 /* get program name */
109 progname
= ((p
= strrchr(argv
[0], '/')) ? ++p
: argv
[0]);
112 master
= thread_master_create(NULL
);
117 opt
= getopt_long(argc
, argv
, "dhf:A:P:v", longopts
, 0);
126 config_file
= optarg
;
135 /* Deal with atoi() returning 0 on failure */
136 if (strcmp(optarg
, "0") == 0) {
140 vty_port
= atoi(optarg
);
141 vty_port
= (vty_port
? vty_port
: 4000);
144 print_version(progname
);
161 /* OSPF vty inits. */
164 /* Change to the daemon program. */
165 if (daemon_mode
&& daemon(0, 0) < 0) {
166 fprintf(stderr
, "daemon failed: %s", strerror(errno
));
170 /* Create VTY socket */
171 vty_serv_sock(vty_addr
, vty_port
, "/tmp/.heavy.sock");
173 /* Configuration file read*/
176 vty_read_config(config_file
, NULL
);
182 /* Fetch next active thread. */
183 while (thread_fetch(master
, &thread
))
184 thread_call(&thread
);