apps/examples/watcher: Fixed an assert failure
This commit is contained in:
parent
ff4c3c3fb8
commit
1673df81d1
@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* examples/watched/watched.c
|
* apps/examples/watched/watched.c
|
||||||
*
|
*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -156,7 +156,7 @@ int watched_unsubscribe(struct watched_info_s *info)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int feed_dog(struct watched_info_s *info)
|
int watched_feed_dog(struct watched_info_s *info)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ int feed_dog(struct watched_info_s *info)
|
|||||||
if (ret == ERROR)
|
if (ret == ERROR)
|
||||||
{
|
{
|
||||||
int errcode = errno;
|
int errcode = errno;
|
||||||
fprintf(stderr, "feed_dog: error %d\n", errcode);
|
fprintf(stderr, "watched_feed_dog: error %d\n", errcode);
|
||||||
ret = errcode;
|
ret = errcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* examples/watched/watched.h
|
* apps/examples/watched/watched.h
|
||||||
*
|
*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -74,6 +74,6 @@ bool watched_is_watcher_on(void);
|
|||||||
int watched_read_watcher_info(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_subscribe(struct watched_info_s *info);
|
||||||
int watched_unsubscribe(struct watched_info_s *info);
|
int watched_unsubscribe(struct watched_info_s *info);
|
||||||
int feed_dog(struct watched_info_s *info);
|
int watched_feed_dog(struct watched_info_s *info);
|
||||||
|
|
||||||
#endif /* __EXAMPLES_WATCHER_WATCHED_H */
|
#endif /* __EXAMPLES_WATCHER_WATCHED_H */
|
||||||
|
@ -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
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -60,7 +60,7 @@ static int task1(int argc, FAR char *argv[])
|
|||||||
|
|
||||||
for (; ; )
|
for (; ; )
|
||||||
{
|
{
|
||||||
feed_dog(&watched_info);
|
watched_feed_dog(&watched_info);
|
||||||
sleep(3);
|
sleep(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,8 +111,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (!watched_is_watcher_on())
|
if (!watched_is_watcher_on())
|
||||||
{
|
{
|
||||||
printf("Please, enable the watcher service \
|
printf("Please, enable the watcher service "
|
||||||
before subscribing tasks!\n");
|
"before subscribing tasks!\n");
|
||||||
ret = ENOENT;
|
ret = ENOENT;
|
||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
@ -44,8 +44,13 @@ config EXAMPLES_WATCHER_TIMEOUT
|
|||||||
|
|
||||||
config EXAMPLES_WATCHER_SIGNAL
|
config EXAMPLES_WATCHER_SIGNAL
|
||||||
int "Signal Number for communication"
|
int "Signal Number for communication"
|
||||||
default 17
|
default 18
|
||||||
---help---
|
---help---
|
||||||
This is the Signal Number used for communication between the watcher task and the watched tasks.
|
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
|
endif
|
||||||
|
@ -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
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
* 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);
|
notefd = open("/dev/note", O_RDONLY);
|
||||||
if (notefd < 0)
|
if (notefd < 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "trace: cannot open /dev/note\n");
|
printf("Error: cannot open /dev/note\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,14 +82,13 @@ void task_mn_print_tasks_status(void)
|
|||||||
{
|
{
|
||||||
task.pid = node->task_id;
|
task.pid = node->task_id;
|
||||||
ioctl(notefd, NOTERAM_GETTASKNAME, (unsigned long)&task);
|
ioctl(notefd, NOTERAM_GETTASKNAME, (unsigned long)&task);
|
||||||
printf("%s ", task.taskname);
|
|
||||||
if (node->reset)
|
if (node->reset)
|
||||||
{
|
{
|
||||||
printf("fed the dog.\n");
|
printf("%s fed the dog.\n", task.taskname);
|
||||||
}
|
}
|
||||||
else
|
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
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr, "watcher: List is empty to print\n");
|
printf("Error: Task list is empty to print\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
* 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
|
* Name: watcher_daemon
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -125,21 +136,30 @@ static int watcher_daemon(int argc, FAR char *argv[])
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct sigaction act;
|
struct sigaction act;
|
||||||
|
struct sigaction act_log;
|
||||||
pid_t watcher_pid;
|
pid_t watcher_pid;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
printf("Watcher Daemon has started!\n");
|
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
|
act.sa_sigaction = feed_sighandler; /* The handler to be triggered when
|
||||||
* receiving a signal */
|
* receiving a signal */
|
||||||
act.sa_flags = SA_SIGINFO; /* Invoke the signal-catching function */
|
act.sa_flags = SA_SIGINFO; /* Invoke the signal-catching function */
|
||||||
sigfillset(&act.sa_mask);
|
sigfillset(&act.sa_mask);
|
||||||
sigdelset(&act.sa_mask, CONFIG_EXAMPLES_WATCHER_SIGNAL); /* Block all
|
|
||||||
* other
|
/* Block all other signals less this one */
|
||||||
* signals less
|
|
||||||
* this one */
|
sigdelset(&act.sa_mask, CONFIG_EXAMPLES_WATCHER_SIGNAL);
|
||||||
|
|
||||||
ret = sigaction(CONFIG_EXAMPLES_WATCHER_SIGNAL, &act, NULL);
|
ret = sigaction(CONFIG_EXAMPLES_WATCHER_SIGNAL, &act, NULL);
|
||||||
if (ret != OK)
|
if (ret != OK)
|
||||||
@ -150,6 +170,26 @@ static int watcher_daemon(int argc, FAR char *argv[])
|
|||||||
goto errout;
|
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 */
|
/* Collecting the necessary information of the current task */
|
||||||
|
|
||||||
watcher_pid = getpid();
|
watcher_pid = getpid();
|
||||||
@ -210,10 +250,6 @@ int main(int argc, FAR char *argv[])
|
|||||||
|
|
||||||
prepare_fs();
|
prepare_fs();
|
||||||
|
|
||||||
/* Initialize and configure the wdt */
|
|
||||||
|
|
||||||
wdt_init();
|
|
||||||
|
|
||||||
/* Start Daemon */
|
/* Start Daemon */
|
||||||
|
|
||||||
ret = task_create("watcher_daemon", CONFIG_EXAMPLES_WATCHER_PRIORITY,
|
ret = task_create("watcher_daemon", CONFIG_EXAMPLES_WATCHER_PRIORITY,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* examples/watcher/wdt.c
|
* apps/examples/watcher/wdt.c
|
||||||
*
|
*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -30,6 +30,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <debug.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include "wdt.h"
|
#include "wdt.h"
|
||||||
#include "task_mn.h"
|
#include "task_mn.h"
|
||||||
@ -38,20 +39,36 @@
|
|||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* 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
|
* 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
|
* Private Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static struct wdog_params_s wdog =
|
static struct wdog_params_s wdog =
|
||||||
{.timeout = CONFIG_EXAMPLES_WATCHER_TIMEOUT,
|
{
|
||||||
|
.timeout = CONFIG_EXAMPLES_WATCHER_TIMEOUT,
|
||||||
.handlers.oldhandler = NULL,
|
.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");
|
int errcode = errno;
|
||||||
task_mn_print_tasks_status();
|
_err("Error: %d\n", errcode);
|
||||||
task_mn_reset_all();
|
ret = errcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -136,6 +158,10 @@ int wdt_init(void)
|
|||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
/* Set the pid, so the handler will be able to notify watcher */
|
||||||
|
|
||||||
|
log_info.task_id = getpid();
|
||||||
|
|
||||||
errout:
|
errout:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user