mobile: Store N.ba files in same directory as config file
authorHarald Welte <laforge@gnumonks.org>
Wed, 2 Mar 2011 10:00:59 +0000 (11:00 +0100)
committerHarald Welte <laforge@gnumonks.org>
Wed, 2 Mar 2011 10:00:59 +0000 (11:00 +0100)
This should remove the last dependency to hard-coded system-wide /etc/osmocom

src/host/layer23/include/osmocom/bb/mobile/app_mobile.h
src/host/layer23/src/mobile/gsm322.c
src/host/layer23/src/mobile/main.c

index 138fbe0..4010a68 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef APP_MOBILE_H
 #define APP_MOBILE_H
 
+char *config_dir;
+
 int l23_app_init(int (*mncc_recv)(struct osmocom_ms *ms, int, void *),
        const char *config_file, uint16_t vty_port);
 int l23_app_exit(void);
index 3c920e4..1996f93 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <limits.h>
 
 #include <osmocore/msgb.h>
 #include <osmocore/talloc.h>
@@ -3463,7 +3464,7 @@ int gsm322_init(struct osmocom_ms *ms)
        struct gsm322_plmn *plmn = &ms->plmn;
        struct gsm322_cellsel *cs = &ms->cellsel;
        FILE *fp;
-       char filename[128];
+       char filename[PATH_MAX];
        int i;
        struct gsm322_ba_list *ba;
        uint8_t buf[4];
@@ -3494,7 +3495,7 @@ int gsm322_init(struct osmocom_ms *ms)
                        cs->list[i].flags |= GSM322_CS_FLAG_SUPPORT;
 
        /* read BA list */
-       sprintf(filename, "/etc/osmocom/%s.ba", ms->name);
+       sprintf(filename, "%s/%s.ba", config_dir, ms->name);
        fp = fopen(filename, "r");
        if (fp) {
                int rc;
@@ -3535,7 +3536,7 @@ int gsm322_exit(struct osmocom_ms *ms)
        struct llist_head *lh, *lh2;
        struct msgb *msg;
        FILE *fp;
-       char filename[128];
+       char filename[PATH_MAX];
        struct gsm322_ba_list *ba;
        uint8_t buf[4];
        int i;
@@ -3561,7 +3562,7 @@ int gsm322_exit(struct osmocom_ms *ms)
        }
 
        /* store BA list */
-       sprintf(filename, "/etc/osmocom/%s.ba", ms->name);
+       sprintf(filename, "%s/%s.ba", config_dir, ms->name);
        fp = fopen(filename, "w");
        if (fp) {
                int rc;
@@ -3601,5 +3602,3 @@ int gsm322_exit(struct osmocom_ms *ms)
        }
        return 0;
 }
-
-
index 5c66510..cd72d13 100644 (file)
@@ -42,6 +42,7 @@
 #include <fcntl.h>
 #include <signal.h>
 #include <time.h>
+#include <libgen.h>
 
 struct log_target *stderr_target;
 
@@ -50,6 +51,7 @@ struct llist_head ms_list;
 static uint32_t gsmtap_ip = 0;
 unsigned short vty_port = 4247;
 int debug_set = 0;
+char *config_dir = NULL;
 
 int mobile_delete(struct osmocom_ms *ms, int force);
 int mobile_signal_cb(unsigned int subsys, unsigned int signal,
@@ -183,8 +185,11 @@ int main(int argc, char **argv)
                if (config_file != NULL)
                        snprintf(config_file, len, "%s/%s", home, osmocomcfg);
        }
+       /* save the config file directory name */
+       config_dir = talloc_strdup(l23_ctx, config_file);
+       config_dir = dirname(config_dir);
+
        rc = l23_app_init(NULL, config_file, vty_port);
-       talloc_free(config_file);
        if (rc)
                exit(rc);