# HG changeset patch # User Edouard Tisserant # Date 1631528357 -7200 # Node ID 5f9db9c6c69c2a494f18a05b59f964cef0920c21 # Parent f4d89cecc6e649956f409cc67c17caa0195b19e5 Xenomai runtime: more verbose error message when problem with RT-Pipes. diff -r f4d89cecc6e6 -r 5f9db9c6c69c targets/Xenomai/plc_Xenomai_main.c --- a/targets/Xenomai/plc_Xenomai_main.c Mon Sep 13 12:18:08 2021 +0200 +++ b/targets/Xenomai/plc_Xenomai_main.c Mon Sep 13 12:19:17 2021 +0200 @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -117,16 +118,16 @@ static unsigned long __debug_tick; -#define _LogAndReturnNull(text) \ +#define _Log(text, err) \ {\ - char mstr[256] = text " for ";\ - strncat(mstr, name, 255);\ + char mstr[256];\ + snprintf(mstr, 255, text " for %s (%d)", name, err);\ LogMessage(LOG_CRITICAL, mstr, strlen(mstr));\ - return NULL;\ } void *create_RT_to_nRT_signal(char* name){ int new_index = -1; + int ret; RT_to_nRT_signal_t *sig; char pipe_dev[64]; @@ -141,19 +142,22 @@ /* fail if none found */ if(new_index == -1) { - _LogAndReturnNull("Maximum count of RT-PIPE reached while creating pipe"); + _Log("Maximum count of RT-PIPE reached while creating pipe", max_RT_to_nRT_signals); + return NULL; } /* create rt pipe */ - if(rt_pipe_create(&sig->pipe, name, new_index, PIPE_SIZE) < 0){ - _LogAndReturnNull("Failed opening real-time end of RT-PIPE"); + if(ret = rt_pipe_create(&sig->pipe, name, new_index, PIPE_SIZE) < 0){ + _Log("Failed opening real-time end of RT-PIPE", ret); + return NULL; } /* open pipe's userland */ - snprintf(pipe_dev, 64, "/dev/rtp%d", new_index); + snprintf(pipe_dev, 63, "/dev/rtp%d", new_index); if((sig->pipe_fd = open(pipe_dev, O_RDWR)) == -1){ rt_pipe_delete(&sig->pipe); - _LogAndReturnNull("Failed opening non-real-time end of RT-PIPE"); + _Log("Failed opening non-real-time end of RT-PIPE", errno); + return NULL; } sig->used = 1; @@ -163,13 +167,19 @@ } void delete_RT_to_nRT_signal(void* handle){ + int ret; RT_to_nRT_signal_t *sig = (RT_to_nRT_signal_t*)handle; + char *name = sig->name; if(!sig->used) return; - rt_pipe_delete(&sig->pipe); - - close(sig->pipe_fd); + if(ret = rt_pipe_delete(&sig->pipe) != 0){ + _Log("Failed closing real-time end of RT-PIPE", ret); + } + + if(close(sig->pipe_fd) != 0){ + _Log("Failed closing non-real-time end of RT-PIPE", errno); + } sig->used = 0; }