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