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/gprs/gb_proxy_main.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'openbsc/src/gprs') diff --git a/openbsc/src/gprs/gb_proxy_main.c b/openbsc/src/gprs/gb_proxy_main.c index 32bbe3863..8ce83f1a1 100644 --- a/openbsc/src/gprs/gb_proxy_main.c +++ b/openbsc/src/gprs/gb_proxy_main.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -67,6 +68,7 @@ const char *openbsc_copyright = static struct log_target *stderr_target; static char *config_file = "osmo_gbproxy.cfg"; struct gbproxy_config gbcfg; +static int daemonize = 0; /* Pointer to the SGSN peer */ extern struct gbprox_peer *gbprox_peer_sgsn; @@ -126,6 +128,7 @@ static void print_help() printf(" Some useful help...\n"); printf(" -h --help this text\n"); printf(" -d option --debug=DNS:DGPRS,0:0 enable debugging\n"); + printf(" -D --daemonize Fork the process into a background daemon\n"); printf(" -c --config-file filename The config file to use.\n"); printf(" -s --disable-color\n"); printf(" -T --timestamp Prefix every log line with a timestamp\n"); @@ -140,6 +143,7 @@ static void handle_options(int argc, char **argv) static struct option long_options[] = { { "help", 0, 0, 'h' }, { "debug", 1, 0, 'd' }, + { "daemonize", 0, 0, 'D' }, { "config-file", 1, 0, 'c' }, { "disable-color", 0, 0, 's' }, { "timestamp", 0, 0, 'T' }, @@ -148,7 +152,7 @@ static void handle_options(int argc, char **argv) { 0, 0, 0, 0 } }; - c = getopt_long(argc, argv, "hd:c:sTVe:", + c = getopt_long(argc, argv, "hd:Dc:sTVe:", long_options, &option_index); if (c == -1) break; @@ -164,6 +168,9 @@ static void handle_options(int argc, char **argv) case 'd': log_parse_category_mask(stderr_target, optarg); break; + case 'D': + daemonize = 1; + break; case 'c': config_file = strdup(optarg); break; @@ -260,6 +267,14 @@ int main(int argc, char **argv) exit(2); } + if (daemonize) { + rc = osmo_daemonize(); + if (rc < 0) { + perror("Error during daemonize"); + exit(1); + } + } + /* Reset all the persistent NS-VCs that we've read from the config */ gbprox_reset_persistent_nsvcs(bssgp_nsi); -- cgit v1.2.3