From patchwork Wed Aug 20 18:15:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Welte X-Patchwork-Id: 381772 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ganesha.gnumonks.org (ganesha.gnumonks.org [IPv6:2001:780:45:1d:225:90ff:fe52:c662]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A51761400D2 for ; Thu, 21 Aug 2014 04:39:27 +1000 (EST) Received: from localhost ([127.0.0.1] helo=ganesha.gnumonks.org) by ganesha.gnumonks.org with esmtp (Exim 4.72) (envelope-from ) id 1XKAmy-0005G7-Ey; Wed, 20 Aug 2014 20:39:16 +0200 Received: from uucp by ganesha.gnumonks.org with local-bsmtp (Exim 4.72) (envelope-from ) id 1XKART-0003S7-MX; Wed, 20 Aug 2014 20:17:04 +0200 Received: from laforge by localhost.localdomain with local (Exim 4.84_RC1) (envelope-from ) id 1XKAPm-0002iC-3d; Wed, 20 Aug 2014 20:15:18 +0200 From: Harald Welte To: openbsc@lists.osmocom.org Subject: [PATCH 4/5] libctrl: Add DLCTRL as logging context for the control interface Date: Wed, 20 Aug 2014 20:15:09 +0200 Message-Id: <1408558510-10364-4-git-send-email-laforge@gnumonks.org> X-Mailer: git-send-email 2.1.0.rc1 In-Reply-To: <1408558510-10364-1-git-send-email-laforge@gnumonks.org> References: <1408558510-10364-1-git-send-email-laforge@gnumonks.org> Cc: daniel@totalueberwachung.de, Harald Welte X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Development of the OpenBSC GSM base station controller List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: openbsc-bounces@lists.osmocom.org Errors-To: openbsc-bounces@lists.osmocom.org ... and make libctrl code use it --- include/osmocom/core/logging.h | 3 ++- src/ctrl/control_cmd.c | 30 +++++++++++++++--------------- src/ctrl/control_if.c | 26 +++++++++++++------------- src/logging.c | 5 +++++ 4 files changed, 35 insertions(+), 29 deletions(-) diff --git a/include/osmocom/core/logging.h b/include/osmocom/core/logging.h index caeea06..3c5e7b1 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 45e517d..8c92033 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 a208071..007e0fe 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 2e3a80a..f9d789d 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 */