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.
diff --git a/openbsc/src/bsc/osmo_bsc_main.c b/openbsc/src/bsc/osmo_bsc_main.c
index 60b5225..7ddf91d 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 @@
 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 @@
 {
 	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 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 @@
 			{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 @@
 		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 @@
 		}
 	}
 
+	if (daemonize) {
+		rc = osmo_daemonize();
+		if (rc < 0) {
+			perror("Error during daemonize");
+			exit(1);
+		}
+	}
 
 	while (1) {
 		bsc_select_main(0);