diff options
author | Harald Welte <laforge@gnumonks.org> | 2010-08-25 19:43:54 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2010-08-25 19:43:54 +0200 |
commit | 2c869efcd3e01d7c111526a3efc140fae5b843af (patch) | |
tree | 33dd151b1931ddee4c4b0f49b26dd316a86d286d /openbsc/src/gprs | |
parent | 305e2906aae7dbf45204f043394719c9a06c1227 (diff) |
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.
Diffstat (limited to 'openbsc/src/gprs')
-rw-r--r-- | openbsc/src/gprs/gb_proxy_main.c | 17 |
1 files changed, 16 insertions, 1 deletions
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 <osmocore/talloc.h> #include <osmocore/select.h> #include <osmocore/rate_ctr.h> +#include <osmocore/process.h> #include <openbsc/signal.h> #include <openbsc/debug.h> @@ -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); |