aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2014-08-20 19:58:13 +0200
committerHarald Welte <laforge@gnumonks.org>2014-08-21 15:34:18 +0200
commit7fd0c830d968e67be555bd1aeabced4cc5e08061 (patch)
treef313a2b194ebd857192efd2585167d52ec6a9762
parentf3c7e85d05f7b2b7bf093162b776f71b2bc6420d (diff)
libctrl: Add DLCTRL as logging context for the control interface
... and make libctrl code use it
-rw-r--r--include/osmocom/core/logging.h3
-rw-r--r--src/ctrl/control_cmd.c30
-rw-r--r--src/ctrl/control_if.c26
-rw-r--r--src/logging.c5
4 files changed, 35 insertions, 29 deletions
diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h
index caeea065..3c5e7b15 100644
--- a/include/osmocom/core/logging.h
+++ b/include/osmocom/core/logging.h
@@ -67,7 +67,8 @@ void logp(int subsys, const char *file, int line, int cont, const char *format,
#define DLMI -5
#define DLMIB -6
#define DLSMS -7
-#define OSMO_NUM_DLIB 7
+#define DLCTRL -8
+#define OSMO_NUM_DLIB 8
struct log_category {
uint8_t loglevel;
diff --git a/src/ctrl/control_cmd.c b/src/ctrl/control_cmd.c
index 45e517db..8c920336 100644
--- a/src/ctrl/control_cmd.c
+++ b/src/ctrl/control_cmd.c
@@ -188,7 +188,7 @@ static void create_cmd_struct(struct ctrl_cmd_struct *cmd, const char *name)
for (cur = name, word = NULL; cur[0] != '\0'; ++cur) {
/* warn about optionals */
if (cur[0] == '(' || cur[0] == ')' || cur[0] == '|') {
- LOGP(DCTRL, LOGL_ERROR,
+ LOGP(DLCTRL, LOGL_ERROR,
"Optionals are not supported in '%s'\n", name);
goto failure;
}
@@ -223,7 +223,7 @@ int ctrl_cmd_install(enum ctrl_node_type node, struct ctrl_cmd_element *cmd)
if (!cmds_vec) {
cmds_vec = vector_init(5);
if (!cmds_vec) {
- LOGP(DCTRL, LOGL_ERROR, "vector_init failed.\n");
+ LOGP(DLCTRL, LOGL_ERROR, "vector_init failed.\n");
return -ENOMEM;
}
vector_set_index(ctrl_node_vec, node, cmds_vec);
@@ -291,7 +291,7 @@ struct ctrl_cmd *ctrl_cmd_parse(void *ctx, struct msgb *msg)
cmd = talloc_zero(ctx, struct ctrl_cmd);
if (!cmd) {
- LOGP(DCTRL, LOGL_ERROR, "Failed to allocate.\n");
+ LOGP(DLCTRL, LOGL_ERROR, "Failed to allocate.\n");
return NULL;
}
@@ -333,11 +333,11 @@ struct ctrl_cmd *ctrl_cmd_parse(void *ctx, struct msgb *msg)
if (!var) {
cmd->type = CTRL_TYPE_ERROR;
cmd->reply = "GET incomplete";
- LOGP(DCTRL, LOGL_NOTICE, "GET Command incomplete\n");
+ LOGP(DLCTRL, LOGL_NOTICE, "GET Command incomplete\n");
goto err;
}
cmd->variable = talloc_strdup(cmd, var);
- LOGP(DCTRL, LOGL_DEBUG, "Command: GET %s\n", cmd->variable);
+ LOGP(DLCTRL, LOGL_DEBUG, "Command: GET %s\n", cmd->variable);
break;
case CTRL_TYPE_SET:
var = strtok_r(NULL, " ", &saveptr);
@@ -345,14 +345,14 @@ struct ctrl_cmd *ctrl_cmd_parse(void *ctx, struct msgb *msg)
if (!var || !val) {
cmd->type = CTRL_TYPE_ERROR;
cmd->reply = "SET incomplete";
- LOGP(DCTRL, LOGL_NOTICE, "SET Command incomplete\n");
+ LOGP(DLCTRL, LOGL_NOTICE, "SET Command incomplete\n");
goto err;
}
cmd->variable = talloc_strdup(cmd, var);
cmd->value = talloc_strdup(cmd, val);
if (!cmd->variable || !cmd->value)
goto oom;
- LOGP(DCTRL, LOGL_DEBUG, "Command: SET %s = %s\n", cmd->variable, cmd->value);
+ LOGP(DLCTRL, LOGL_DEBUG, "Command: SET %s = %s\n", cmd->variable, cmd->value);
break;
case CTRL_TYPE_GET_REPLY:
case CTRL_TYPE_SET_REPLY:
@@ -362,14 +362,14 @@ struct ctrl_cmd *ctrl_cmd_parse(void *ctx, struct msgb *msg)
if (!var || !val) {
cmd->type = CTRL_TYPE_ERROR;
cmd->reply = "Trap/Reply incomplete";
- LOGP(DCTRL, LOGL_NOTICE, "Trap/Reply incomplete\n");
+ LOGP(DLCTRL, LOGL_NOTICE, "Trap/Reply incomplete\n");
goto err;
}
cmd->variable = talloc_strdup(cmd, var);
cmd->reply = talloc_strdup(cmd, val);
if (!cmd->variable || !cmd->reply)
goto oom;
- LOGP(DCTRL, LOGL_DEBUG, "Command: TRAP/REPLY %s: %s\n", cmd->variable, cmd->reply);
+ LOGP(DLCTRL, LOGL_DEBUG, "Command: TRAP/REPLY %s: %s\n", cmd->variable, cmd->reply);
break;
case CTRL_TYPE_ERROR:
var = strtok_r(NULL, "\0", &saveptr);
@@ -380,7 +380,7 @@ struct ctrl_cmd *ctrl_cmd_parse(void *ctx, struct msgb *msg)
cmd->reply = talloc_strdup(cmd, var);
if (!cmd->reply)
goto oom;
- LOGP(DCTRL, LOGL_DEBUG, "Command: ERROR %s\n", cmd->reply);
+ LOGP(DLCTRL, LOGL_DEBUG, "Command: ERROR %s\n", cmd->reply);
break;
case CTRL_TYPE_UNKNOWN:
default:
@@ -420,7 +420,7 @@ struct msgb *ctrl_cmd_make(struct ctrl_cmd *cmd)
tmp = talloc_asprintf(cmd, "%s %s %s", type, cmd->id, cmd->variable);
if (!tmp) {
- LOGP(DCTRL, LOGL_ERROR, "Failed to allocate cmd.\n");
+ LOGP(DLCTRL, LOGL_ERROR, "Failed to allocate cmd.\n");
goto err;
}
@@ -435,7 +435,7 @@ struct msgb *ctrl_cmd_make(struct ctrl_cmd *cmd)
tmp = talloc_asprintf(cmd, "%s %s %s %s", type, cmd->id, cmd->variable,
cmd->value);
if (!tmp) {
- LOGP(DCTRL, LOGL_ERROR, "Failed to allocate cmd.\n");
+ LOGP(DLCTRL, LOGL_ERROR, "Failed to allocate cmd.\n");
goto err;
}
@@ -452,7 +452,7 @@ struct msgb *ctrl_cmd_make(struct ctrl_cmd *cmd)
tmp = talloc_asprintf(cmd, "%s %s %s %s", type, cmd->id, cmd->variable,
cmd->reply);
if (!tmp) {
- LOGP(DCTRL, LOGL_ERROR, "Failed to allocate cmd.\n");
+ LOGP(DLCTRL, LOGL_ERROR, "Failed to allocate cmd.\n");
goto err;
}
@@ -467,7 +467,7 @@ struct msgb *ctrl_cmd_make(struct ctrl_cmd *cmd)
tmp = talloc_asprintf(cmd, "%s %s %s", type, cmd->id,
cmd->reply);
if (!tmp) {
- LOGP(DCTRL, LOGL_ERROR, "Failed to allocate cmd.\n");
+ LOGP(DLCTRL, LOGL_ERROR, "Failed to allocate cmd.\n");
goto err;
}
@@ -476,7 +476,7 @@ struct msgb *ctrl_cmd_make(struct ctrl_cmd *cmd)
talloc_free(tmp);
break;
default:
- LOGP(DCTRL, LOGL_NOTICE, "Unknown command type %i\n", cmd->type);
+ LOGP(DLCTRL, LOGL_NOTICE, "Unknown command type %i\n", cmd->type);
goto err;
break;
}
diff --git a/src/ctrl/control_if.c b/src/ctrl/control_if.c
index a2080714..007e0fea 100644
--- a/src/ctrl/control_if.c
+++ b/src/ctrl/control_if.c
@@ -77,7 +77,7 @@ int ctrl_cmd_send(struct osmo_wqueue *queue, struct ctrl_cmd *cmd)
msg = ctrl_cmd_make(cmd);
if (!msg) {
- LOGP(DCTRL, LOGL_ERROR, "Could not generate msg\n");
+ LOGP(DLCTRL, LOGL_ERROR, "Could not generate msg\n");
return -1;
}
@@ -86,7 +86,7 @@ int ctrl_cmd_send(struct osmo_wqueue *queue, struct ctrl_cmd *cmd)
ret = osmo_wqueue_enqueue(queue, msg);
if (ret != 0) {
- LOGP(DCTRL, LOGL_ERROR, "Failed to enqueue the command.\n");
+ LOGP(DLCTRL, LOGL_ERROR, "Failed to enqueue the command.\n");
msgb_free(msg);
}
return ret;
@@ -136,27 +136,27 @@ static int handle_control_read(struct osmo_fd * bfd)
if (ret == -EAGAIN)
return 0;
if (ret == 0)
- LOGP(DCTRL, LOGL_INFO, "The control connection was closed\n");
+ LOGP(DLCTRL, LOGL_INFO, "The control connection was closed\n");
else
- LOGP(DCTRL, LOGL_ERROR, "Failed to parse ip access message: %d\n", ret);
+ LOGP(DLCTRL, LOGL_ERROR, "Failed to parse ip access message: %d\n", ret);
goto err;
}
if (msg->len < sizeof(*iph) + sizeof(*iph_ext)) {
- LOGP(DCTRL, LOGL_ERROR, "The message is too short.\n");
+ LOGP(DLCTRL, LOGL_ERROR, "The message is too short.\n");
goto err;
}
iph = (struct ipaccess_head *) msg->data;
if (iph->proto != IPAC_PROTO_OSMO) {
- LOGP(DCTRL, LOGL_ERROR, "Protocol mismatch. We got 0x%x\n", iph->proto);
+ LOGP(DLCTRL, LOGL_ERROR, "Protocol mismatch. We got 0x%x\n", iph->proto);
goto err;
}
iph_ext = (struct ipaccess_head_ext *) iph->data;
if (iph_ext->proto != IPAC_PROTO_EXT_CTRL) {
- LOGP(DCTRL, LOGL_ERROR, "Extended protocol mismatch. We got 0x%x\n", iph_ext->proto);
+ LOGP(DLCTRL, LOGL_ERROR, "Extended protocol mismatch. We got 0x%x\n", iph_ext->proto);
goto err;
}
@@ -174,7 +174,7 @@ static int handle_control_read(struct osmo_fd * bfd)
cmd = talloc_zero(ccon, struct ctrl_cmd);
if (!cmd)
goto err;
- LOGP(DCTRL, LOGL_ERROR, "Command parser error.\n");
+ LOGP(DLCTRL, LOGL_ERROR, "Command parser error.\n");
cmd->type = CTRL_TYPE_ERROR;
cmd->id = "err";
cmd->reply = "Command parser error.";
@@ -197,7 +197,7 @@ static int control_write_cb(struct osmo_fd *bfd, struct msgb *msg)
rc = write(bfd->fd, msg->data, msg->len);
if (rc != msg->len)
- LOGP(DCTRL, LOGL_ERROR, "Failed to write message to the control connection.\n");
+ LOGP(DLCTRL, LOGL_ERROR, "Failed to write message to the control connection.\n");
return rc;
}
@@ -232,19 +232,19 @@ static int listen_fd_cb(struct osmo_fd *listen_bfd, unsigned int what)
perror("accept");
return fd;
}
- LOGP(DCTRL, LOGL_INFO, "accept()ed new control connection from %s\n",
+ LOGP(DLCTRL, LOGL_INFO, "accept()ed new control connection from %s\n",
inet_ntoa(sa.sin_addr));
on = 1;
ret = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on));
if (ret != 0) {
- LOGP(DCTRL, LOGL_ERROR, "Failed to set TCP_NODELAY: %s\n", strerror(errno));
+ LOGP(DLCTRL, LOGL_ERROR, "Failed to set TCP_NODELAY: %s\n", strerror(errno));
close(fd);
return ret;
}
ccon = ctrl_connection_alloc(listen_bfd->data);
if (!ccon) {
- LOGP(DCTRL, LOGL_ERROR, "Failed to allocate.\n");
+ LOGP(DLCTRL, LOGL_ERROR, "Failed to allocate.\n");
close(fd);
return -1;
}
@@ -258,7 +258,7 @@ static int listen_fd_cb(struct osmo_fd *listen_bfd, unsigned int what)
ret = osmo_fd_register(&ccon->write_queue.bfd);
if (ret < 0) {
- LOGP(DCTRL, LOGL_ERROR, "Could not register FD.\n");
+ LOGP(DLCTRL, LOGL_ERROR, "Could not register FD.\n");
close(ccon->write_queue.bfd.fd);
talloc_free(ccon);
}
diff --git a/src/logging.c b/src/logging.c
index 2e3a80ad..f9d789d7 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -106,6 +106,11 @@ static const struct log_info_cat internal_cat[OSMO_NUM_DLIB] = {
.enabled = 1, .loglevel = LOGL_NOTICE,
.color = "\033[1;38m",
},
+ [INT2IDX(DLCTRL)] = {
+ .name = "DLCTRL",
+ .description = "Control Interface",
+ .enabled = 1, .loglevel = LOGL_NOTICE,
+ },
};
/*! \brief descriptive string for each log level */