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/mgcp/mgcp_main.c b/openbsc/src/mgcp/mgcp_main.c
index 76f4667..21968aa 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 @@
 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 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 @@
 			print_version(1);
 			exit(0);
 			break;
+		case 'D':
+			daemonize = 1;
+			break;
 		default:
 			/* ignore */
 			break;
@@ -259,6 +265,14 @@
 	/* 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);