RTEMS5: update libbsd logging

Show messages synchronously during boot,
then redirect through errlog before user app.

Disable syslog() during tests
This commit is contained in:
Michael Davidsaver
2021-06-26 22:02:33 -07:00
parent c1dcd728d7
commit 5ef537684e
2 changed files with 66 additions and 6 deletions

View File

@@ -18,6 +18,9 @@
* Extensive tests so far only with qemu.
*/
/* trigger sys/syslog.h to emit prioritynames[] */
#define SYSLOG_NAMES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -30,6 +33,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/syslog.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <assert.h>
@@ -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 <level>\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,

View File

@@ -28,6 +28,13 @@
# endif
#endif
#ifdef __rtems__
# include <syslog.h>
# ifndef RTEMS_LEGACY_STACK
# include <rtems/bsd/bsd.h>
# 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