aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2010-08-25 19:43:54 +0200
committerHarald Welte <laforge@gnumonks.org>2010-08-25 19:43:54 +0200
commit2c869efcd3e01d7c111526a3efc140fae5b843af (patch)
tree33dd151b1931ddee4c4b0f49b26dd316a86d286d /openbsc
parent305e2906aae7dbf45204f043394719c9a06c1227 (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')
-rw-r--r--openbsc/configure.in2
-rw-r--r--openbsc/src/bsc/osmo_bsc_main.c16
-rw-r--r--openbsc/src/bsc_hack.c17
-rw-r--r--openbsc/src/gprs/gb_proxy_main.c17
-rw-r--r--openbsc/src/mgcp/mgcp_main.c16
-rw-r--r--openbsc/src/nat/bsc_nat.c14
6 files changed, 76 insertions, 6 deletions
diff --git a/openbsc/configure.in b/openbsc/configure.in
index c683f767..0167725a 100644
--- a/openbsc/configure.in
+++ b/openbsc/configure.in
@@ -43,7 +43,7 @@ AC_ARG_ENABLE([osmo-bsc], [AS_HELP_STRING([--enable-osmo-bsc], [Build the Osmo B
])
AM_CONDITIONAL(BUILD_BSC, test "x$osmo_ac_build_bsc" = "xyes")
-PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 0.1.16)
+PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 0.1.18)
PKG_CHECK_MODULES(LIBOSMOVTY, libosmovty >= 0.1.9)
dnl checks for header files
diff --git a/openbsc/src/bsc/osmo_bsc_main.c b/openbsc/src/bsc/osmo_bsc_main.c
index 60b5225e..7ddf91d2 100644
--- a/openbsc/src/bsc/osmo_bsc_main.c
+++ b/openbsc/src/bsc/osmo_bsc_main.c
@@ -25,6 +25,7 @@
#include <osmocom/vty/command.h>
#include <osmocore/talloc.h>
+#include <osmocore/process.h>
#include <osmocom/sccp/sccp.h>
@@ -41,6 +42,7 @@ static struct log_target *stderr_target;
struct gsm_network *bsc_gsmnet = 0;
static const char *config_file = "openbsc.cfg";
static const char *rf_ctl = NULL;
+static int daemonize = 0;
extern void bsc_vty_init(void);
extern int bsc_bootstrap_network(int (*layer4)(struct gsm_network *, int, void *), const char *cfg_file);
@@ -54,6 +56,7 @@ static void print_help()
{
printf(" Some useful help...\n");
printf(" -h --help this text\n");
+ printf(" -D --daemonize Fork the process into a background daemon\n");
printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM enable debugging\n");
printf(" -s --disable-color\n");
printf(" -T --timestamp. Print a timestamp in the debug output.\n");
@@ -71,6 +74,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'},
@@ -82,7 +86,7 @@ static void handle_options(int argc, char** argv)
{0, 0, 0, 0}
};
- c = getopt_long(argc, argv, "hd:sTc:e:r:t",
+ c = getopt_long(argc, argv, "hd:DsTc:e:r:t",
long_options, &option_index);
if (c == -1)
break;
@@ -98,6 +102,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;
@@ -179,6 +186,13 @@ int main(int argc, char **argv)
}
}
+ if (daemonize) {
+ rc = osmo_daemonize();
+ if (rc < 0) {
+ perror("Error during daemonize");
+ exit(1);
+ }
+ }
while (1) {
bsc_select_main(0);
diff --git a/openbsc/src/bsc_hack.c b/openbsc/src/bsc_hack.c
index 45156f39..4e8309b0 100644
--- a/openbsc/src/bsc_hack.c
+++ b/openbsc/src/bsc_hack.c
@@ -32,6 +32,7 @@
#include <openbsc/db.h>
#include <osmocore/select.h>
+#include <osmocore/process.h>
#include <openbsc/debug.h>
#include <openbsc/e1_input.h>
#include <osmocore/talloc.h>
@@ -48,6 +49,7 @@ struct gsm_network *bsc_gsmnet = 0;
static const char *database_name = "hlr.sqlite3";
static const char *config_file = "openbsc.cfg";
extern const char *openbsc_copyright;
+static int daemonize = 0;
/* timer to store statistics */
#define DB_SYNC_INTERVAL 60, 0
@@ -80,6 +82,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(" -c --config-file filename The config file to use.\n");
printf(" -s --disable-color\n");
printf(" -l --database db-name The database to use\n");
@@ -98,6 +101,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'},
{"database", 1, 0, 'l'},
@@ -110,7 +114,7 @@ static void handle_options(int argc, char** argv)
{0, 0, 0, 0}
};
- c = getopt_long(argc, argv, "hd:sl:ar:p:TPVc:e:",
+ c = getopt_long(argc, argv, "hd:Dsl:ar:p:TPVc:e:",
long_options, &option_index);
if (c == -1)
break;
@@ -126,6 +130,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 'l':
database_name = strdup(optarg);
break;
@@ -267,6 +274,14 @@ int main(int argc, char **argv)
signal(SIGUSR2, &signal_handler);
signal(SIGPIPE, SIG_IGN);
+ if (daemonize) {
+ rc = osmo_daemonize();
+ if (rc < 0) {
+ perror("Error during daemonize");
+ exit(1);
+ }
+ }
+
while (1) {
bsc_upqueue(bsc_gsmnet);
log_reset_context();
diff --git a/openbsc/src/gprs/gb_proxy_main.c b/openbsc/src/gprs/gb_proxy_main.c
index 32bbe386..8ce83f1a 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);
diff --git a/openbsc/src/mgcp/mgcp_main.c b/openbsc/src/mgcp/mgcp_main.c
index 76f4667f..21968aa6 100644
--- a/openbsc/src/mgcp/mgcp_main.c
+++ b/openbsc/src/mgcp/mgcp_main.c
@@ -35,6 +35,7 @@
#include <openbsc/debug.h>
#include <osmocore/msgb.h>
#include <osmocore/talloc.h>
+#include <osmocore/process.h>
#include <openbsc/gsm_data.h>
#include <osmocore/select.h>
#include <openbsc/mgcp.h>
@@ -57,6 +58,7 @@ void subscr_put() { abort(); }
static struct bsc_fd bfd;
static struct mgcp_config *cfg;
static int reset_endpoints = 0;
+static int daemonize = 0;
const char *openbsc_copyright =
"Copyright (C) 2009-2010 Holger Freyther and On-Waves\n"
@@ -85,11 +87,12 @@ static void handle_options(int argc, char** argv)
static struct option long_options[] = {
{"help", 0, 0, 'h'},
{"config-file", 1, 0, 'c'},
+ {"daemonize", 0, 0, 'D'},
{"version", 0, 0, 'V'},
{0, 0, 0, 0},
};
- c = getopt_long(argc, argv, "hc:V", long_options, &option_index);
+ c = getopt_long(argc, argv, "hc:VD", long_options, &option_index);
if (c == -1)
break;
@@ -106,6 +109,9 @@ static void handle_options(int argc, char** argv)
print_version(1);
exit(0);
break;
+ case 'D':
+ daemonize = 1;
+ break;
default:
/* ignore */
break;
@@ -259,6 +265,14 @@ int main(int argc, char** argv)
/* initialisation */
srand(time(NULL));
+ if (daemonize) {
+ rc = osmo_daemonize();
+ if (rc < 0) {
+ perror("Error during daemonize");
+ exit(1);
+ }
+ }
+
/* main loop */
while (1) {
bsc_select_main(0);
diff --git a/openbsc/src/nat/bsc_nat.c b/openbsc/src/nat/bsc_nat.c
index e029b117..997a57f4 100644
--- a/openbsc/src/nat/bsc_nat.c
+++ b/openbsc/src/nat/bsc_nat.c
@@ -46,6 +46,7 @@
#include <osmocore/gsm0808.h>
#include <osmocore/talloc.h>
+#include <osmocore/process.h>
#include <osmocore/protocol/gsm_08_08.h>
@@ -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;