Skip to content

Commit

Permalink
Split main, introduce NO_MAIN.
Browse files Browse the repository at this point in the history
  • Loading branch information
jech committed May 29, 2024
1 parent 4c09a45 commit 2d9c1b0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
62 changes: 37 additions & 25 deletions babeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,14 @@ kernel_link_notify(int add, struct kernel_link *link, void *closure)
}
}

#ifndef NO_MAIN
int
main(int argc, char **argv)
{
struct sockaddr_in6 sin6;
int rc, fd, i, opt;
time_t expiry_time, source_expiry_time, kernel_dump_time;
const char **config_files = NULL;
int num_config_files = 0;
void *vrc;
unsigned int seed;
struct interface *ifp;

gettime(&now);

Expand Down Expand Up @@ -378,12 +375,45 @@ main(int argc, char **argv)
rc = write(pfd, buf, len);
if(rc < len) {
perror("write(pidfile)");
goto fail_pid;
unlink(pidfile);
exit(1);
}

close(pfd);
}

return babel_main(argv + optind, argc - optind);

usage:
fprintf(stderr,
"%s\n"
"Syntax: babeld "
"[-V] [-m multicast_address] [-p port] [-S state-file]\n"
" "
"[-h hello] [-H wired_hello] [-z kind[,factor]]\n"
" "
"[-g port] [-G port] [-k metric] [-A metric] [-s] [-l] [-w] [-r]\n"
" "
"[-t table] [-T table] [-c file] [-C statement]\n"
" "
"[-d level] [-D] [-L logfile] [-I pidfile]\n"
" "
"interface...\n",
BABELD_VERSION);
exit(1);

}
#endif

int
babel_main(char **interface_names, int num_interface_names)
{
struct interface *ifp;
time_t expiry_time, source_expiry_time, kernel_dump_time;
struct sockaddr_in6 sin6;
void *vrc;
int i, fd, rc;

rc = kernel_setup(1);
if(rc < 0) {
fprintf(stderr, "kernel_setup failed.\n");
Expand All @@ -403,8 +433,8 @@ main(int argc, char **argv)
goto fail;
}

for(i = optind; i < argc; i++) {
vrc = add_interface(argv[i], NULL);
for(i = 0; i < num_interface_names; i++) {
vrc = add_interface(interface_names[i], NULL);
if(vrc == NULL)
goto fail;
}
Expand Down Expand Up @@ -815,24 +845,6 @@ main(int argc, char **argv)
debugf("Done.\n");
return 0;

usage:
fprintf(stderr,
"%s\n"
"Syntax: babeld "
"[-V] [-m multicast_address] [-p port] [-S state-file]\n"
" "
"[-h hello] [-H wired_hello] [-z kind[,factor]]\n"
" "
"[-g port] [-G port] [-k metric] [-A metric] [-s] [-l] [-w] [-r]\n"
" "
"[-t table] [-T table] [-c file] [-C statement]\n"
" "
"[-d level] [-D] [-L logfile] [-I pidfile]\n"
" "
"interface...\n",
BABELD_VERSION);
exit(1);

fail:
FOR_ALL_INTERFACES(ifp) {
if(!if_up(ifp))
Expand Down
1 change: 1 addition & 0 deletions babeld.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ extern int kernel_check_interval;
extern int max_request_hopcount;
extern int shutdown_delay_msec;

int babel_main(char **interface_names, int num_interface_names);
void schedule_neighbours_check(int msecs, int override);
void schedule_interfaces_check(int msecs, int override);
int resize_receive_buffer(int size);
Expand Down

0 comments on commit 2d9c1b0

Please sign in to comment.