Module: xenomai-forge
Branch: next
Commit: 7fee510f194a7045c17872d28212bd18ce71f47c
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=7fee510f194a7045c17872d28212bd18ce71f47c

Author: Philippe Gerum <r...@xenomai.org>
Date:   Mon May 26 15:13:02 2014 +0200

lib/cobalt: warn unconditionally on critical SIGDEBUG receipt

---

 lib/cobalt/internal.c          |   38 +++++++++++++++++++++++++-------------
 testsuite/latency/latency.c    |    2 +-
 testsuite/unit/mutex-torture.c |    2 +-
 3 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index ef092e9..b1cbc4e 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -397,23 +397,35 @@ int cobalt_monitor_drain_all_sync(cobalt_monitor_t *mon)
        return ret;
 }
 
+#define __raw_write_out(__msg)                                 \
+       do {                                                    \
+               int __ret;                                      \
+               __ret = write(1, __msg , sizeof(__msg));        \
+               (void)__ret;                                    \
+       } while (0)
+
+#define raw_write_out(__msg)   __raw_write_out("Xenomai/cobalt: " __msg "\n")
+
 void cobalt_sigdebug_handler(int sig, siginfo_t *si, void *context)
 {
-       if (si->si_value.sival_int == SIGDEBUG_NOMLOCK) {
-               fprintf(stderr, "Xenomai: process memory not locked "
-                       "(missing mlockall?)\n");
-               fflush(stderr);
-               exit(4);
+       if (!sigdebug_marked(si))
+               goto forward;
+
+       switch (sigdebug_reason(si)) {
+       case SIGDEBUG_NOMLOCK:
+               raw_write_out("process memory not locked (missing mlockall?)");
+               _exit(4);
+       case SIGDEBUG_RESCNT_IMBALANCE:
+               raw_write_out("internal resource count imbalance");
+               _exit(5);
+       case SIGDEBUG_WATCHDOG:
+               raw_write_out("watchdog triggered");
+               break;
        }
 
-       /*
-        * XNTRAPSW was set for the thread but no user-defined handler
-        * has been set to override our internal handler, so let's
-        * restore the setting before we registered and re-raise the
-        * signal. Usually triggers the default signal action.
-        */
-       sigaction(SIGXCPU, &__cobalt_orig_sigdebug, NULL);
-       pthread_kill(pthread_self(), SIGXCPU);
+forward:
+       sigaction(SIGDEBUG, &__cobalt_orig_sigdebug, NULL);
+       pthread_kill(pthread_self(), SIGDEBUG);
 }
 
 static inline
diff --git a/testsuite/latency/latency.c b/testsuite/latency/latency.c
index a4fc39c..ccf7dfe 100644
--- a/testsuite/latency/latency.c
+++ b/testsuite/latency/latency.c
@@ -547,7 +547,7 @@ static void sigdebug(int sig, siginfo_t *si, void *context)
 {
        const char fmt[] = "Mode switch detected (reason: %s), aborting.\n"
                "Enable XENO_OPT_DEBUG_TRACE_RELAX to find the cause.\n";
-       unsigned int reason = si->si_value.sival_int;
+       unsigned int reason = sigdebug_reason(si);
        int n __attribute__ ((unused));
        static char buffer[256];
 
diff --git a/testsuite/unit/mutex-torture.c b/testsuite/unit/mutex-torture.c
index ede430b..c0a0457 100644
--- a/testsuite/unit/mutex-torture.c
+++ b/testsuite/unit/mutex-torture.c
@@ -50,7 +50,7 @@ static const char *reason_str[] = {
 
 static void sigdebug(int sig, siginfo_t *si, void *context)
 {
-       unsigned int reason = si->si_value.sival_int;
+       unsigned int reason = sigdebug_reason(si);
 
        printf("\nSIGDEBUG received, reason %d: %s\n", reason,
               reason <= SIGDEBUG_WATCHDOG ? reason_str[reason] : "<unknown>");


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to