diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c
index 95229c2..c7e6a6c 100644
--- a/src/shared/mgmt.c
+++ b/src/shared/mgmt.c
#include "src/shared/mgmt.h"
#include "src/shared/timeout.h"
+#define DBG(_mgmt, _format, arg...) \
+ mgmt_log(_mgmt, "%s:%s() " _format, __FILE__, __func__, ## arg)
+
struct mgmt {
int ref_count;
int fd;
return false;
}
+static void mgmt_log(struct mgmt *mgmt, const char *format, ...)
+{
+ va_list ap;
+
+ if (!mgmt || !format || !mgmt->debug_callback)
+ return;
+
+ va_start(ap, format);
+ util_debug_va(mgmt->debug_callback, mgmt->debug_data, format, ap);
+ va_end(ap);
+}
+
static bool send_request(struct mgmt *mgmt, struct mgmt_request *request)
{
struct iovec iov;
ret = io_send(mgmt->io, &iov, 1);
if (ret < 0) {
- util_debug(mgmt->debug_callback, mgmt->debug_data,
- "write failed: %s", strerror(-ret));
+ DBG(mgmt, "write failed: %s", strerror(-ret));
+
if (request->callback)
request->callback(MGMT_STATUS_FAILED, 0, NULL,
request->user_data);
request,
NULL);
- util_debug(mgmt->debug_callback, mgmt->debug_data,
- "[0x%04x] command 0x%04x",
- request->index, request->opcode);
+ DBG(mgmt, "[0x%04x] command 0x%04x", request->index, request->opcode);
util_hexdump('<', request->buf, ret, mgmt->debug_callback,
mgmt->debug_data);
request = queue_remove_if(mgmt->pending_list,
match_request_opcode_index, &match);
if (!request) {
- util_debug(mgmt->debug_callback, mgmt->debug_data,
- "Unable to find request for opcode 0x%04x",
- opcode);
+ DBG(mgmt, "Unable to find request for opcode 0x%04x", opcode);
/* Attempt to remove with no opcode */
request = queue_remove_if(mgmt->pending_list,
cc = mgmt->buf + MGMT_HDR_SIZE;
opcode = btohs(cc->opcode);
- util_debug(mgmt->debug_callback, mgmt->debug_data,
- "[0x%04x] command 0x%04x complete: 0x%02x",
+ DBG(mgmt, "[0x%04x] command 0x%04x complete: 0x%02x",
index, opcode, cc->status);
request_complete(mgmt, cc->status, opcode, index, length - 3,
cs = mgmt->buf + MGMT_HDR_SIZE;
opcode = btohs(cs->opcode);
- util_debug(mgmt->debug_callback, mgmt->debug_data,
- "[0x%04x] command 0x%02x status: 0x%02x",
+ DBG(mgmt, "[0x%04x] command 0x%02x status: 0x%02x",
index, opcode, cs->status);
request_complete(mgmt, cs->status, opcode, index, 0, NULL);
break;
default:
- util_debug(mgmt->debug_callback, mgmt->debug_data,
- "[0x%04x] event 0x%04x", index, event);
+ DBG(mgmt, "[0x%04x] event 0x%04x", index, event);
process_notify(mgmt, event, index, length,
mgmt->buf + MGMT_HDR_SIZE);