Commit 07f7d358 authored by Philippe Gerum's avatar Philippe Gerum
Browse files

libevl: allow for receiving NULL element names


Signed-off-by: default avatarPhilippe Gerum <rpm@xenomai.org>
parent a281771a
......@@ -34,21 +34,24 @@ static int init_event_vargs(struct evl_event *evt,
{
struct evl_monitor_attrs attrs;
struct evl_element_ids eids;
char *name = NULL;
int efd, ret;
char *name;
if (evl_shared_memory == NULL)
return -ENXIO;
if (fmt) {
ret = vasprintf(&name, fmt, ap);
if (ret < 0)
return -ENOMEM;
}
attrs.type = EVL_MONITOR_EVENT;
attrs.protocol = EVL_EVENT_GATED;
attrs.clockfd = clockfd;
attrs.initval = 0;
efd = create_evl_element(EVL_MONITOR_DEV, name, &attrs, flags, &eids);
if (name)
free(name);
if (efd < 0)
return efd;
......
......@@ -32,24 +32,27 @@ int evl_create_flags(struct evl_flags *flg, int clockfd,
{
struct evl_monitor_attrs attrs;
struct evl_element_ids eids;
char *name = NULL;
int efd, ret;
va_list ap;
char *name;
if (evl_shared_memory == NULL)
return -ENXIO;
if (fmt) {
va_start(ap, fmt);
ret = vasprintf(&name, fmt, ap);
va_end(ap);
if (ret < 0)
return -ENOMEM;
}
attrs.type = EVL_MONITOR_EVENT;
attrs.protocol = EVL_EVENT_MASK;
attrs.clockfd = clockfd;
attrs.initval = initval;
efd = create_evl_element(EVL_MONITOR_DEV, name, &attrs, flags, &eids);
if (name)
free(name);
if (efd < 0)
return efd;
......
......@@ -87,7 +87,7 @@ int create_evl_element(const char *type, const char *name,
* Turn on public mode if the user-provided name starts with a
* slash. Anonymous elements must be private by definition.
*/
if (!name) {
if (name == NULL) {
if (clone_flags & EVL_CLONE_PUBLIC)
return -EINVAL;
} else if (*name == '/') {
......
......@@ -35,8 +35,8 @@ static int init_mutex_vargs(struct evl_mutex *mutex,
struct evl_monitor_attrs attrs;
struct evl_monitor_state *gst;
struct evl_element_ids eids;
char *name = NULL;
int efd, ret;
char *name;
if (evl_shared_memory == NULL)
return -ENXIO;
......@@ -54,15 +54,18 @@ static int init_mutex_vargs(struct evl_mutex *mutex,
return -EINVAL;
}
if (fmt) {
ret = vasprintf(&name, fmt, ap);
if (ret < 0)
return -ENOMEM;
}
attrs.type = EVL_MONITOR_GATE;
attrs.protocol = protocol;
attrs.clockfd = clockfd;
attrs.initval = ceiling;
efd = create_evl_element(EVL_MONITOR_DEV, name, &attrs, flags, &eids);
if (name)
free(name);
if (efd < 0)
return efd;
......
......@@ -16,17 +16,20 @@
int evl_create_observable(int flags, const char *fmt, ...)
{
char *name = NULL;
int ret, efd;
va_list ap;
char *name;
if (fmt) {
va_start(ap, fmt);
ret = vasprintf(&name, fmt, ap);
va_end(ap);
if (ret < 0)
return -ENOMEM;
}
efd = create_evl_element(EVL_OBSERVABLE_DEV, name, NULL, flags, NULL);
if (name)
free(name);
return efd;
......
......@@ -36,20 +36,23 @@ int evl_create_proxy(int targetfd, size_t bufsz, size_t granularity,
int flags, const char *fmt, ...)
{
struct evl_proxy_attrs attrs;
char *name = NULL;
int ret, efd;
va_list ap;
char *name;
if (fmt) {
va_start(ap, fmt);
ret = vasprintf(&name, fmt, ap);
va_end(ap);
if (ret < 0)
return -ENOMEM;
}
attrs.fd = targetfd;
attrs.bufsz = bufsz;
attrs.granularity = granularity;
efd = create_evl_element(EVL_PROXY_DEV, name, &attrs, flags, NULL);
if (name)
free(name);
return efd;
......
......@@ -31,24 +31,27 @@ int evl_create_sem(struct evl_sem *sem, int clockfd,
{
struct evl_monitor_attrs attrs;
struct evl_element_ids eids;
char *name = NULL;
int efd, ret;
va_list ap;
char *name;
if (evl_shared_memory == NULL)
return -ENXIO;
if (fmt) {
va_start(ap, fmt);
ret = vasprintf(&name, fmt, ap);
va_end(ap);
if (ret < 0)
return -ENOMEM;
}
attrs.type = EVL_MONITOR_EVENT;
attrs.protocol = EVL_EVENT_COUNT;
attrs.clockfd = clockfd;
attrs.initval = initval;
efd = create_evl_element(EVL_MONITOR_DEV, name, &attrs, flags, &eids);
if (name)
free(name);
if (efd < 0)
return efd;
......
......@@ -57,8 +57,8 @@ int evl_attach_thread(int flags, const char *fmt, ...)
struct evl_sched_attrs attrs;
struct evl_element_ids eids;
struct sched_param param;
char *name = NULL;
va_list ap;
char *name;
/*
* Try to initialize if not yet done, so that attaching a
......@@ -76,13 +76,16 @@ int evl_attach_thread(int flags, const char *fmt, ...)
if (evl_current != EVL_NO_HANDLE)
return -EBUSY;
if (fmt) {
va_start(ap, fmt);
ret = vasprintf(&name, fmt, ap);
va_end(ap);
if (ret < 0)
return -ENOMEM;
}
efd = create_evl_element(EVL_THREAD_DEV, name, NULL, flags, &eids);
if (name)
free(name);
if (efd < 0)
return efd;
......
......@@ -14,19 +14,22 @@ int evl_create_xbuf(size_t i_bufsz, size_t o_bufsz,
int flags, const char *fmt, ...)
{
struct evl_xbuf_attrs attrs;
char *name = NULL;
int ret, efd;
va_list ap;
char *name;
if (fmt) {
va_start(ap, fmt);
ret = vasprintf(&name, fmt, ap);
va_end(ap);
if (ret < 0)
return -ENOMEM;
}
attrs.i_bufsz = i_bufsz;
attrs.o_bufsz = o_bufsz;
efd = create_evl_element(EVL_XBUF_DEV, name, &attrs, flags, NULL);
if (name)
free(name);
return efd;
......
......@@ -11,6 +11,7 @@
#include <evl/sem.h>
#include <evl/xbuf.h>
#include <evl/proxy.h>
#include <evl/observable.h>
#include "helpers.h"
static inline bool element_is_public(const char *path)
......@@ -33,6 +34,9 @@ int main(int argc, char *argv[])
__Texpr_assert(!element_is_public(path));
__Tcall_assert(efd, evl_detach_self());
__Tcall_assert(efd, evl_attach_self(NULL)); /* unnamed (private) */
__Tcall_assert(efd, evl_detach_self());
name = get_unique_name_and_path(EVL_MONITOR_DEV, 0, &path); /* public */
__Tcall_assert(efd, evl_new_sem(&sem, name));
__Texpr_assert(element_is_public(path));
......@@ -43,6 +47,9 @@ int main(int argc, char *argv[])
__Texpr_assert(!element_is_public(path));
__Tcall_assert(efd, evl_close_sem(&sem));
__Tcall_assert(efd, evl_new_sem(&sem, NULL)); /* unnamed (private) */
__Tcall_assert(efd, evl_close_sem(&sem));
name = get_unique_name_and_path(EVL_XBUF_DEV, 0, &path); /* public */
__Tcall_assert(efd, evl_new_xbuf(1024, name));
__Texpr_assert(element_is_public(path));
......@@ -53,6 +60,9 @@ int main(int argc, char *argv[])
__Texpr_assert(!element_is_public(path));
__Tcall_assert(ret, close(efd));
__Tcall_assert(efd, evl_new_xbuf(1024, NULL)); /* unnamed (private) */
__Tcall_assert(efd, close(efd));
name = get_unique_name_and_path(EVL_PROXY_DEV, 0, &path); /* public */
__Tcall_assert(efd, evl_new_proxy(1, 0, name));
__Texpr_assert(element_is_public(path));
......@@ -63,5 +73,21 @@ int main(int argc, char *argv[])
__Texpr_assert(!element_is_public(path));
__Tcall_assert(ret, close(efd));
__Tcall_assert(efd, evl_new_proxy(1, 0, NULL)); /* unnamed (private) */
__Tcall_assert(efd, close(efd));
name = get_unique_name_and_path(EVL_OBSERVABLE_DEV, 0, &path); /* public */
__Tcall_assert(efd, evl_new_observable(name));
__Texpr_assert(element_is_public(path));
__Tcall_assert(ret, close(efd));
name = get_unique_name_and_path(EVL_PROXY_DEV, 0, &path); /* private */
__Tcall_assert(efd, evl_new_observable(name + 1));
__Texpr_assert(!element_is_public(path));
__Tcall_assert(ret, close(efd));
__Tcall_assert(efd, evl_new_observable(NULL)); /* unnamed (private) */
__Tcall_assert(efd, close(efd));
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment