From 5ef537684eeeeb59f63d7ca7fe4e65b4be37474a Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Sat, 26 Jun 2021 22:02:33 -0700 Subject: [PATCH] RTEMS5: update libbsd logging Show messages synchronously during boot, then redirect through errlog before user app. Disable syslog() during tests --- modules/libcom/RTEMS/posix/rtems_init.c | 53 ++++++++++++++++++++++--- modules/libcom/src/misc/epicsUnitTest.c | 19 +++++++++ 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/modules/libcom/RTEMS/posix/rtems_init.c b/modules/libcom/RTEMS/posix/rtems_init.c index 960a7841b..33983f76c 100644 --- a/modules/libcom/RTEMS/posix/rtems_init.c +++ b/modules/libcom/RTEMS/posix/rtems_init.c @@ -18,6 +18,9 @@ * Extensive tests so far only with qemu. */ +/* trigger sys/syslog.h to emit prioritynames[] */ +#define SYSLOG_NAMES + #include #include #include @@ -30,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -633,6 +637,42 @@ static void zonesetCallFunc(const iocshArgBuf *args) zoneset(args[0].sval); } +#ifndef RTEMS_LEGACY_STACK +static int bsd_log_to_erl(int level, const char *fmt, va_list ap) +{ + return errlogVprintf(fmt, ap); +} +#endif // RTEMS_LEGACY_STACK + +static void setlogmaskCallFunc(const iocshArgBuf *args) +{ + const char* name = args[0].sval; + const CODE* cur; + if(!name) { + printf("Usage: setlogmask \n" + "\n" + " Level names:\n"); + for(cur = prioritynames; cur->c_name; cur++) { + printf(" %s\n", cur->c_name); + } + } else { + for(cur = prioritynames; cur->c_name; cur++) { + if(strcmp(name, cur->c_name)!=0) + continue; + + (void)setlogmask(LOG_MASK(cur->c_val)); +#ifndef RTEMS_LEGACY_STACK + rtems_bsd_setlogpriority(name); +#endif + return; + } + printf("Error: unknown log level.\n"); + } +} +static const iocshArg setlogmaskArg0 = {"level name", iocshArgString}; +static const iocshArg * const setlogmaskArgs[1] = {&setlogmaskArg0}; +static const iocshFuncDef setlogmaskFuncDef = {"setlogmask",1,setlogmaskArgs, + "Set syslog() threshold level"}; /* * Register RTEMS-specific commands @@ -646,6 +686,7 @@ static void iocshRegisterRTEMS (void) #endif iocshRegister(&zonesetFuncDef, &zonesetCallFunc); iocshRegister(&rtshellFuncDef, &rtshellCallFunc); + iocshRegister(&setlogmaskFuncDef, &setlogmaskCallFunc); #if __RTEMS_MAJOR__ > 4 rtems_shell_init_environment(); #endif @@ -977,9 +1018,6 @@ POSIX_Init ( void *argument __attribute__((unused))) /* Let other tasks run to complete background work */ default_network_set_self_prio(RTEMS_MAXIMUM_PRIORITY - 1U); - /* suppress all output from bsd network initialization */ - rtems_bsd_set_vprintf_handler(rtems_bsd_vprintf_handler_mute); - sc = rtems_bsd_initialize(); assert(sc == RTEMS_SUCCESSFUL); @@ -1066,9 +1104,6 @@ POSIX_Init ( void *argument __attribute__((unused))) rtems_bsdnet_synchronize_ntp (0, 0); #endif // not RTEMS_LEGACY_STACK - /* show messages from network after initialization ? good idea? */ - //rtems_bsd_set_vprintf_handler(bsd_vprintf_handler_old); - printf("\n***** Setting up file system *****\n"); initialize_remote_filesystem(argv, initialize_local_filesystem(argv)); fixup_hosts(); @@ -1113,6 +1148,12 @@ POSIX_Init ( void *argument __attribute__((unused))) errlogFlush(); printf ("***** Starting EPICS application *****\n"); + +#ifndef RTEMS_LEGACY_STACK + // switch OS to async logging + rtems_bsd_set_vprintf_handler(bsd_log_to_erl); +#endif + #if 0 // Start an rtems shell before main, for debugging RTEMS system issues rtems_shell_init("SHLL", RTEMS_MINIMUM_STACK_SIZE * 4, diff --git a/modules/libcom/src/misc/epicsUnitTest.c b/modules/libcom/src/misc/epicsUnitTest.c index a15af0a95..d21bcf03b 100644 --- a/modules/libcom/src/misc/epicsUnitTest.c +++ b/modules/libcom/src/misc/epicsUnitTest.c @@ -28,6 +28,13 @@ # endif #endif +#ifdef __rtems__ +# include +# ifndef RTEMS_LEGACY_STACK +# include +# endif +#endif + #include "epicsThread.h" #include "epicsMutex.h" #include "epicsUnitTest.h" @@ -95,6 +102,18 @@ static int testReportHook(int reportType, char *message, int *returnValue) static void testOnce(void *dummy) { testLock = epicsMutexMustCreate(); perlHarness = (getenv("HARNESS_ACTIVE") != NULL); +#ifdef __rtems__ + // syslog() on RTEMS prints to stdout, which will interfere with test output. + // setlogmask() ignores empty mask, so must allow at least one level. + (void)setlogmask(LOG_MASK(LOG_CRIT)); + printf("# mask syslog() output\n"); +#ifndef RTEMS_LEGACY_STACK + // with libbsd setlogmask() is a no-op :( + // name strings in sys/syslog.h + rtems_bsd_setlogpriority("crit"); +#endif +#endif + #ifdef _WIN32 #ifdef HAVE_SETERROMODE /* SEM_FAILCRITICALERRORS - Don't display modal dialog