From 2c869efcd3e01d7c111526a3efc140fae5b843af Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 25 Aug 2010 19:43:54 +0200 Subject: Introduce '-D' commandline option to daemonize processes This uses the osmo_daemonize() function of libosmocore >= 0.1.18, and is now implemented for bac_nat, osmo-bsc, bsc_hack, osmo-gbproxy and bsc_mgcp. This means only osmo-sgsn is missing, which currently has no option parsing at all. --- openbsc/src/nat/bsc_nat.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'openbsc/src/nat/bsc_nat.c') diff --git a/openbsc/src/nat/bsc_nat.c b/openbsc/src/nat/bsc_nat.c index e029b1176..997a57f44 100644 --- a/openbsc/src/nat/bsc_nat.c +++ b/openbsc/src/nat/bsc_nat.c @@ -46,6 +46,7 @@ #include #include +#include #include @@ -65,6 +66,7 @@ static struct in_addr local_addr; static struct bsc_fd bsc_listen; static const char *msc_ip = NULL; static struct timer_list sccp_close; +static int daemonize = 0; const char *openbsc_copyright = "Copyright (C) 2010 Holger Hans Peter Freyther and On-Waves\n" @@ -994,6 +996,7 @@ static void print_help() printf(" Some useful help...\n"); printf(" -h --help this text\n"); printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM enable debugging\n"); + printf(" -D --daemonize Fork the process into a background daemon\n"); printf(" -s --disable-color\n"); printf(" -c --config-file filename The config file to use.\n"); printf(" -m --msc=IP. The address of the MSC.\n"); @@ -1106,8 +1109,9 @@ static struct vty_app_info vty_info = { int main(int argc, char** argv) { - talloc_init_ctx(); + int rc; + talloc_init_ctx(); log_init(&log_info); stderr_target = log_target_create_stderr(); @@ -1182,6 +1186,14 @@ int main(int argc, char** argv) signal(SIGUSR1, &signal_handler); signal(SIGPIPE, SIG_IGN); + if (daemonize) { + rc = osmo_daemonize(); + if (rc < 0) { + perror("Error during daemonize"); + exit(1); + } + } + /* recycle timer */ sccp_set_log_area(DSCCP); sccp_close.cb = sccp_close_unconfirmed; -- cgit v1.2.3