summaryrefslogtreecommitdiffstats
path: root/src/shared/libosmocore/src
diff options
context:
space:
mode:
authorSylvain Munaut <tnt@246tNt.com>2010-09-17 14:40:56 +0200
committerSylvain Munaut <tnt@246tNt.com>2010-09-17 14:40:56 +0200
commit8f553d57cb44c8797d456a27adfb6637aa1bd1c6 (patch)
treef3d908122b9f00bbf49ade0e839ff43e5ea04f27 /src/shared/libosmocore/src
parent66d8352a24a0dae83605b7e31c0e0427365ce1ac (diff)
parentaf5ee34c353ea2868a4b04b227bc1b511e1ac42b (diff)
Merge commit 'af5ee34c353ea2868a4b04b227bc1b511e1ac42b'
Diffstat (limited to 'src/shared/libosmocore/src')
-rw-r--r--src/shared/libosmocore/src/Makefile.am4
-rw-r--r--src/shared/libosmocore/src/gsm0808.c2
-rw-r--r--src/shared/libosmocore/src/logging.c67
-rw-r--r--src/shared/libosmocore/src/plugin.c1
-rw-r--r--src/shared/libosmocore/src/process.c74
-rw-r--r--src/shared/libosmocore/src/select.c12
-rw-r--r--src/shared/libosmocore/src/vty/Makefile.am1
-rw-r--r--src/shared/libosmocore/src/vty/command.c18
-rw-r--r--src/shared/libosmocore/src/vty/telnet_interface.c9
-rw-r--r--src/shared/libosmocore/src/vty/vty.c9
10 files changed, 181 insertions, 16 deletions
diff --git a/src/shared/libosmocore/src/Makefile.am b/src/shared/libosmocore/src/Makefile.am
index e197e179..1e97bb9b 100644
--- a/src/shared/libosmocore/src/Makefile.am
+++ b/src/shared/libosmocore/src/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS=vty
+SUBDIRS=. vty
# This is _NOT_ the library release version, it's an API version.
# Please read Chapter 6 "Library interface versions" of the libtool documentation before making any modification
@@ -13,7 +13,7 @@ libosmocore_la_SOURCES = timer.c select.c signal.c msgb.c rxlev_stat.c \
tlv_parser.c bitvec.c comp128.c gsm_utils.c statistics.c \
write_queue.c utils.c rsl.c gsm48.c gsm48_ie.c \
logging.c gsm0808.c rate_ctr.c gsmtap_util.c \
- gprs_cipher_core.c crc16.c panic.c
+ gprs_cipher_core.c crc16.c panic.c process.c
if ENABLE_PLUGIN
libosmocore_la_SOURCES += plugin.c
diff --git a/src/shared/libosmocore/src/gsm0808.c b/src/shared/libosmocore/src/gsm0808.c
index c8dc6645..42a73b9f 100644
--- a/src/shared/libosmocore/src/gsm0808.c
+++ b/src/shared/libosmocore/src/gsm0808.c
@@ -302,6 +302,8 @@ static const struct tlv_definition bss_att_tlvdef = {
[GSM0808_IE_CELL_IDENTIFIER] = { TLV_TYPE_TLV },
[GSM0808_IE_CHOSEN_CHANNEL] = { TLV_TYPE_TV },
[GSM0808_IE_LAYER_3_INFORMATION] = { TLV_TYPE_TLV },
+ [GSM0808_IE_SPEECH_VERSION] = { TLV_TYPE_TV },
+ [GSM0808_IE_CHOSEN_ENCR_ALG] = { TLV_TYPE_TV },
},
};
diff --git a/src/shared/libosmocore/src/logging.c b/src/shared/libosmocore/src/logging.c
index 30316a5f..b3b5cb69 100644
--- a/src/shared/libosmocore/src/logging.c
+++ b/src/shared/libosmocore/src/logging.c
@@ -294,14 +294,11 @@ void log_set_category_filter(struct log_target *target, int category,
target->categories[category].loglevel = level;
}
-/* since C89/C99 says stderr is a macro, we can safely do this! */
-#ifdef stderr
-static void _stderr_output(struct log_target *target, const char *log)
+static void _file_output(struct log_target *target, const char *log)
{
- fprintf(target->tgt_stdout.out, "%s", log);
- fflush(target->tgt_stdout.out);
+ fprintf(target->tgt_file.out, "%s", log);
+ fflush(target->tgt_file.out);
}
-#endif
struct log_target *log_target_create(void)
{
@@ -340,14 +337,68 @@ struct log_target *log_target_create_stderr(void)
if (!target)
return NULL;
- target->tgt_stdout.out = stderr;
- target->output = _stderr_output;
+ target->tgt_file.out = stderr;
+ target->output = _file_output;
return target;
#else
return NULL;
#endif /* stderr */
}
+struct log_target *log_target_create_file(const char *fname)
+{
+ struct log_target *target;
+
+ target = log_target_create();
+ if (!target)
+ return NULL;
+
+ target->tgt_file.out = fopen(fname, "a");
+ if (!target->tgt_file.out)
+ return NULL;
+
+ target->output = _file_output;
+
+ target->tgt_file.fname = talloc_strdup(target, fname);
+
+ return target;
+}
+
+void log_target_destroy(struct log_target *target)
+{
+
+ /* just in case, to make sure we don't have any references */
+ log_del_target(target);
+
+ if (target->output == &_file_output) {
+/* since C89/C99 says stderr is a macro, we can safely do this! */
+#ifdef stderr
+ /* don't close stderr */
+ if (target->tgt_file.out != stderr)
+#endif
+ {
+ fclose(target->tgt_file.out);
+ target->tgt_file.out = NULL;
+ }
+ }
+
+ talloc_free(target);
+}
+
+/* close and re-open a log file (for log file rotation) */
+int log_target_file_reopen(struct log_target *target)
+{
+ fclose(target->tgt_file.out);
+
+ target->tgt_file.out = fopen(target->tgt_file.fname, "a");
+ if (!target->tgt_file.out)
+ return -errno;
+
+ /* we assume target->output already to be set */
+
+ return 0;
+}
+
const char *log_vty_level_string(struct log_info *info)
{
const struct value_string *vs;
diff --git a/src/shared/libosmocore/src/plugin.c b/src/shared/libosmocore/src/plugin.c
index e953508a..3ba2d431 100644
--- a/src/shared/libosmocore/src/plugin.c
+++ b/src/shared/libosmocore/src/plugin.c
@@ -29,6 +29,7 @@
#include <dlfcn.h>
#include <stdio.h>
#include <errno.h>
+#include <limits.h>
#include <osmocore/plugin.h>
diff --git a/src/shared/libosmocore/src/process.c b/src/shared/libosmocore/src/process.c
new file mode 100644
index 00000000..180efa51
--- /dev/null
+++ b/src/shared/libosmocore/src/process.c
@@ -0,0 +1,74 @@
+/* Process handling support code */
+
+/* (C) 2010 by Harald Welte <laforge@gnumonks.org>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+int osmo_daemonize(void)
+{
+ int rc;
+ pid_t pid, sid;
+
+ /* Check if parent PID == init, in which case we are already a daemon */
+ if (getppid() == 1)
+ return -EEXIST;
+
+ /* Fork from the parent process */
+ pid = fork();
+ if (pid < 0) {
+ /* some error happened */
+ return pid;
+ }
+
+ if (pid > 0) {
+ /* if we have received a positive PID, then we are the parent
+ * and can exit */
+ exit(0);
+ }
+
+ /* FIXME: do we really want this? */
+ umask(0);
+
+ /* Create a new session and set process group ID */
+ sid = setsid();
+ if (sid < 0)
+ return sid;
+
+ /* Change to the /tmp directory, which prevents the CWD from being locked
+ * and unable to remove it */
+ rc = chdir("/tmp");
+ if (rc < 0)
+ return rc;
+
+ /* Redirect stdio to /dev/null */
+/* since C89/C99 says stderr is a macro, we can safely do this! */
+#ifdef stderr
+ freopen("/dev/null", "r", stdin);
+ freopen("/dev/null", "w", stdout);
+ freopen("/dev/null", "w", stderr);
+#endif
+
+ return 0;
+}
diff --git a/src/shared/libosmocore/src/select.c b/src/shared/libosmocore/src/select.c
index 2f6afa7f..f52b0a0c 100644
--- a/src/shared/libosmocore/src/select.c
+++ b/src/shared/libosmocore/src/select.c
@@ -19,6 +19,8 @@
*/
#include <fcntl.h>
+#include <stdio.h>
+
#include <osmocore/select.h>
#include <osmocore/linuxlist.h>
#include <osmocore/timer.h>
@@ -48,6 +50,16 @@ int bsc_register_fd(struct bsc_fd *fd)
if (fd->fd > maxfd)
maxfd = fd->fd;
+#ifdef BSC_FD_CHECK
+ struct bsc_fd *entry;
+ llist_for_each_entry(entry, &bsc_fds, list) {
+ if (entry == fd) {
+ fprintf(stderr, "Adding a bsc_fd that is already in the list.\n");
+ return 0;
+ }
+ }
+#endif
+
llist_add_tail(&fd->list, &bsc_fds);
return 0;
diff --git a/src/shared/libosmocore/src/vty/Makefile.am b/src/shared/libosmocore/src/vty/Makefile.am
index f2859cff..7353ab84 100644
--- a/src/shared/libosmocore/src/vty/Makefile.am
+++ b/src/shared/libosmocore/src/vty/Makefile.am
@@ -10,4 +10,5 @@ lib_LTLIBRARIES = libosmovty.la
libosmovty_la_SOURCES = buffer.c command.c vty.c vector.c utils.c \
telnet_interface.c logging_vty.c
+libosmovty_la_LIBADD = $(top_builddir)/src/libosmocore.la
endif
diff --git a/src/shared/libosmocore/src/vty/command.c b/src/shared/libosmocore/src/vty/command.c
index 598e63cc..7525df65 100644
--- a/src/shared/libosmocore/src/vty/command.c
+++ b/src/shared/libosmocore/src/vty/command.c
@@ -139,6 +139,18 @@ static int cmp_desc(const void *p, const void *q)
return strcmp(a->cmd, b->cmd);
}
+static int is_config(struct vty *vty)
+{
+ if (vty->node <= CONFIG_NODE)
+ return 0;
+ else if (vty->node > CONFIG_NODE && vty->node < _LAST_OSMOVTY_NODE)
+ return 1;
+ else if (host.app_info->is_config_node)
+ return host.app_info->is_config_node(vty, vty->node);
+ else
+ return vty->node > CONFIG_NODE;
+}
+
/* Sort each node's command element according to command string. */
void sort_node()
{
@@ -1947,9 +1959,9 @@ cmd_execute_command(vector vline, struct vty *vty, struct cmd_element **cmd,
if (vtysh)
return saved_ret;
- /* This assumes all nodes above CONFIG_NODE are childs of CONFIG_NODE */
+ /* Go to parent for config nodes to attempt to find the right command */
while (ret != CMD_SUCCESS && ret != CMD_WARNING
- && vty->node > CONFIG_NODE) {
+ && is_config(vty)) {
vty_go_parent(vty);
ret = cmd_execute_command_real(vline, vty, cmd);
tried = 1;
@@ -2097,7 +2109,7 @@ int config_from_file(struct vty *vty, FILE * fp)
/* Try again with setting node to CONFIG_NODE */
while (ret != CMD_SUCCESS && ret != CMD_WARNING
&& ret != CMD_ERR_NOTHING_TODO
- && vty->node != CONFIG_NODE) {
+ && vty->node != CONFIG_NODE && is_config(vty)) {
vty_go_parent(vty);
ret = cmd_execute_command_strict(vline, vty, NULL);
}
diff --git a/src/shared/libosmocore/src/vty/telnet_interface.c b/src/shared/libosmocore/src/vty/telnet_interface.c
index 90690960..1523a899 100644
--- a/src/shared/libosmocore/src/vty/telnet_interface.c
+++ b/src/shared/libosmocore/src/vty/telnet_interface.c
@@ -31,6 +31,7 @@
#include <osmocom/vty/telnet_interface.h>
#include <osmocom/vty/buffer.h>
+#include <osmocom/vty/command.h>
/* per connection data */
LLIST_HEAD(active_connections);
@@ -89,16 +90,18 @@ int telnet_init(void *tall_ctx, void *priv, int port)
return 0;
}
-extern const char *openbsc_copyright;
+extern struct host host;
static void print_welcome(int fd)
{
int ret;
static char *msg =
- "Welcome to the OpenBSC Control interface\n";
+ "Welcome to the OpenBSC Control interface\r\n";
ret = write(fd, msg, strlen(msg));
- ret = write(fd, openbsc_copyright, strlen(openbsc_copyright));
+
+ if (host.app_info->copyright)
+ ret = write(fd, host.app_info->copyright, strlen(host.app_info->copyright));
}
int telnet_close_client(struct bsc_fd *fd)
diff --git a/src/shared/libosmocore/src/vty/vty.c b/src/shared/libosmocore/src/vty/vty.c
index ff17abf6..5c5a908d 100644
--- a/src/shared/libosmocore/src/vty/vty.c
+++ b/src/shared/libosmocore/src/vty/vty.c
@@ -248,6 +248,15 @@ int vty_out_newline(struct vty *vty)
return 0;
}
+void *vty_current_index(struct vty *vty)
+{
+ return vty->index;
+}
+int vty_current_node(struct vty *vty)
+{
+ return vty->node;
+}
+
int vty_config_lock(struct vty *vty)
{
if (vty_config == 0) {