]>
git.proxmox.com Git - mirror_frr.git/blob - tests/helpers/c/main.c
2 * This file is part of Quagga.
4 * Quagga is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2, or (at your option) any
9 * Quagga is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; see the file COPYING; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <lib/version.h>
29 extern void test_init(void);
31 struct thread_master
*master
;
33 struct option longopts
[] = {{"daemon", no_argument
, NULL
, 'd'},
34 {"config_file", required_argument
, NULL
, 'f'},
35 {"help", no_argument
, NULL
, 'h'},
36 {"vty_addr", required_argument
, NULL
, 'A'},
37 {"vty_port", required_argument
, NULL
, 'P'},
38 {"version", no_argument
, NULL
, 'v'},
44 "Make the daemon exit\n")
49 static int timer_count
;
50 static void test_timer(struct thread
*thread
)
52 int *count
= THREAD_ARG(thread
);
54 printf("run %d of timer\n", (*count
)++);
55 thread_add_timer(master
, test_timer
, count
, 5, NULL
);
58 static void test_timer_init(void)
60 thread_add_timer(master
, test_timer
, &timer_count
, 10, NULL
);
63 static void test_vty_init(void)
65 install_element(VIEW_NODE
, &daemon_exit_cmd
);
68 /* Help information display. */
69 static void usage(char *progname
, int status
)
72 fprintf(stderr
, "Try `%s --help' for more information.\n",
75 printf("Usage : %s [OPTION...]\n\
76 Daemon which does 'slow' things.\n\n\
77 -d, --daemon Runs in daemon mode\n\
78 -f, --config_file Set configuration file name\n\
79 -A, --vty_addr Set vty's bind address\n\
80 -P, --vty_port Set vty's port number\n\
81 -v, --version Print program version\n\
82 -h, --help Display this help and exit\n\
85 progname
, FRR_BUG_ADDRESS
);
92 int main(int argc
, char **argv
)
95 char *vty_addr
= NULL
;
100 char *config_file
= NULL
;
102 /* Set umask before anything for security */
105 /* get program name */
106 progname
= ((p
= strrchr(argv
[0], '/')) ? ++p
: argv
[0]);
109 master
= thread_master_create(NULL
);
114 opt
= getopt_long(argc
, argv
, "dhf:A:P:v", longopts
, 0);
123 config_file
= optarg
;
132 /* Deal with atoi() returning 0 on failure */
133 if (strcmp(optarg
, "0") == 0) {
137 vty_port
= atoi(optarg
);
138 vty_port
= (vty_port
? vty_port
: 4000);
141 print_version(progname
);
155 vty_init(master
, false);
157 nb_init(master
, NULL
, 0, false);
159 /* OSPF vty inits. */
162 /* Change to the daemon program. */
163 if (daemon_mode
&& daemon(0, 0) < 0) {
164 fprintf(stderr
, "daemon failed: %s", strerror(errno
));
168 /* Create VTY socket */
169 vty_serv_sock(vty_addr
, vty_port
, "/tmp/.heavy.sock");
171 /* Configuration file read*/
174 vty_read_config(NULL
, config_file
, NULL
);
180 /* Fetch next active thread. */
181 while (thread_fetch(master
, &thread
))
182 thread_call(&thread
);