All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] Export posix mqueues and named semaphores to procfs
@ 2021-08-23 15:00 Florian Bezdeka
  2021-08-23 15:00 ` [PATCH 1/6] cobalt/registry: Share xnregistry_vfreg_ops with other compile units Florian Bezdeka
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Florian Bezdeka @ 2021-08-23 15:00 UTC (permalink / raw)
  To: xenomai

Hi all,

with this series I'm trying to care about all the feedback I got for
RFCs I sent out some days ago. Exporting mqueues and named semaphores to
the procfs helps to debug and identify resource leaks.

mqueues will be exported to 
	/proc/xenomai/registry/posix/mqueue/<name>

named semaphores will be exported to 
	/proc/xenomai/registry/posix/sem/<name>

While adding the tests I noticed that the exit code of the subprocess
started in the smokey leak test was not correctly reported to the parent
process. That is now fixed as well. (See last patch for details)

All patches compile time tested for all targets by the gitlab
hackerspace CI pipeline. In addition manually tested on ARM64. My
internal CI is currently out of order, so tests on real hardware were
skipped this time.

Best regards,
Florian

 
Florian Bezdeka (6):
  cobalt/registry: Share xnregistry_vfreg_ops with other compile units
  cobalt/registry: Initialize refcnt of exported virtual proc files
  cobalt/registry: Adding a new xnptree for exporting posix entries
  cobalt/posix/mqueue: Export created mqueues to procfs
  cobalt/posix/semaphore: Export named semaphores to procfs
  testsuite/smokey/leaks: Add export checks for mqueues and named
    semaphores

 include/cobalt/kernel/registry.h |  2 +
 kernel/cobalt/posix/mqueue.c     | 38 +++++++++++++++++-
 kernel/cobalt/posix/sem.c        | 37 ++++++++++++++++-
 kernel/cobalt/registry.c         |  3 ++
 testsuite/smokey/leaks/leaks.c   | 68 +++++++++++++++++++++-----------
 5 files changed, 123 insertions(+), 25 deletions(-)

-- 
2.30.2



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/6] cobalt/registry: Share xnregistry_vfreg_ops with other compile units
  2021-08-23 15:00 [PATCH 0/6] Export posix mqueues and named semaphores to procfs Florian Bezdeka
@ 2021-08-23 15:00 ` Florian Bezdeka
  2021-08-23 15:00 ` [PATCH 2/6] cobalt/registry: Initialize refcnt of exported virtual proc files Florian Bezdeka
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Florian Bezdeka @ 2021-08-23 15:00 UTC (permalink / raw)
  To: xenomai

Allows re-using xnregistry_vfreg_ops. All other file options were
already available.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 include/cobalt/kernel/registry.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/cobalt/kernel/registry.h b/include/cobalt/kernel/registry.h
index 624db5a78..a459da503 100644
--- a/include/cobalt/kernel/registry.h
+++ b/include/cobalt/kernel/registry.h
@@ -195,6 +195,8 @@ extern struct xnpnode_ops xnregistry_vfsnap_ops;
 
 extern struct xnpnode_ops xnregistry_vlink_ops;
 
+extern struct xnpnode_ops xnregistry_vfreg_ops;
+
 /** @} */
 
 #endif /* !_COBALT_KERNEL_REGISTRY_H */
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/6] cobalt/registry: Initialize refcnt of exported virtual proc files
  2021-08-23 15:00 [PATCH 0/6] Export posix mqueues and named semaphores to procfs Florian Bezdeka
  2021-08-23 15:00 ` [PATCH 1/6] cobalt/registry: Share xnregistry_vfreg_ops with other compile units Florian Bezdeka
@ 2021-08-23 15:00 ` Florian Bezdeka
  2021-08-23 15:00 ` [PATCH 3/6] cobalt/registry: Adding a new xnptree for exporting posix entries Florian Bezdeka
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Florian Bezdeka @ 2021-08-23 15:00 UTC (permalink / raw)
  To: xenomai

The refcnt field was never initialized and triggered a BUG() in
vfile_regular_release (vfile.c) when closing / releasing such a virtual
file.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 kernel/cobalt/registry.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/cobalt/registry.c b/kernel/cobalt/registry.c
index fa1de66c3..211e0f76f 100644
--- a/kernel/cobalt/registry.c
+++ b/kernel/cobalt/registry.c
@@ -403,6 +403,7 @@ static int registry_export_vfreg(struct xnobject *object,
 	object->vfile_u.vfreg.privsz = p->vfile.privsz;
 	object->vfile_u.vfreg.ops = p->vfile.ops;
 	object->vfile_u.vfreg.entry.lockops = p->vfile.lockops;
+	object->vfile_u.vfreg.entry.refcnt = 0;
 
 	ret = xnvfile_init_regular(object->key, &object->vfile_u.vfreg,
 				   &pnode->vdir);
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/6] cobalt/registry: Adding a new xnptree for exporting posix entries
  2021-08-23 15:00 [PATCH 0/6] Export posix mqueues and named semaphores to procfs Florian Bezdeka
  2021-08-23 15:00 ` [PATCH 1/6] cobalt/registry: Share xnregistry_vfreg_ops with other compile units Florian Bezdeka
  2021-08-23 15:00 ` [PATCH 2/6] cobalt/registry: Initialize refcnt of exported virtual proc files Florian Bezdeka
@ 2021-08-23 15:00 ` Florian Bezdeka
  2021-08-24  5:47   ` Jan Kiszka
  2021-08-23 15:00 ` [PATCH 4/6] cobalt/posix/mqueue: Export created mqueues to procfs Florian Bezdeka
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 10+ messages in thread
From: Florian Bezdeka @ 2021-08-23 15:00 UTC (permalink / raw)
  To: xenomai

Will be used later for exporting named semaphores as well as mqueues
to /proc/xenomai/registry/posix/{mqueue,sem}

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 kernel/cobalt/registry.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/cobalt/registry.c b/kernel/cobalt/registry.c
index 211e0f76f..3c67b64e6 100644
--- a/kernel/cobalt/registry.c
+++ b/kernel/cobalt/registry.c
@@ -73,6 +73,8 @@ static int proc_virq;
 
 static struct xnvfile_directory registry_vfroot;
 
+DEFINE_XNPTREE(posix_ptree, "posix");
+
 static int usage_vfile_show(struct xnvfile_regular_iterator *it, void *data)
 {
 	xnvfile_printf(it, "%u/%u\n",
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/6] cobalt/posix/mqueue: Export created mqueues to procfs
  2021-08-23 15:00 [PATCH 0/6] Export posix mqueues and named semaphores to procfs Florian Bezdeka
                   ` (2 preceding siblings ...)
  2021-08-23 15:00 ` [PATCH 3/6] cobalt/registry: Adding a new xnptree for exporting posix entries Florian Bezdeka
@ 2021-08-23 15:00 ` Florian Bezdeka
  2021-08-24  5:48   ` Jan Kiszka
  2021-08-23 15:00 ` [PATCH 5/6] cobalt/posix/semaphore: Export named semaphores " Florian Bezdeka
  2021-08-23 15:00 ` [PATCH 6/6] testsuite/smokey/leaks: Add export checks for mqueues and named semaphores Florian Bezdeka
  5 siblings, 1 reply; 10+ messages in thread
From: Florian Bezdeka @ 2021-08-23 15:00 UTC (permalink / raw)
  To: xenomai

Exporting created mqueues to /proc/xenomai/registry/posix/mqueue helps
to identify resource leaks by making mqueues visible. The content of all
created virtual files is empty. Removal of such files is not possible
and reports "operation not supported".

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 kernel/cobalt/posix/mqueue.c | 38 +++++++++++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/kernel/cobalt/posix/mqueue.c b/kernel/cobalt/posix/mqueue.c
index ebe7cf7b0..72759e484 100644
--- a/kernel/cobalt/posix/mqueue.c
+++ b/kernel/cobalt/posix/mqueue.c
@@ -87,6 +87,41 @@ static struct mq_attr default_attr = {
 
 static LIST_HEAD(cobalt_mqq);
 
+#ifdef CONFIG_XENO_OPT_VFILE
+
+extern struct xnptree posix_ptree;
+
+static int mq_vfile_show(struct xnvfile_regular_iterator *it, void *data)
+{
+	return 0;
+}
+
+static struct xnvfile_regular_ops mq_vfile_ops = {
+	.show = mq_vfile_show,
+};
+
+static struct xnpnode_regular __mq_pnode = {
+	.node = {
+		.dirname = "mqueue",
+		.root = &posix_ptree,
+		.ops = &xnregistry_vfreg_ops,
+	},
+	.vfile = {
+		.ops = &mq_vfile_ops,
+	},
+};
+
+#else /* !CONFIG_XENO_OPT_VFILE */
+
+static struct xnpnode_link __mq_pnode = {
+	.node = {
+		.dirname = "mqueue",
+	}
+};
+
+#endif /* !CONFIG_XENO_OPT_VFILE */
+
+
 static inline struct cobalt_msg *mq_msg_alloc(struct cobalt_mq *mq)
 {
 	if (list_empty(&mq->avail))
@@ -352,7 +387,8 @@ static int mq_open(int uqd, const char *name, int oflags,
 		}
 
 		xnlock_get_irqsave(&nklock, s);
-		err = xnregistry_enter(mq->name, mq, &mq->handle, NULL);
+		err = xnregistry_enter(mq->name, mq, &mq->handle,
+				       &__mq_pnode.node);
 		if (err < 0)
 			--mq->refs;
 		else
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 5/6] cobalt/posix/semaphore: Export named semaphores to procfs
  2021-08-23 15:00 [PATCH 0/6] Export posix mqueues and named semaphores to procfs Florian Bezdeka
                   ` (3 preceding siblings ...)
  2021-08-23 15:00 ` [PATCH 4/6] cobalt/posix/mqueue: Export created mqueues to procfs Florian Bezdeka
@ 2021-08-23 15:00 ` Florian Bezdeka
  2021-08-23 15:00 ` [PATCH 6/6] testsuite/smokey/leaks: Add export checks for mqueues and named semaphores Florian Bezdeka
  5 siblings, 0 replies; 10+ messages in thread
From: Florian Bezdeka @ 2021-08-23 15:00 UTC (permalink / raw)
  To: xenomai

Exporting named semaphores to /proc/xenomai/registry/posix/sem helps
to identify resource leaks by making registered semaphores visible. The
content of all created virtual files is empty. Removal of such files is
not possible and reports "operation not supported".

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 kernel/cobalt/posix/sem.c | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/kernel/cobalt/posix/sem.c b/kernel/cobalt/posix/sem.c
index 72b20c78d..88d7b363a 100644
--- a/kernel/cobalt/posix/sem.c
+++ b/kernel/cobalt/posix/sem.c
@@ -26,6 +26,40 @@
 #include "sem.h"
 #include <trace/events/cobalt-posix.h>
 
+#ifdef CONFIG_XENO_OPT_VFILE
+
+extern struct xnptree posix_ptree;
+
+static int sem_vfile_show(struct xnvfile_regular_iterator *it, void *data)
+{
+	return 0;
+}
+
+static struct xnvfile_regular_ops sem_vfile_ops = {
+	.show = sem_vfile_show,
+};
+
+static struct xnpnode_regular __sem_pnode = {
+	.node = {
+		.dirname = "sem",
+		.root = &posix_ptree,
+		.ops = &xnregistry_vfreg_ops,
+	},
+	.vfile = {
+		.ops = &sem_vfile_ops,
+	},
+};
+
+#else /* !CONFIG_XENO_OPT_VFILE */
+
+static struct xnpnode_link __sem_pnode = {
+	.node = {
+		.dirname = "sem",
+	}
+};
+
+#endif /* !CONFIG_XENO_OPT_VFILE */
+
 static inline struct cobalt_resources *sem_kqueue(struct cobalt_sem *sem)
 {
 	int pshared = !!(sem->flags & SEM_PSHARED);
@@ -134,7 +168,8 @@ __cobalt_sem_init(const char *name, struct cobalt_sem_shadow *sm,
 		goto err_lock_put;
 	}
 
-	ret = xnregistry_enter(name ?: "", sem, &sem->resnode.handle, NULL);
+	ret = xnregistry_enter(name ?: "", sem, &sem->resnode.handle,
+			       name ? &__sem_pnode.node : NULL);
 	if (ret < 0)
 		goto err_lock_put;
 
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 6/6] testsuite/smokey/leaks: Add export checks for mqueues and named semaphores
  2021-08-23 15:00 [PATCH 0/6] Export posix mqueues and named semaphores to procfs Florian Bezdeka
                   ` (4 preceding siblings ...)
  2021-08-23 15:00 ` [PATCH 5/6] cobalt/posix/semaphore: Export named semaphores " Florian Bezdeka
@ 2021-08-23 15:00 ` Florian Bezdeka
  2021-08-24  5:48   ` Jan Kiszka
  5 siblings, 1 reply; 10+ messages in thread
From: Florian Bezdeka @ 2021-08-23 15:00 UTC (permalink / raw)
  To: xenomai

Make sure mqueues and named semaphores are exported to the procfs if
the kernel has procfs support activated.

While at it: The exit code of the child process was never correctly
reported to the parent process. Hence, the status code check was wrong
at all. The variable previously named subprocess_status was not shared
between both processes.

Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
---
 testsuite/smokey/leaks/leaks.c | 68 ++++++++++++++++++++++------------
 1 file changed, 45 insertions(+), 23 deletions(-)

diff --git a/testsuite/smokey/leaks/leaks.c b/testsuite/smokey/leaks/leaks.c
index d5577d85e..433dfcc17 100644
--- a/testsuite/smokey/leaks/leaks.c
+++ b/testsuite/smokey/leaks/leaks.c
@@ -28,6 +28,7 @@
 #include <pthread.h>
 #include <fcntl.h>
 #include <sys/mman.h>
+#include <sys/stat.h>
 #include <semaphore.h>
 #include <mqueue.h>
 #include <signal.h>
@@ -71,6 +72,24 @@ const char *memdev[] = {
 
 static int memdevfd[3];
 
+static int procfs_exists(const char *type, const char *name)
+{
+	struct stat s;
+	char path[128];
+	int ret;
+
+	/* Ignore if the kernel seems to be compiled without procfs support */
+	if (stat("/proc/xenomai", &s) || !S_ISDIR(s.st_mode))
+		return 0;
+
+	ret = snprintf(path, 128, "%s/%s/%s", "/proc/xenomai/registry/posix",
+		       type, &name[1]);
+	if (ret < 0)
+		return -EINVAL;
+
+	return smokey_check_errno(stat(path, &s));
+}
+
 static unsigned long long get_used(void)
 {
 	struct cobalt_memdev_stat statbuf;
@@ -91,9 +110,7 @@ static void *empty(void *cookie)
 	return cookie;
 }
 
-static int subprocess_status;
-
-static inline void subprocess_leak(void)
+static inline int subprocess_leak(void)
 {
 	struct sigevent sevt;
 	pthread_mutex_t mutex;
@@ -105,36 +122,44 @@ static inline void subprocess_leak(void)
 
 	ret = smokey_check_status(pthread_create(&thread, NULL, empty, NULL));
 	if (ret)
-		goto fail;
+		return ret;
 	
 	ret = smokey_check_status(pthread_mutex_init(&mutex, NULL));
 	if (ret)
-		goto fail;
+		return ret;
 	
 	ret = smokey_check_status(pthread_cond_init(&cond, NULL));
 	if (ret)
-		goto fail;
+		return ret;
 
 	ret = smokey_check_errno(sem_init(&sem, 0, 0));
 	if (ret)
-		goto fail;
+		return ret;
 
 	ret = smokey_check_errno(-!(sem_open(SEM_NAME, O_CREAT, 0644, 1)));
 	if (ret)
-		goto fail;
+		return ret;
+
+	ret = procfs_exists("sem", SEM_NAME);
+	if (ret)
+		return ret;
 
 	sevt.sigev_notify = SIGEV_THREAD_ID;
 	sevt.sigev_signo = SIGALRM;
 	sevt.sigev_notify_thread_id = syscall(__NR_gettid);
 	ret = smokey_check_errno(timer_create(CLOCK_MONOTONIC, &sevt, &tm));
 	if (ret)
-		goto fail;
-	
+		return ret;
+
 	ret = smokey_check_errno(mq_open(MQ_NAME, O_RDWR | O_CREAT, 0644, NULL));
-	if (ret >= 0)
-		return;
-fail:
-	subprocess_status = ret;
+	if (ret < 0)
+		return ret;
+
+	ret = procfs_exists("mqueue", MQ_NAME);
+	if (ret)
+		return ret;
+
+	return 0;
 }
 
 static int run_leaks(struct smokey_test *t, int argc, char *const argv[])
@@ -143,7 +168,7 @@ static int run_leaks(struct smokey_test *t, int argc, char *const argv[])
 	struct sigevent sevt;
 	pthread_mutex_t mutex;
 	pthread_cond_t cond;
-	int fd, failed = 0, i, ret;
+	int fd, failed = 0, i, ret, child_ret;
 	pthread_t thread;
 	sem_t sem, *psem;
 	timer_t tm;
@@ -235,11 +260,9 @@ static int run_leaks(struct smokey_test *t, int argc, char *const argv[])
 	child = smokey_check_errno(fork());
 	if (child < 0)
 		return child;
-	if (!child) {
-		subprocess_leak();
-		exit(EXIT_SUCCESS);
-	}
-	while (waitpid(child, NULL, 0) == -1 && errno == EINTR);
+	if (!child)
+		exit(subprocess_leak());
+	while (waitpid(child, &child_ret, 0) == -1 && errno == EINTR);
 	sleep(1);
 
 	ret = smokey_check_errno(sem_unlink(SEM_NAME));
@@ -248,9 +271,8 @@ static int run_leaks(struct smokey_test *t, int argc, char *const argv[])
 	ret = smokey_check_errno(mq_unlink(MQ_NAME));
 	if (ret)
 		return ret;
-	if (subprocess_status)
-		return subprocess_status;
-		
+	if (WIFEXITED(child_ret) && WEXITSTATUS(child_ret))
+		return -WEXITSTATUS(child_ret);
 	check_used("fork", before, failed);
 #endif
 
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 3/6] cobalt/registry: Adding a new xnptree for exporting posix entries
  2021-08-23 15:00 ` [PATCH 3/6] cobalt/registry: Adding a new xnptree for exporting posix entries Florian Bezdeka
@ 2021-08-24  5:47   ` Jan Kiszka
  0 siblings, 0 replies; 10+ messages in thread
From: Jan Kiszka @ 2021-08-24  5:47 UTC (permalink / raw)
  To: Florian Bezdeka, xenomai

On 23.08.21 17:00, Florian Bezdeka wrote:
> Will be used later for exporting named semaphores as well as mqueues
> to /proc/xenomai/registry/posix/{mqueue,sem}
> 
> Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
> ---
>  kernel/cobalt/registry.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/kernel/cobalt/registry.c b/kernel/cobalt/registry.c
> index 211e0f76f..3c67b64e6 100644
> --- a/kernel/cobalt/registry.c
> +++ b/kernel/cobalt/registry.c
> @@ -73,6 +73,8 @@ static int proc_virq;
>  
>  static struct xnvfile_directory registry_vfroot;
>  
> +DEFINE_XNPTREE(posix_ptree, "posix");
> +
>  static int usage_vfile_show(struct xnvfile_regular_iterator *it, void *data)
>  {
>  	xnvfile_printf(it, "%u/%u\n",
> 

Better let kernel/cobalt/posix/process.c carry this.

Jan

-- 
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 4/6] cobalt/posix/mqueue: Export created mqueues to procfs
  2021-08-23 15:00 ` [PATCH 4/6] cobalt/posix/mqueue: Export created mqueues to procfs Florian Bezdeka
@ 2021-08-24  5:48   ` Jan Kiszka
  0 siblings, 0 replies; 10+ messages in thread
From: Jan Kiszka @ 2021-08-24  5:48 UTC (permalink / raw)
  To: Florian Bezdeka, xenomai

On 23.08.21 17:00, Florian Bezdeka wrote:
> Exporting created mqueues to /proc/xenomai/registry/posix/mqueue helps
> to identify resource leaks by making mqueues visible. The content of all
> created virtual files is empty. Removal of such files is not possible
> and reports "operation not supported".
> 
> Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
> ---
>  kernel/cobalt/posix/mqueue.c | 38 +++++++++++++++++++++++++++++++++++-
>  1 file changed, 37 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/cobalt/posix/mqueue.c b/kernel/cobalt/posix/mqueue.c
> index ebe7cf7b0..72759e484 100644
> --- a/kernel/cobalt/posix/mqueue.c
> +++ b/kernel/cobalt/posix/mqueue.c
> @@ -87,6 +87,41 @@ static struct mq_attr default_attr = {
>  
>  static LIST_HEAD(cobalt_mqq);
>  
> +#ifdef CONFIG_XENO_OPT_VFILE
> +
> +extern struct xnptree posix_ptree;

kernel/cobalt/posix/internal.h

Jan

> +
> +static int mq_vfile_show(struct xnvfile_regular_iterator *it, void *data)
> +{
> +	return 0;
> +}
> +
> +static struct xnvfile_regular_ops mq_vfile_ops = {
> +	.show = mq_vfile_show,
> +};
> +
> +static struct xnpnode_regular __mq_pnode = {
> +	.node = {
> +		.dirname = "mqueue",
> +		.root = &posix_ptree,
> +		.ops = &xnregistry_vfreg_ops,
> +	},
> +	.vfile = {
> +		.ops = &mq_vfile_ops,
> +	},
> +};
> +
> +#else /* !CONFIG_XENO_OPT_VFILE */
> +
> +static struct xnpnode_link __mq_pnode = {
> +	.node = {
> +		.dirname = "mqueue",
> +	}
> +};
> +
> +#endif /* !CONFIG_XENO_OPT_VFILE */
> +
> +
>  static inline struct cobalt_msg *mq_msg_alloc(struct cobalt_mq *mq)
>  {
>  	if (list_empty(&mq->avail))
> @@ -352,7 +387,8 @@ static int mq_open(int uqd, const char *name, int oflags,
>  		}
>  
>  		xnlock_get_irqsave(&nklock, s);
> -		err = xnregistry_enter(mq->name, mq, &mq->handle, NULL);
> +		err = xnregistry_enter(mq->name, mq, &mq->handle,
> +				       &__mq_pnode.node);
>  		if (err < 0)
>  			--mq->refs;
>  		else
> 

-- 
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 6/6] testsuite/smokey/leaks: Add export checks for mqueues and named semaphores
  2021-08-23 15:00 ` [PATCH 6/6] testsuite/smokey/leaks: Add export checks for mqueues and named semaphores Florian Bezdeka
@ 2021-08-24  5:48   ` Jan Kiszka
  0 siblings, 0 replies; 10+ messages in thread
From: Jan Kiszka @ 2021-08-24  5:48 UTC (permalink / raw)
  To: Florian Bezdeka, xenomai

On 23.08.21 17:00, Florian Bezdeka wrote:
> Make sure mqueues and named semaphores are exported to the procfs if
> the kernel has procfs support activated.
> 
> While at it: The exit code of the child process was never correctly
> reported to the parent process. Hence, the status code check was wrong
> at all. The variable previously named subprocess_status was not shared
> between both processes.

The second part should better be separate.

Jan

> 
> Signed-off-by: Florian Bezdeka <florian.bezdeka@siemens.com>
> ---
>  testsuite/smokey/leaks/leaks.c | 68 ++++++++++++++++++++++------------
>  1 file changed, 45 insertions(+), 23 deletions(-)
> 
> diff --git a/testsuite/smokey/leaks/leaks.c b/testsuite/smokey/leaks/leaks.c
> index d5577d85e..433dfcc17 100644
> --- a/testsuite/smokey/leaks/leaks.c
> +++ b/testsuite/smokey/leaks/leaks.c
> @@ -28,6 +28,7 @@
>  #include <pthread.h>
>  #include <fcntl.h>
>  #include <sys/mman.h>
> +#include <sys/stat.h>
>  #include <semaphore.h>
>  #include <mqueue.h>
>  #include <signal.h>
> @@ -71,6 +72,24 @@ const char *memdev[] = {
>  
>  static int memdevfd[3];
>  
> +static int procfs_exists(const char *type, const char *name)
> +{
> +	struct stat s;
> +	char path[128];
> +	int ret;
> +
> +	/* Ignore if the kernel seems to be compiled without procfs support */
> +	if (stat("/proc/xenomai", &s) || !S_ISDIR(s.st_mode))
> +		return 0;
> +
> +	ret = snprintf(path, 128, "%s/%s/%s", "/proc/xenomai/registry/posix",
> +		       type, &name[1]);
> +	if (ret < 0)
> +		return -EINVAL;
> +
> +	return smokey_check_errno(stat(path, &s));
> +}
> +
>  static unsigned long long get_used(void)
>  {
>  	struct cobalt_memdev_stat statbuf;
> @@ -91,9 +110,7 @@ static void *empty(void *cookie)
>  	return cookie;
>  }
>  
> -static int subprocess_status;
> -
> -static inline void subprocess_leak(void)
> +static inline int subprocess_leak(void)
>  {
>  	struct sigevent sevt;
>  	pthread_mutex_t mutex;
> @@ -105,36 +122,44 @@ static inline void subprocess_leak(void)
>  
>  	ret = smokey_check_status(pthread_create(&thread, NULL, empty, NULL));
>  	if (ret)
> -		goto fail;
> +		return ret;
>  	
>  	ret = smokey_check_status(pthread_mutex_init(&mutex, NULL));
>  	if (ret)
> -		goto fail;
> +		return ret;
>  	
>  	ret = smokey_check_status(pthread_cond_init(&cond, NULL));
>  	if (ret)
> -		goto fail;
> +		return ret;
>  
>  	ret = smokey_check_errno(sem_init(&sem, 0, 0));
>  	if (ret)
> -		goto fail;
> +		return ret;
>  
>  	ret = smokey_check_errno(-!(sem_open(SEM_NAME, O_CREAT, 0644, 1)));
>  	if (ret)
> -		goto fail;
> +		return ret;
> +
> +	ret = procfs_exists("sem", SEM_NAME);
> +	if (ret)
> +		return ret;
>  
>  	sevt.sigev_notify = SIGEV_THREAD_ID;
>  	sevt.sigev_signo = SIGALRM;
>  	sevt.sigev_notify_thread_id = syscall(__NR_gettid);
>  	ret = smokey_check_errno(timer_create(CLOCK_MONOTONIC, &sevt, &tm));
>  	if (ret)
> -		goto fail;
> -	
> +		return ret;
> +
>  	ret = smokey_check_errno(mq_open(MQ_NAME, O_RDWR | O_CREAT, 0644, NULL));
> -	if (ret >= 0)
> -		return;
> -fail:
> -	subprocess_status = ret;
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = procfs_exists("mqueue", MQ_NAME);
> +	if (ret)
> +		return ret;
> +
> +	return 0;
>  }
>  
>  static int run_leaks(struct smokey_test *t, int argc, char *const argv[])
> @@ -143,7 +168,7 @@ static int run_leaks(struct smokey_test *t, int argc, char *const argv[])
>  	struct sigevent sevt;
>  	pthread_mutex_t mutex;
>  	pthread_cond_t cond;
> -	int fd, failed = 0, i, ret;
> +	int fd, failed = 0, i, ret, child_ret;
>  	pthread_t thread;
>  	sem_t sem, *psem;
>  	timer_t tm;
> @@ -235,11 +260,9 @@ static int run_leaks(struct smokey_test *t, int argc, char *const argv[])
>  	child = smokey_check_errno(fork());
>  	if (child < 0)
>  		return child;
> -	if (!child) {
> -		subprocess_leak();
> -		exit(EXIT_SUCCESS);
> -	}
> -	while (waitpid(child, NULL, 0) == -1 && errno == EINTR);
> +	if (!child)
> +		exit(subprocess_leak());
> +	while (waitpid(child, &child_ret, 0) == -1 && errno == EINTR);
>  	sleep(1);
>  
>  	ret = smokey_check_errno(sem_unlink(SEM_NAME));
> @@ -248,9 +271,8 @@ static int run_leaks(struct smokey_test *t, int argc, char *const argv[])
>  	ret = smokey_check_errno(mq_unlink(MQ_NAME));
>  	if (ret)
>  		return ret;
> -	if (subprocess_status)
> -		return subprocess_status;
> -		
> +	if (WIFEXITED(child_ret) && WEXITSTATUS(child_ret))
> +		return -WEXITSTATUS(child_ret);
>  	check_used("fork", before, failed);
>  #endif
>  
> 

-- 
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-08-24  5:48 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-23 15:00 [PATCH 0/6] Export posix mqueues and named semaphores to procfs Florian Bezdeka
2021-08-23 15:00 ` [PATCH 1/6] cobalt/registry: Share xnregistry_vfreg_ops with other compile units Florian Bezdeka
2021-08-23 15:00 ` [PATCH 2/6] cobalt/registry: Initialize refcnt of exported virtual proc files Florian Bezdeka
2021-08-23 15:00 ` [PATCH 3/6] cobalt/registry: Adding a new xnptree for exporting posix entries Florian Bezdeka
2021-08-24  5:47   ` Jan Kiszka
2021-08-23 15:00 ` [PATCH 4/6] cobalt/posix/mqueue: Export created mqueues to procfs Florian Bezdeka
2021-08-24  5:48   ` Jan Kiszka
2021-08-23 15:00 ` [PATCH 5/6] cobalt/posix/semaphore: Export named semaphores " Florian Bezdeka
2021-08-23 15:00 ` [PATCH 6/6] testsuite/smokey/leaks: Add export checks for mqueues and named semaphores Florian Bezdeka
2021-08-24  5:48   ` Jan Kiszka

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.