Skip to content

Commit

Permalink
On Vxworks clone std* file handles because they are thread specific
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk-zimoch committed Aug 21, 2023
1 parent 00dc55b commit 8dc6b3e
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions modules/libcom/src/error/errlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ static struct {
epicsMutexId msgQueueLock;

/* guarded by msgQueueLock */
int atExit;
int sevToLog;
int toConsole;
int ttyConsole;
int atExit:1;
int toConsole:1;
int ttyConsole:1;
int closeConsole:1;
FILE *console;

/* A loop counter maintained by errlogThread. */
Expand Down Expand Up @@ -466,7 +467,7 @@ int eltc(int yesno)
{
errlogInit(0);
epicsMutexMustLock(pvt.msgQueueLock);
pvt.toConsole = yesno;
pvt.toConsole = yesno ? 1 : 0;
epicsMutexUnlock(pvt.msgQueueLock);
errlogFlush();
return 0;
Expand All @@ -476,8 +477,22 @@ int errlogSetConsole(FILE *stream)
{
errlogInit(0);
epicsMutexMustLock(pvt.msgQueueLock);
if (pvt.closeConsole) {
fclose(pvt.console);
}
pvt.console = stream ? stream : stderr;
pvt.ttyConsole = isATTY(pvt.console);
#ifdef vxWorks
/* The stderr/stdout we get may become invalid as they are thread specific.
* Also, the FDs are actually maps to some "real" FDs.
* Thus, we clone the pvt.console and link it with a dup of the "real" FD.
* The dup'ed FD will be closed when the FILE handle is fclosed. */
if (fileno(pvt.console) <= 2) {
pvt.console = fdopen(dup(ioTaskStdGet(0, fileno(pvt.console))),"w");
pvt.closeConsole = 1;
} else
pvt.closeConsole = 0;
#endif
epicsMutexUnlock(pvt.msgQueueLock);
/* make sure worker has stopped writing to the previous stream */
errlogSequence();
Expand Down Expand Up @@ -551,7 +566,13 @@ static void errlogInitPvt(void *arg)
pvt.maxMsgSize = pconfig->maxMsgSize;
ellInit(&pvt.listenerList);
pvt.toConsole = TRUE;
#ifdef vxWorks
pvt.console = fdopen(dup(ioTaskStdGet(0, 2)),"w");
pvt.closeConsole = 1;
#else
pvt.console = stderr;
pvt.closeConsole = 0;
#endif
pvt.ttyConsole = isATTY(stderr);
pvt.waitForWork = epicsEventCreate(epicsEventEmpty);
pvt.listenerLock = epicsMutexCreate();
Expand Down

0 comments on commit 8dc6b3e

Please sign in to comment.