]>
git.proxmox.com Git - mirror_frr.git/blob - tests/helpers/c/main.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
7 #include <lib/version.h>
15 extern void test_init(void);
17 struct event_loop
*master
;
19 struct option longopts
[] = {{"daemon", no_argument
, NULL
, 'd'},
20 {"config_file", required_argument
, NULL
, 'f'},
21 {"help", no_argument
, NULL
, 'h'},
22 {"vty_addr", required_argument
, NULL
, 'A'},
23 {"vty_port", required_argument
, NULL
, 'P'},
24 {"version", no_argument
, NULL
, 'v'},
30 "Make the daemon exit\n")
35 static int timer_count
;
36 static void test_timer(struct event
*thread
)
38 int *count
= EVENT_ARG(thread
);
40 printf("run %d of timer\n", (*count
)++);
41 event_add_timer(master
, test_timer
, count
, 5, NULL
);
44 static void test_timer_init(void)
46 event_add_timer(master
, test_timer
, &timer_count
, 10, NULL
);
49 static void test_vty_init(void)
51 install_element(VIEW_NODE
, &daemon_exit_cmd
);
54 /* Help information display. */
55 static void usage(char *progname
, int status
)
58 fprintf(stderr
, "Try `%s --help' for more information.\n",
61 printf("Usage : %s [OPTION...]\n\
62 Daemon which does 'slow' things.\n\n\
63 -d, --daemon Runs in daemon mode\n\
64 -f, --config_file Set configuration file name\n\
65 -A, --vty_addr Set vty's bind address\n\
66 -P, --vty_port Set vty's port number\n\
67 -v, --version Print program version\n\
68 -h, --help Display this help and exit\n\
71 progname
, FRR_BUG_ADDRESS
);
78 int main(int argc
, char **argv
)
81 char *vty_addr
= NULL
;
86 char *config_file
= NULL
;
88 /* Set umask before anything for security */
91 /* get program name */
92 progname
= ((p
= strrchr(argv
[0], '/')) ? ++p
: argv
[0]);
95 master
= event_master_create(NULL
);
100 opt
= getopt_long(argc
, argv
, "dhf:A:P:v", longopts
, 0);
109 config_file
= optarg
;
118 /* Deal with atoi() returning 0 on failure */
119 if (strcmp(optarg
, "0") == 0) {
123 vty_port
= atoi(optarg
);
124 vty_port
= (vty_port
? vty_port
: 4000);
127 print_version(progname
);
141 vty_init(master
, false);
143 nb_init(master
, NULL
, 0, false);
145 /* OSPF vty inits. */
148 /* Change to the daemon program. */
149 if (daemon_mode
&& daemon(0, 0) < 0) {
150 fprintf(stderr
, "daemon failed: %s", strerror(errno
));
154 /* Create VTY socket */
155 vty_serv_sock(vty_addr
, vty_port
, "/tmp/.heavy.sock");
157 /* Configuration file read*/
160 vty_read_config(NULL
, config_file
, NULL
);
166 /* Fetch next active thread. */
167 while (event_fetch(master
, &thread
))