aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo-bts-sysmo/main.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2012-05-31 21:02:18 +0200
committerHarald Welte <laforge@gnumonks.org>2012-05-31 21:02:18 +0200
commit700c645478249319dcf7e7e138c13dbbb9c04ba9 (patch)
treee526946b714abccb8ee21db36a3af4d770e4c643 /src/osmo-bts-sysmo/main.c
parent346e531222a38bd0399e1a17f8de4a9594538993 (diff)
add /var/lock/bts_rf_lock and /var/run/osmo-bts.pid for rf control
an external application can create /var/lock/bts_rf_lock and then kill the pid in /var/run/osmo-bts.pid in order to shut down the BTS. Any re-spawning scripts will trigger, but osmo-bts will refuse to start up until /var/lock/bts_rf_lock is removed again.
Diffstat (limited to 'src/osmo-bts-sysmo/main.c')
-rw-r--r--src/osmo-bts-sysmo/main.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/osmo-bts-sysmo/main.c b/src/osmo-bts-sysmo/main.c
index 2d84449c..1dcc8d39 100644
--- a/src/osmo-bts-sysmo/main.c
+++ b/src/osmo-bts-sysmo/main.c
@@ -24,7 +24,10 @@
#include <stdlib.h>
#include <errno.h>
#include <getopt.h>
+#include <limits.h>
#include <sys/signal.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@@ -41,6 +44,8 @@
#include <osmo-bts/vty.h>
#include <osmo-bts/bts_model.h>
+#define SYSMOBTS_RF_LOCK_PATH "/var/lock/bts_rf_lock"
+
#include "l1_if.h"
/* FIXME: read from real hardware */
@@ -202,8 +207,28 @@ static void signal_handler(int signal)
}
}
+static int write_pid_file(char *procname)
+{
+ FILE *outf;
+ char tmp[PATH_MAX+1];
+
+ snprintf(tmp, sizeof(tmp)-1, "/var/run/%s.pid", procname);
+ tmp[PATH_MAX-1] = '\0';
+
+ outf = fopen(tmp, "w");
+ if (!outf)
+ return -1;
+
+ fprintf(outf, "%d\n", getpid());
+
+ fclose(outf);
+
+ return 0;
+}
+
int main(int argc, char **argv)
{
+ struct stat st;
struct gsm_bts_role_bts *btsb;
struct ipabis_link *link;
void *tall_msgb_ctx;
@@ -228,7 +253,6 @@ int main(int argc, char **argv)
btsb = bts_role_bts(bts);
btsb->support.ciphers = (1 << 0) | (1 << 1) | (1 << 2);
-
rc = vty_read_config_file(config_file, NULL);
if (rc < 0) {
fprintf(stderr, "Failed to parse the config file: '%s'\n",
@@ -236,6 +260,12 @@ int main(int argc, char **argv)
exit(1);
}
+ if (stat(SYSMOBTS_RF_LOCK_PATH, &st) == 0) {
+ LOGP(DL1C, LOGL_NOTICE, "Not starting BTS due to RF_LOCK file present\n");
+ exit(23);
+ }
+ write_pid_file("osmo-bts");
+
rc = telnet_init(tall_bts_ctx, NULL, 4241);
if (rc < 0) {
fprintf(stderr, "Error initializing telnet\n");