You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/03/16 18:30:12 UTC
[incubator-nuttx-apps] branch master updated:
apps/examples/watcher: Fixed an assert failure
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 1673df8 apps/examples/watcher: Fixed an assert failure
1673df8 is described below
commit 1673df81d165152804b4c39da7562fafa2dd2d41
Author: Sara Souza <sa...@espressif.com>
AuthorDate: Mon Mar 8 10:32:13 2021 -0300
apps/examples/watcher: Fixed an assert failure
---
examples/watched/watched.c | 6 ++---
examples/watched/watched.h | 10 ++++----
examples/watched/watched_main.c | 8 +++---
examples/watcher/Kconfig | 7 +++++-
examples/watcher/task_mn.c | 11 ++++----
examples/watcher/watcher_main.c | 56 +++++++++++++++++++++++++++++++++--------
examples/watcher/wdt.c | 46 +++++++++++++++++++++++++--------
7 files changed, 105 insertions(+), 39 deletions(-)
diff --git a/examples/watched/watched.c b/examples/watched/watched.c
index 87a66e9..2f6a49d 100644
--- a/examples/watched/watched.c
+++ b/examples/watched/watched.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * examples/watched/watched.c
+ * apps/examples/watched/watched.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -156,7 +156,7 @@ int watched_unsubscribe(struct watched_info_s *info)
return ret;
}
-int feed_dog(struct watched_info_s *info)
+int watched_feed_dog(struct watched_info_s *info)
{
int ret;
@@ -168,7 +168,7 @@ int feed_dog(struct watched_info_s *info)
if (ret == ERROR)
{
int errcode = errno;
- fprintf(stderr, "feed_dog: error %d\n", errcode);
+ fprintf(stderr, "watched_feed_dog: error %d\n", errcode);
ret = errcode;
}
diff --git a/examples/watched/watched.h b/examples/watched/watched.h
index 6cc1973..8f2150c 100644
--- a/examples/watched/watched.h
+++ b/examples/watched/watched.h
@@ -1,5 +1,5 @@
/****************************************************************************
- * examples/watched/watched.h
+ * apps/examples/watched/watched.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -71,9 +71,9 @@ struct watched_info_s
****************************************************************************/
bool watched_is_watcher_on(void);
-int watched_read_watcher_info(struct watched_info_s *info);
-int watched_subscribe(struct watched_info_s *info);
-int watched_unsubscribe(struct watched_info_s *info);
-int feed_dog(struct watched_info_s *info);
+int watched_read_watcher_info(struct watched_info_s *info);
+int watched_subscribe(struct watched_info_s *info);
+int watched_unsubscribe(struct watched_info_s *info);
+int watched_feed_dog(struct watched_info_s *info);
#endif /* __EXAMPLES_WATCHER_WATCHED_H */
diff --git a/examples/watched/watched_main.c b/examples/watched/watched_main.c
index 76fee41..cc44d03 100644
--- a/examples/watched/watched_main.c
+++ b/examples/watched/watched_main.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * examples/watched/watched_main.c
+ * apps/examples/watched/watched_main.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -60,7 +60,7 @@ static int task1(int argc, FAR char *argv[])
for (; ; )
{
- feed_dog(&watched_info);
+ watched_feed_dog(&watched_info);
sleep(3);
}
@@ -111,8 +111,8 @@ int main(int argc, char *argv[])
if (!watched_is_watcher_on())
{
- printf("Please, enable the watcher service \
- before subscribing tasks!\n");
+ printf("Please, enable the watcher service "
+ "before subscribing tasks!\n");
ret = ENOENT;
goto errout;
}
diff --git a/examples/watcher/Kconfig b/examples/watcher/Kconfig
index 3262913..fa8ceeb 100644
--- a/examples/watcher/Kconfig
+++ b/examples/watcher/Kconfig
@@ -44,8 +44,13 @@ config EXAMPLES_WATCHER_TIMEOUT
config EXAMPLES_WATCHER_SIGNAL
int "Signal Number for communication"
- default 17
+ default 18
---help---
This is the Signal Number used for communication between the watcher task and the watched tasks.
+config EXAMPLES_WATCHER_SIGNAL_LOG
+ int "Signal Number for logging"
+ default 19
+ ---help---
+ This is the Signal Number used by the wdt handler to notify the signal handler to log the tasks.
endif
diff --git a/examples/watcher/task_mn.c b/examples/watcher/task_mn.c
index 8ba7527..d2a6892 100644
--- a/examples/watcher/task_mn.c
+++ b/examples/watcher/task_mn.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * examples/watcher/task_mn.c
+ * apps/examples/watcher/task_mn.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -72,7 +72,7 @@ void task_mn_print_tasks_status(void)
notefd = open("/dev/note", O_RDONLY);
if (notefd < 0)
{
- fprintf(stderr, "trace: cannot open /dev/note\n");
+ printf("Error: cannot open /dev/note\n");
return;
}
@@ -82,14 +82,13 @@ void task_mn_print_tasks_status(void)
{
task.pid = node->task_id;
ioctl(notefd, NOTERAM_GETTASKNAME, (unsigned long)&task);
- printf("%s ", task.taskname);
if (node->reset)
{
- printf("fed the dog.\n");
+ printf("%s fed the dog.\n", task.taskname);
}
else
{
- printf("starved the dog.\n");
+ printf("%s starved the dog.\n", task.taskname);
}
}
@@ -99,7 +98,7 @@ void task_mn_print_tasks_status(void)
}
else
{
- fprintf(stderr, "watcher: List is empty to print\n");
+ printf("Error: Task list is empty to print\n");
}
}
diff --git a/examples/watcher/watcher_main.c b/examples/watcher/watcher_main.c
index c62e859..0534846 100644
--- a/examples/watcher/watcher_main.c
+++ b/examples/watcher/watcher_main.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * examples/watcher/watcher_main.c
+ * apps/examples/watcher/watcher_main.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -117,6 +117,17 @@ static void feed_sighandler(int signo, FAR siginfo_t * siginfo,
}
}
+static void wdt_log(int signo, FAR siginfo_t * siginfo,
+ FAR void *context)
+{
+ if (watched_tasks.head != NULL)
+ {
+ printf("*** Printing Tasks Status ***\n");
+ task_mn_print_tasks_status();
+ task_mn_reset_all();
+ }
+}
+
/****************************************************************************
* Name: watcher_daemon
****************************************************************************/
@@ -125,21 +136,30 @@ static int watcher_daemon(int argc, FAR char *argv[])
{
int ret;
struct sigaction act;
+ struct sigaction act_log;
pid_t watcher_pid;
FILE *fp;
printf("Watcher Daemon has started!\n");
- /* Configuring a signal action */
+ /* Initialize and configure the wdt */
+
+ wdt_init();
+
+ /* Configure signals action */
+
+ /* Configure signal to receive the subscribe/unsubscribe
+ * and feed requests
+ */
act.sa_sigaction = feed_sighandler; /* The handler to be triggered when
* receiving a signal */
act.sa_flags = SA_SIGINFO; /* Invoke the signal-catching function */
sigfillset(&act.sa_mask);
- sigdelset(&act.sa_mask, CONFIG_EXAMPLES_WATCHER_SIGNAL); /* Block all
- * other
- * signals less
- * this one */
+
+ /* Block all other signals less this one */
+
+ sigdelset(&act.sa_mask, CONFIG_EXAMPLES_WATCHER_SIGNAL);
ret = sigaction(CONFIG_EXAMPLES_WATCHER_SIGNAL, &act, NULL);
if (ret != OK)
@@ -150,6 +170,26 @@ static int watcher_daemon(int argc, FAR char *argv[])
goto errout;
}
+ /* Configure signal to log the taks at wdt timeout */
+
+ act_log.sa_sigaction = wdt_log; /* The handler to be triggered when
+ * receiving a signal */
+ act_log.sa_flags = SA_SIGINFO; /* Invoke the signal-catching function */
+ sigfillset(&act_log.sa_mask);
+
+ /* Block all other signals less this one */
+
+ sigdelset(&act_log.sa_mask, CONFIG_EXAMPLES_WATCHER_SIGNAL_LOG);
+
+ ret = sigaction(CONFIG_EXAMPLES_WATCHER_SIGNAL_LOG, &act_log, NULL);
+ if (ret != OK)
+ {
+ int errcode = errno;
+ fprintf(stderr, "ERROR: sigaction failed: %d\n", errcode);
+ ret = errcode;
+ goto errout;
+ }
+
/* Collecting the necessary information of the current task */
watcher_pid = getpid();
@@ -210,10 +250,6 @@ int main(int argc, FAR char *argv[])
prepare_fs();
- /* Initialize and configure the wdt */
-
- wdt_init();
-
/* Start Daemon */
ret = task_create("watcher_daemon", CONFIG_EXAMPLES_WATCHER_PRIORITY,
diff --git a/examples/watcher/wdt.c b/examples/watcher/wdt.c
index d34cebd..ea4ff6d 100644
--- a/examples/watcher/wdt.c
+++ b/examples/watcher/wdt.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * examples/watcher/wdt.c
+ * apps/examples/watcher/wdt.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -30,6 +30,7 @@
#include <string.h>
#include <errno.h>
#include <fcntl.h>
+#include <debug.h>
#include <sys/ioctl.h>
#include "wdt.h"
#include "task_mn.h"
@@ -39,19 +40,35 @@
****************************************************************************/
/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct wdt_loginfo_s
+{
+ pid_t task_id; /* Id of the task that performs logging */
+ int signal; /* Signal that triggers the logging */
+};
+
+/****************************************************************************
* Private Definitions
****************************************************************************/
-static int wdt_print_handler(int irq, FAR void *context, FAR void *arg);
+static int wdt_handler(int irq, FAR void *context, FAR void *arg);
/****************************************************************************
* Private Data
****************************************************************************/
static struct wdog_params_s wdog =
-{.timeout = CONFIG_EXAMPLES_WATCHER_TIMEOUT,
+{
+ .timeout = CONFIG_EXAMPLES_WATCHER_TIMEOUT,
.handlers.oldhandler = NULL,
- .handlers.newhandler = wdt_print_handler
+ .handlers.newhandler = wdt_handler
+};
+
+static struct wdt_loginfo_s log_info =
+{
+ .signal = CONFIG_EXAMPLES_WATCHER_SIGNAL_LOG
};
/****************************************************************************
@@ -67,16 +84,21 @@ static struct wdog_params_s wdog =
*
****************************************************************************/
-static int wdt_print_handler(int irq, FAR void *context, FAR void *arg)
+static int wdt_handler(int irq, FAR void *context, FAR void *arg)
{
- if (watched_tasks.head != NULL)
+ int ret = OK;
+
+ /* Notify the watcher task to log */
+
+ ret = kill(log_info.task_id, log_info.signal);
+ if (ret == ERROR)
{
- printf("*** Printing Tasks Status ***\n");
- task_mn_print_tasks_status();
- task_mn_reset_all();
+ int errcode = errno;
+ _err("Error: %d\n", errcode);
+ ret = errcode;
}
- return OK;
+ return ret;
}
/****************************************************************************
@@ -136,6 +158,10 @@ int wdt_init(void)
close(fd);
+ /* Set the pid, so the handler will be able to notify watcher */
+
+ log_info.task_id = getpid();
+
errout:
return ret;
}