1998-05-15 07:56:13 +00:00
|
|
|
/*
|
|
|
|
* BIRD Internet Routing Daemon -- Unix Entry Point
|
|
|
|
*
|
2000-01-16 16:44:50 +00:00
|
|
|
* (c) 1998--2000 Martin Mares <mj@ucw.cz>
|
1998-05-15 07:56:13 +00:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
2015-08-05 09:42:40 +00:00
|
|
|
#ifndef _GNU_SOURCE
|
2015-08-19 12:48:37 +00:00
|
|
|
#define _GNU_SOURCE
|
2015-08-05 09:42:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <grp.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <libgen.h>
|
|
|
|
|
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "lib/lists.h"
|
|
|
|
#include "lib/resource.h"
|
|
|
|
#include "lib/socket.h"
|
|
|
|
#include "lib/event.h"
|
|
|
|
#include "lib/string.h"
|
|
|
|
#include "nest/route.h"
|
|
|
|
#include "nest/protocol.h"
|
|
|
|
#include "nest/iface.h"
|
|
|
|
#include "nest/cli.h"
|
|
|
|
#include "nest/locks.h"
|
|
|
|
#include "conf/conf.h"
|
|
|
|
#include "filter/filter.h"
|
|
|
|
|
|
|
|
#include "unix.h"
|
|
|
|
#include "krt.h"
|
|
|
|
|
|
|
|
#include "lib/main_helper.h"
|
|
|
|
|
1998-06-03 08:43:44 +00:00
|
|
|
/*
|
|
|
|
* Hic Est main()
|
|
|
|
*/
|
1998-05-15 07:56:13 +00:00
|
|
|
|
|
|
|
int
|
1999-02-13 19:43:21 +00:00
|
|
|
main(int argc, char **argv)
|
1998-05-15 07:56:13 +00:00
|
|
|
{
|
1999-03-04 11:36:26 +00:00
|
|
|
#ifdef HAVE_LIBDMALLOC
|
|
|
|
if (!getenv("DMALLOC_OPTIONS"))
|
|
|
|
dmalloc_debug(0x2f03d00);
|
|
|
|
#endif
|
|
|
|
|
1999-02-13 19:43:21 +00:00
|
|
|
parse_args(argc, argv);
|
1999-12-06 13:45:56 +00:00
|
|
|
if (debug_flag == 1)
|
|
|
|
log_init_debug("");
|
2010-04-07 09:00:36 +00:00
|
|
|
log_switch(debug_flag, NULL, NULL);
|
1999-02-13 19:43:21 +00:00
|
|
|
|
1998-11-27 21:09:57 +00:00
|
|
|
resource_init();
|
1999-12-09 18:54:20 +00:00
|
|
|
olock_init();
|
1998-05-24 14:50:18 +00:00
|
|
|
io_init();
|
1998-05-20 11:54:33 +00:00
|
|
|
rt_init();
|
1998-05-26 21:42:05 +00:00
|
|
|
if_init();
|
2012-03-18 16:32:30 +00:00
|
|
|
roa_init();
|
2012-12-26 11:40:48 +00:00
|
|
|
config_init();
|
1998-11-27 21:09:57 +00:00
|
|
|
|
2011-05-15 14:29:44 +00:00
|
|
|
uid_t use_uid = get_uid(use_user);
|
|
|
|
gid_t use_gid = get_gid(use_group);
|
|
|
|
|
2010-03-17 11:19:22 +00:00
|
|
|
if (!parse_and_exit)
|
2011-05-15 14:29:44 +00:00
|
|
|
{
|
|
|
|
test_old_bird(path_control_socket);
|
|
|
|
cli_init_unix(use_uid, use_gid);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (use_gid)
|
|
|
|
drop_gid(use_gid);
|
|
|
|
|
|
|
|
if (use_uid)
|
|
|
|
drop_uid(use_uid);
|
2010-03-17 11:19:22 +00:00
|
|
|
|
2013-10-05 17:30:12 +00:00
|
|
|
if (!parse_and_exit)
|
|
|
|
open_pid_file();
|
|
|
|
|
1998-10-18 11:53:21 +00:00
|
|
|
protos_build();
|
2000-04-01 10:19:47 +00:00
|
|
|
proto_build(&proto_unix_kernel);
|
|
|
|
proto_build(&proto_unix_iface);
|
1998-11-27 21:09:57 +00:00
|
|
|
|
2013-10-05 18:12:28 +00:00
|
|
|
struct config *conf = read_config();
|
1998-05-26 21:42:05 +00:00
|
|
|
|
2009-11-19 10:44:17 +00:00
|
|
|
if (parse_and_exit)
|
|
|
|
exit(0);
|
|
|
|
|
2013-10-05 20:45:08 +00:00
|
|
|
if (!(debug_flag||run_in_foreground))
|
2000-05-08 19:10:36 +00:00
|
|
|
{
|
|
|
|
pid_t pid = fork();
|
|
|
|
if (pid < 0)
|
|
|
|
die("fork: %m");
|
2000-05-08 22:31:34 +00:00
|
|
|
if (pid)
|
2000-05-08 19:10:36 +00:00
|
|
|
return 0;
|
|
|
|
setsid();
|
2007-06-20 07:33:26 +00:00
|
|
|
close(0);
|
|
|
|
if (open("/dev/null", O_RDWR) < 0)
|
|
|
|
die("Cannot open /dev/null: %m");
|
|
|
|
dup2(0, 1);
|
|
|
|
dup2(0, 2);
|
2000-05-08 19:10:36 +00:00
|
|
|
}
|
|
|
|
|
2014-02-07 12:09:55 +00:00
|
|
|
main_thread_init();
|
|
|
|
|
2013-10-05 17:30:12 +00:00
|
|
|
write_pid_file();
|
|
|
|
|
1998-05-24 14:50:18 +00:00
|
|
|
signal_init();
|
|
|
|
|
2013-10-05 18:12:28 +00:00
|
|
|
config_commit(conf, RECONFIG_HARD, 0);
|
|
|
|
|
2014-03-20 13:07:12 +00:00
|
|
|
graceful_restart_init();
|
|
|
|
|
2000-05-04 20:52:28 +00:00
|
|
|
#ifdef LOCAL_DEBUG
|
|
|
|
async_dump_flag = 1;
|
|
|
|
#endif
|
1998-05-26 21:42:05 +00:00
|
|
|
|
2010-02-06 21:57:51 +00:00
|
|
|
log(L_INFO "Started");
|
2000-03-12 21:01:38 +00:00
|
|
|
DBG("Entering I/O loop.\n");
|
1998-05-15 07:56:13 +00:00
|
|
|
|
1998-05-24 14:50:18 +00:00
|
|
|
io_loop();
|
1998-12-20 14:27:37 +00:00
|
|
|
bug("I/O loop died");
|
1998-05-15 07:56:13 +00:00
|
|
|
}
|