Skip to content

Commit

Permalink
mqueue, ubx-mq: fix issue caused by strictler cleanup
Browse files Browse the repository at this point in the history
Using a strictler block cleanup policy caused the mqueues created by
ubx-mq tool to be properly destructed, but in their cleanup they
called mq_unlink which removed the queue. This adds a mqueue config
`unlink` to defined whether the queue shall be removed or not (default
yes).

In addition, the ubx.node_cleanup is set as the default gc method for
node instead of ubx.node_rm. This leaves the logging intact, which is
desirable for the same reasons as above. ubx.node_rm can still be
called explicitly (i.e. as done by blockdiagram:pulldown) when the
main node is being destructed.

Signed-off-by: Markus Klotzbuecher <mk@mkio.de>
  • Loading branch information
kmarkus committed Jul 8, 2020
1 parent 78ea94b commit 8fc97f6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lua/ubx.lua
Expand Up @@ -309,7 +309,7 @@ end
-- @param attrs node attributes
-- @return ubx_node_t
function M.node_create(name, params)
local nd = ffi.gc(ffi.new("ubx_node_t"), ubx.ubx_node_rm)
local nd = ffi.gc(ffi.new("ubx_node_t"), ubx.ubx_node_cleanup)
params = params or {}
local attrs=0
if params.mlockall then attrs = bit.bor(attrs, ffi.C.ND_MLOCK_ALL) end
Expand Down
16 changes: 13 additions & 3 deletions std_blocks/mqueue/mqueue.c
Expand Up @@ -22,6 +22,7 @@ ubx_proto_config_t mqueue_config[] = {
{ .name = "data_len", .type_name = "long", .max = 1, .doc = "array length (multiplier) of data (default: 1)" },
{ .name = "buffer_len", .type_name = "long", .min = 1, .max = 1, .doc = "max number of data elements the buffer shall hold" },
{ .name = "blocking", .type_name = "uint32_t", .min = 0, .max = 1, .doc = "enable blocking mode (def: 0)" },
{ .name = "unlink", .type_name = "uint32_t", .min = 0, .max = 1, .doc = "call mq_unlink in cleanup (def: 1 (yes)" },
{ 0 }
};

Expand All @@ -35,6 +36,7 @@ struct mqueue_info {
const ubx_type_t *type; /* type of contained elements */
long data_len; /* buffer size of each element */
long buffer_len; /* number of elements */
uint32_t unlink;

unsigned long cnt_send_err;
unsigned long cnt_recv_err;
Expand Down Expand Up @@ -112,6 +114,11 @@ int mqueue_init(ubx_block_t *i)
goto out_free_info;
}

/* unlink */
len = cfg_getptr_uint32(i, "unlink", &val);
assert(len >= 0);
inf->unlink = (len>0) ? *val : 1;

/* configure max message size */
mqa.mq_msgsize = inf->data_len * inf->type->size;

Expand Down Expand Up @@ -169,10 +176,13 @@ void mqueue_cleanup(ubx_block_t *i)
if (mq_close(inf->mqd) != 0)
ubx_err(i, "mq_close %s failed: %s", inf->mq_name, strerror(errno));

ret = mq_unlink(inf->mq_name);
if (inf->unlink) {
ubx_info(i, "%s: removing mq %s", __func__, inf->mq_name);
ret = mq_unlink(inf->mq_name);

if (ret < 0 && errno != ENOENT)
ubx_err(i, "mq_unlink %s failed: %s", inf->mq_name, strerror(errno));
if (ret < 0 && errno != ENOENT)
ubx_err(i, "mq_unlink %s failed: %s", inf->mq_name, strerror(errno));
}

free(inf);
}
Expand Down
1 change: 1 addition & 0 deletions tools/ubx-mq
Expand Up @@ -85,6 +85,7 @@ local function read(mqtab, preloads)
type_name = ubx.safe_tostr(typ.name),
data_len = mqtab.data_len,
buffer_len = 32,
unlink=0,
blocking = 1 } )

local mq = nd:b("mq")
Expand Down

0 comments on commit 8fc97f6

Please sign in to comment.