From b9443f8813e29a764b517e1f5f329ae952c9cd07 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Fri, 23 Mar 2018 11:39:53 -0500 Subject: [PATCH 01/20] Tell MSVC to use absolute filenames in diagnostics (-FC flag) --- configure/os/CONFIG.win32-x86.win32-x86 | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/configure/os/CONFIG.win32-x86.win32-x86 b/configure/os/CONFIG.win32-x86.win32-x86 index f5b21cc2e..54a0ec954 100644 --- a/configure/os/CONFIG.win32-x86.win32-x86 +++ b/configure/os/CONFIG.win32-x86.win32-x86 @@ -85,16 +85,20 @@ CPP = cl -nologo -C -E # Configure OS vendor C++ compiler # -# __STDC__=0 gives us both: -# 1) define STDC for code (pretend ANSI conformance) -# 2) set it to 0 to use MS C "extensions" (open for _open etc.) -# because MS uses: if __STDC__ ... disable many nice things -# # -EHsc - generate code for exceptions # -GR - generate code for run time type identification # CCC = cl -EHsc -GR -CODE_CPPFLAGS += -nologo -D__STDC__=0 + +# Other compiler flags, used for CPP, C and C++ +# +# -FC - Show absolute path of source file in diagnostics +# -D__STDC__=0 gives us both: +# 1) define STDC for code (pretend ANSI conformance) +# 2) set it to 0 to use MS C "extensions" (open for _open etc.) +# because MS uses: if __STDC__ ... disable many nice things +# +CODE_CPPFLAGS += -nologo -FC -D__STDC__=0 CODE_CPPFLAGS += -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE From 3f3696fb91e31ca654b1b472190297a8451364ae Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 3 May 2018 14:28:44 -0500 Subject: [PATCH 02/20] dbStatic: Prevent modifying a NAME field using a DB file Fixes LP: #1597809 --- src/dbStatic/dbLexRoutines.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/dbStatic/dbLexRoutines.c b/src/dbStatic/dbLexRoutines.c index db95cc61f..87bb7295f 100644 --- a/src/dbStatic/dbLexRoutines.c +++ b/src/dbStatic/dbLexRoutines.c @@ -974,6 +974,12 @@ static void dbRecordField(char *name,char *value) yyerror(NULL); return; } + if (pdbentry->indfield == 0) { + epicsPrintf("Can't set \"NAME\" field of record \"%s\"\n", + dbGetRecordName(pdbentry)); + yyerror(NULL); + return; + } dbTranslateEscape(value, value); /* yuck: in-place, but safe */ status = dbPutString(pdbentry,value); if(status) { From 116c90c2ea1e3e542ee5d0d42349a64b1f4097b1 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 3 May 2018 14:40:12 -0500 Subject: [PATCH 03/20] Reformatting, no code changes --- src/dbStatic/dbLexRoutines.c | 67 ++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/src/dbStatic/dbLexRoutines.c b/src/dbStatic/dbLexRoutines.c index 87bb7295f..91437b342 100644 --- a/src/dbStatic/dbLexRoutines.c +++ b/src/dbStatic/dbLexRoutines.c @@ -960,29 +960,29 @@ static void dbRecordHead(char *recordType, char *name, int visible) static void dbRecordField(char *name,char *value) { - DBENTRY *pdbentry; - tempListNode *ptempListNode; - long status; + DBENTRY *pdbentry; + tempListNode *ptempListNode; + long status; - if(duplicate) return; + if (duplicate) return; ptempListNode = (tempListNode *)ellFirst(&tempList); pdbentry = ptempListNode->item; status = dbFindField(pdbentry,name); - if(status) { - epicsPrintf("Record \"%s\" does not have a field \"%s\"\n", - dbGetRecordName(pdbentry), name); - yyerror(NULL); - return; + if (status) { + epicsPrintf("Record \"%s\" does not have a field \"%s\"\n", + dbGetRecordName(pdbentry), name); + yyerror(NULL); + return; } if (pdbentry->indfield == 0) { epicsPrintf("Can't set \"NAME\" field of record \"%s\"\n", - dbGetRecordName(pdbentry)); + dbGetRecordName(pdbentry)); yyerror(NULL); return; } dbTranslateEscape(value, value); /* yuck: in-place, but safe */ status = dbPutString(pdbentry,value); - if(status) { + if (status) { epicsPrintf("Can't set \"%s.%s\" to \"%s\"\n", dbGetRecordName(pdbentry), name, value); yyerror(NULL); @@ -992,33 +992,33 @@ static void dbRecordField(char *name,char *value) static void dbRecordInfo(char *name, char *value) { - DBENTRY *pdbentry; - tempListNode *ptempListNode; - long status; + DBENTRY *pdbentry; + tempListNode *ptempListNode; + long status; - if(duplicate) return; + if (duplicate) return; ptempListNode = (tempListNode *)ellFirst(&tempList); pdbentry = ptempListNode->item; status = dbPutInfo(pdbentry,name,value); - if(status) { - epicsPrintf("Can't set \"%s\" info \"%s\" to \"%s\"\n", + if (status) { + epicsPrintf("Can't set \"%s\" info \"%s\" to \"%s\"\n", dbGetRecordName(pdbentry), name, value); - yyerror(NULL); - return; + yyerror(NULL); + return; } } static void dbRecordAlias(char *name) { - DBENTRY *pdbentry; - tempListNode *ptempListNode; - long status; + DBENTRY *pdbentry; + tempListNode *ptempListNode; + long status; - if(duplicate) return; + if (duplicate) return; ptempListNode = (tempListNode *)ellFirst(&tempList); pdbentry = ptempListNode->item; status = dbCreateAlias(pdbentry, name); - if(status) { + if (status) { epicsPrintf("Can't create alias \"%s\" for \"%s\"\n", name, dbGetRecordName(pdbentry)); yyerror(NULL); @@ -1028,15 +1028,16 @@ static void dbRecordAlias(char *name) static void dbAlias(char *name, char *alias) { - DBENTRY dbEntry; - DBENTRY *pdbEntry = &dbEntry; + DBENTRY dbEntry; + DBENTRY *pdbEntry = &dbEntry; dbInitEntry(pdbbase, pdbEntry); if (dbFindRecord(pdbEntry, name)) { epicsPrintf("Alias \"%s\" refers to unknown record \"%s\"\n", alias, name); yyerror(NULL); - } else if (dbCreateAlias(pdbEntry, alias)) { + } + else if (dbCreateAlias(pdbEntry, alias)) { epicsPrintf("Can't create alias \"%s\" referring to \"%s\"\n", alias, name); yyerror(NULL); @@ -1046,14 +1047,14 @@ static void dbAlias(char *name, char *alias) static void dbRecordBody(void) { - DBENTRY *pdbentry; + DBENTRY *pdbentry; - if(duplicate) { - duplicate = FALSE; - return; + if (duplicate) { + duplicate = FALSE; + return; } pdbentry = (DBENTRY *)popFirstTemp(); - if(ellCount(&tempList)) - yyerrorAbort("dbRecordBody: tempList not empty"); + if (ellCount(&tempList)) + yyerrorAbort("dbRecordBody: tempList not empty"); dbFreeEntry(pdbentry); } From cbd46342246c670260e3a9faeaa8491e7e73b17f Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Fri, 14 Sep 2018 12:00:47 +0200 Subject: [PATCH 04/20] install header needed by iocStats --- src/db/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/src/db/Makefile b/src/db/Makefile index 0ebdffdb6..abfb56675 100644 --- a/src/db/Makefile +++ b/src/db/Makefile @@ -33,6 +33,7 @@ INC += dbIocRegister.h # The following go away what old database access goes away INC += db_access_routines.h INC += db_convert.h +INC += dbCaPvt.h DBDINC += menuAlarmSevr DBDINC += menuAlarmStat From f65c39c0d29f964779c95864a81e093be54a5167 Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Fri, 14 Sep 2018 15:23:13 +0200 Subject: [PATCH 05/20] backport dbQuietMacroWarnings --- src/dbStatic/dbLexRoutines.c | 4 ++++ src/misc/base.dbd | 1 + 2 files changed, 5 insertions(+) diff --git a/src/dbStatic/dbLexRoutines.c b/src/dbStatic/dbLexRoutines.c index 91437b342..87a286b2c 100644 --- a/src/dbStatic/dbLexRoutines.c +++ b/src/dbStatic/dbLexRoutines.c @@ -47,6 +47,9 @@ epicsExportAddress(int,dbRecordsOnceOnly); epicsShareDef int dbBptNotMonotonic=0; epicsExportAddress(int,dbBptNotMonotonic); +epicsShareDef int dbQuietMacroWarnings=0; +epicsExportAddress(int,dbQuietMacroWarnings); + /*private routines */ static void yyerrorAbort(char *str); static void allocTemp(void *pvoid); @@ -227,6 +230,7 @@ static long dbReadCOM(DBBASE **ppdbbase,const char *filename, FILE *fp, free((void *)macPairs); mac_input_buffer = dbCalloc(MY_BUFFER_SIZE,sizeof(char)); } + macSuppressWarning(macHandle,dbQuietMacroWarnings); } pinputFile = dbCalloc(1,sizeof(inputFile)); if (filename) { diff --git a/src/misc/base.dbd b/src/misc/base.dbd index 7cecf8c7a..780dad129 100644 --- a/src/misc/base.dbd +++ b/src/misc/base.dbd @@ -49,6 +49,7 @@ variable(CASDEBUG,int) # dbStaticLib settings variable(dbRecordsOnceOnly,int) variable(dbBptNotMonotonic,int) +variable(dbQuietMacroWarnings,int) # dbLoadTemplate settings variable(dbTemplateMaxVars,int) From 8a53c494ffaa757900637abbcf04b55f32689730 Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Thu, 9 May 2019 16:25:02 +0200 Subject: [PATCH 06/20] Don't build with clang for SL6 any more --- configure/os/CONFIG_SITE.SL6-x86_64.Common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure/os/CONFIG_SITE.SL6-x86_64.Common b/configure/os/CONFIG_SITE.SL6-x86_64.Common index 9d8cb9f96..7aa041e73 100644 --- a/configure/os/CONFIG_SITE.SL6-x86_64.Common +++ b/configure/os/CONFIG_SITE.SL6-x86_64.Common @@ -2,6 +2,6 @@ CROSS_COMPILER_TARGET_ARCHS += SL6-x86 # Improved error checking with clang -CROSS_COMPILER_TARGET_ARCHS += SL6-x86_64-clang +#CROSS_COMPILER_TARGET_ARCHS += SL6-x86_64-clang include $(CONFIG)/os/CONFIG_SITE.linux-x86_64.Common From 962bf4d2dd316c0d14192242def78c49f29bfe84 Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Thu, 9 May 2019 16:25:23 +0200 Subject: [PATCH 07/20] added newer eldk53-ppc4xxFP (DeltaTau) --- configure/os/CONFIG.Common.eldk53-ppc4xxFP | 23 ++++++++++++++++++++++ configure/os/CONFIG_SITE.linux-x86.Common | 2 ++ 2 files changed, 25 insertions(+) create mode 100644 configure/os/CONFIG.Common.eldk53-ppc4xxFP diff --git a/configure/os/CONFIG.Common.eldk53-ppc4xxFP b/configure/os/CONFIG.Common.eldk53-ppc4xxFP new file mode 100644 index 000000000..e8454cf91 --- /dev/null +++ b/configure/os/CONFIG.Common.eldk53-ppc4xxFP @@ -0,0 +1,23 @@ +# DeltaTau PowerPMAC with ELDK 5.3 + +# Include definitions common to all Linux targets +include $(CONFIG)/os/CONFIG.Common.linuxCommon + +COMMANDLINE_LIBRARY = READLINE + +ARCH_CLASS = ppc + +SDK = eldk +SDK_DIR = /opt/eldk-5.3 +SDK_HOST_ARCH = $(GNU_HOST_ARCH)-$(SDK)-$(GNU_HOST_OS) +GNU_ARCH = ppc440e-linux +SDKTARGETSYSROOT=$(SDK_DIR)/powerpc-4xx/sysroots +GNU_DIR = $(SDKTARGETSYSROOT)/$(SDK_HOST_ARCH)/usr +GNU_BIN = $(GNU_DIR)/bin/$(GNU_ARCH) +GNU_TARGET_INCLUDE_DIR = +GNU_TARGET=powerpc-linux + +ARCH_DEP_CPPFLAGS = -m32 -mcpu=440fp -mhard-float +ARCH_DEP_CPPFLAGS += --sysroot=$(SDKTARGETSYSROOT)/$(GNU_ARCH) +ARCH_DEP_LDFLAGS = --sysroot=$(SDKTARGETSYSROOT)/$(GNU_ARCH) +AS=$(GNU_BIN)/$(GNU_TARGET)-as diff --git a/configure/os/CONFIG_SITE.linux-x86.Common b/configure/os/CONFIG_SITE.linux-x86.Common index fb3b6213d..4baf36444 100644 --- a/configure/os/CONFIG_SITE.linux-x86.Common +++ b/configure/os/CONFIG_SITE.linux-x86.Common @@ -10,6 +10,7 @@ GNU_HOST_ARCH=i686 GNU_HOST_OS=linux +LD_LIBRARY_PATH= # vxWorks 5 for MVxxxx boards CROSS_COMPILER_TARGET_ARCHS += T2-ppc604 @@ -34,6 +35,7 @@ CROSS_COMPILER_TARGET_ARCHS += eldk52-e500v2 # DeltaTau PowerPMAC CROSS_COMPILER_TARGET_ARCHS += eldk42-ppc4xxFP +CROSS_COMPILER_TARGET_ARCHS += eldk53-ppc4xxFP # Test other vxWorks versions CROSS_COMPILER_TARGET_ARCHS += V66-ppc603 From 8b5225c14faaa5c465d252bb3a0ec2c45d2562cf Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Thu, 9 May 2019 16:31:51 +0200 Subject: [PATCH 08/20] merged with origin/PSI-3.14 --- configure/os/CONFIG.Common.SL6-x86 | 1 - configure/os/CONFIG.Common.SL6-x86_64 | 2 -- configure/os/CONFIG.Common.eldk42-ppc4xxFP | 2 -- configure/os/CONFIG.Common.linuxCommon | 2 ++ configure/os/CONFIG.Common.moxa42-armv6l | 1 - configure/os/CONFIG.Common.mvl40-xscale_be | 1 - 6 files changed, 2 insertions(+), 7 deletions(-) diff --git a/configure/os/CONFIG.Common.SL6-x86 b/configure/os/CONFIG.Common.SL6-x86 index fafe11534..e5d9c2804 100644 --- a/configure/os/CONFIG.Common.SL6-x86 +++ b/configure/os/CONFIG.Common.SL6-x86 @@ -4,4 +4,3 @@ include $(CONFIG)/os/CONFIG.Common.linux-x86 COMMANDLINE_LIBRARY = READLINE ARCH_DEP_CFLAGS += -march=i686 -ARCH_DEP_CXXFLAGS += -fno-strict-aliasing diff --git a/configure/os/CONFIG.Common.SL6-x86_64 b/configure/os/CONFIG.Common.SL6-x86_64 index c80ad3be3..083caea5f 100644 --- a/configure/os/CONFIG.Common.SL6-x86_64 +++ b/configure/os/CONFIG.Common.SL6-x86_64 @@ -2,5 +2,3 @@ include $(CONFIG)/os/CONFIG.Common.linux-x86_64 COMMANDLINE_LIBRARY = READLINE - -ARCH_DEP_CXXFLAGS += -fno-strict-aliasing diff --git a/configure/os/CONFIG.Common.eldk42-ppc4xxFP b/configure/os/CONFIG.Common.eldk42-ppc4xxFP index 77b2375d9..001b9df7a 100644 --- a/configure/os/CONFIG.Common.eldk42-ppc4xxFP +++ b/configure/os/CONFIG.Common.eldk42-ppc4xxFP @@ -11,8 +11,6 @@ ELDK=/opt/eldk-4.2 GNU_TARGET=ppc_4xxFP GNU_DIR=$(ELDK)/usr -ARCH_DEP_CFLAGS += -fno-strict-aliasing - # This cross tool chain is installed in a somehow weired way # Without the following lines it does not work on RHEL7 # but it worked on SL6 diff --git a/configure/os/CONFIG.Common.linuxCommon b/configure/os/CONFIG.Common.linuxCommon index 348d1b476..84db5c7ac 100644 --- a/configure/os/CONFIG.Common.linuxCommon +++ b/configure/os/CONFIG.Common.linuxCommon @@ -42,3 +42,5 @@ LDLIBS_READLINE_CURSES = -lreadline -lcurses # Allow site overrides -include $(CONFIG)/os/CONFIG_SITE.Common.linuxCommon -include $(CONFIG)/os/CONFIG_SITE.$(EPICS_HOST_ARCH).linuxCommon + +CODE_CPPFLAGS += -fno-strict-aliasing diff --git a/configure/os/CONFIG.Common.moxa42-armv6l b/configure/os/CONFIG.Common.moxa42-armv6l index 130c850b5..eecdcc7c1 100644 --- a/configure/os/CONFIG.Common.moxa42-armv6l +++ b/configure/os/CONFIG.Common.moxa42-armv6l @@ -14,4 +14,3 @@ COMMANDLINE_LIBRARY = READLINE_NCURSES ARCH_DEP_CXXFLAGS += -Wno-psabi ARCH_DEP_CFLAGS += -funwind-tables -ARCH_DEP_CXXFLAGS += -fno-strict-aliasing diff --git a/configure/os/CONFIG.Common.mvl40-xscale_be b/configure/os/CONFIG.Common.mvl40-xscale_be index 9d2b75655..3606ab4cf 100644 --- a/configure/os/CONFIG.Common.mvl40-xscale_be +++ b/configure/os/CONFIG.Common.mvl40-xscale_be @@ -10,4 +10,3 @@ ARCH_CLASS = xscale GNU_DIR=/afs/psi.ch/project/embeddedlinux/moxa/xscale_be/armv5teb-montavista-linuxeabi ARCH_DEP_CFLAGS += -funwind-tables -ARCH_DEP_CPPFLAGS += -fno-strict-aliasing From d0e83116e6cd669149dffe09a1d80e8288fb7a9f Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Mon, 2 Sep 2019 09:38:28 +0200 Subject: [PATCH 09/20] merge logClient changes from 7.0.3 --- src/libCom/logClient/iocLog.c | 14 ----- src/libCom/logClient/logClient.c | 90 +++++++++++++++++++++++++++----- src/libCom/logClient/logClient.h | 1 + 3 files changed, 78 insertions(+), 27 deletions(-) diff --git a/src/libCom/logClient/iocLog.c b/src/libCom/logClient/iocLog.c index c6c707c30..e62da2050 100644 --- a/src/libCom/logClient/iocLog.c +++ b/src/libCom/logClient/iocLog.c @@ -18,7 +18,6 @@ #define epicsExportSharedSymbols #include "envDefs.h" -#include "errlog.h" #include "logClient.h" #include "iocLog.h" @@ -90,9 +89,6 @@ static logClientId iocLogClientInit (void) return NULL; } id = logClientCreate (addr, port); - if (id != NULL) { - errlogAddListener ( logClientSendMessage, id ); - } return id; } @@ -139,13 +135,3 @@ logClientId epicsShareAPI logClientInit (void) { return iocLogClientInit (); } - -/* - * logClientSendMessage (); deprecated - */ -void logClientSendMessage ( logClientId id, const char * message ) -{ - if ( !iocLogDisable ) { - logClientSend (id, message); - } -} diff --git a/src/libCom/logClient/logClient.c b/src/libCom/logClient/logClient.c index 4f5daaab1..99ee671d9 100644 --- a/src/libCom/logClient/logClient.c +++ b/src/libCom/logClient/logClient.c @@ -24,6 +24,8 @@ #define epicsExportSharedSymbols #include "dbDefs.h" #include "epicsEvent.h" +#include "iocLog.h" +#include "errlog.h" #include "epicsMutex.h" #include "epicsThread.h" #include "epicsTime.h" @@ -54,6 +56,11 @@ static const double LOG_RESTART_DELAY = 5.0; /* sec */ static const double LOG_SERVER_CREATE_CONNECT_SYNC_TIMEOUT = 5.0; /* sec */ static const double LOG_SERVER_SHUTDOWN_TIMEOUT = 30.0; /* sec */ +/* + * If set using iocLogPrefix() this string is prepended to all log messages: + */ +static char* logClientPrefix = NULL; + /* * logClientClose () */ @@ -147,6 +154,8 @@ static void logClientDestroy (logClientId id) return; } + errlogRemoveListeners ( logClientSendMessage, (void *) pClient ); + logClientClose ( pClient ); epicsMutexDestroy ( pClient->mutex ); @@ -156,22 +165,13 @@ static void logClientDestroy (logClientId id) free ( pClient ); } -/* - * logClientSend () +/* + * This method requires the pClient->mutex be owned already. */ -void epicsShareAPI logClientSend ( logClientId id, const char * message ) -{ - logClient * pClient = ( logClient * ) id; +static void sendMessageChunk(logClient * pClient, const char * message) { unsigned strSize; - if ( ! pClient || ! message ) { - return; - } - strSize = strlen ( message ); - - epicsMutexMustLock ( pClient->mutex ); - while ( strSize ) { unsigned msgBufBytesLeft = sizeof ( pClient->msgBuf ) - pClient->nextMsgIndex; @@ -228,10 +228,31 @@ void epicsShareAPI logClientSend ( logClientId id, const char * message ) break; } } - +} + + +/* + * logClientSend () + */ +void epicsShareAPI logClientSend ( logClientId id, const char * message ) +{ + logClient * pClient = ( logClient * ) id; + + if ( ! pClient || ! message ) { + return; + } + + epicsMutexMustLock ( pClient->mutex ); + + if (logClientPrefix) { + sendMessageChunk(pClient, logClientPrefix); + } + sendMessageChunk(pClient, message); + epicsMutexUnlock (pClient->mutex); } + void epicsShareAPI logClientFlush ( logClientId id ) { logClient * pClient = ( logClient * ) id; @@ -528,6 +549,8 @@ logClientId epicsShareAPI logClientCreate ( pClient->name, LOG_SERVER_CREATE_CONNECT_SYNC_TIMEOUT ); } + errlogAddListener ( logClientSendMessage, (void *) pClient ); + return (void *) pClient; } @@ -550,5 +573,46 @@ void epicsShareAPI logClientShow (logClientId id, unsigned level) pClient->sock==INVALID_SOCKET?"INVALID":"OK", pClient->connectCount); } + + if (logClientPrefix) { + printf ("log client: prefix is \"%s\"\n", logClientPrefix); + } } +/* + * logClientSendMessage (); deprecated + */ +void logClientSendMessage ( logClientId id, const char * message ) +{ + if ( !iocLogDisable ) { + logClientSend (id, message); + } +} + +/* + * iocLogPrefix() + */ +void epicsShareAPI iocLogPrefix(const char * prefix) +{ + + /* If we have already established a log prefix, don't let the user change + * it. The iocLogPrefix command is expected to be run from the IOC startup + * script during initialization; the prefix can't be changed once it has + * been set. + */ + + if (logClientPrefix) { + printf ("iocLogPrefix: The prefix was already set to \"%s\" " + "and can't be changed.\n", logClientPrefix); + return; + } + + if (prefix) { + unsigned prefixLen = strlen(prefix); + if (prefixLen > 0) { + char * localCopy = malloc(prefixLen+1); + strcpy(localCopy, prefix); + logClientPrefix = localCopy; + } + } +} diff --git a/src/libCom/logClient/logClient.h b/src/libCom/logClient/logClient.h index 8f1ec09d5..1797bbb20 100644 --- a/src/libCom/logClient/logClient.h +++ b/src/libCom/logClient/logClient.h @@ -33,6 +33,7 @@ epicsShareFunc logClientId epicsShareAPI logClientCreate ( epicsShareFunc void epicsShareAPI logClientSend (logClientId id, const char *message); epicsShareFunc void epicsShareAPI logClientShow (logClientId id, unsigned level); epicsShareFunc void epicsShareAPI logClientFlush (logClientId id); +epicsShareFunc void epicsShareAPI iocLogPrefix(const char* prefix); /* deprecated interface; retained for backward compatibility */ /* note: implementations are in iocLog.c, not logClient.c */ From 12af6fa23104800bd4c6a6254e7ba4bb148553e3 Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Mon, 2 Sep 2019 10:56:50 +0200 Subject: [PATCH 10/20] Use perl instead of date for EPICS_SITE_VERSION because of Windows --- configure/CONFIG_SITE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure/CONFIG_SITE b/configure/CONFIG_SITE index a3749bc06..d3bf9128d 100644 --- a/configure/CONFIG_SITE +++ b/configure/CONFIG_SITE @@ -191,7 +191,7 @@ USE_POSIX_THREAD_PRIORITY_SCHEDULING = YES # Site version number, if set will append '-' and this string to the # EPICS version number string that is reported by many tools -EPICS_SITE_VERSION := $(shell date +%Y-%m) +EPICS_SITE_VERSION=$(shell $(PERL) -MPOSIX -e 'print strftime "%Y-%m-%d $(shell git describe --tags --dirty)", localtime') # For GNU compiler, use pipes rather than temporary files for communication # between the various stages of compilation. From 2e2b7be9bdef430719abbfd1ac83bd27a3ea611d Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Mon, 2 Sep 2019 11:10:44 +0200 Subject: [PATCH 11/20] make sure softIoc for vxWorks contains all functions --- src/softIoc/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/softIoc/Makefile b/src/softIoc/Makefile index 0ddf54187..63d5f5b8a 100644 --- a/src/softIoc/Makefile +++ b/src/softIoc/Makefile @@ -12,6 +12,8 @@ include $(TOP)/configure/CONFIG PROD_IOC_DEFAULT = softIoc PROD_IOC_iOS = -nil- +PROD_LDFLAGS_vxWorks = --whole-archive + DBD += softIoc.dbd softIoc_DBD += base.dbd softIoc_DBD += dlload.dbd From 7c5c03edb0550f5a422dd67354b9923ee7799313 Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Mon, 2 Sep 2019 11:38:28 +0200 Subject: [PATCH 12/20] Use READLINE as default for all Linux targets --- configure/os/CONFIG.Common.RHEL7-x86_64 | 2 -- configure/os/CONFIG.Common.RHEL7-x86_64-clang | 2 -- configure/os/CONFIG.Common.SL6-x86 | 2 -- configure/os/CONFIG.Common.SL6-x86_64 | 2 -- configure/os/CONFIG.Common.SL6-x86_64-clang | 2 -- configure/os/CONFIG.Common.eldk51-ppc4xxSF | 2 -- configure/os/CONFIG.Common.eldk52-e500v2 | 2 -- configure/os/CONFIG.Common.eldk53-ppc4xxFP | 2 -- configure/os/CONFIG.Common.fslqoriq20-e6500_64 | 2 -- configure/os/CONFIG.Common.raspbian-arm | 4 +--- configure/os/CONFIG.Common.yocto21-aarch64 | 2 -- configure/os/CONFIG_SITE.Common.linuxCommon | 1 + 12 files changed, 2 insertions(+), 23 deletions(-) create mode 100644 configure/os/CONFIG_SITE.Common.linuxCommon diff --git a/configure/os/CONFIG.Common.RHEL7-x86_64 b/configure/os/CONFIG.Common.RHEL7-x86_64 index 083caea5f..757bcb323 100644 --- a/configure/os/CONFIG.Common.RHEL7-x86_64 +++ b/configure/os/CONFIG.Common.RHEL7-x86_64 @@ -1,4 +1,2 @@ # Include definitions common to linux pentium targets include $(CONFIG)/os/CONFIG.Common.linux-x86_64 - -COMMANDLINE_LIBRARY = READLINE diff --git a/configure/os/CONFIG.Common.RHEL7-x86_64-clang b/configure/os/CONFIG.Common.RHEL7-x86_64-clang index 57f57aa53..fa50b4f9c 100644 --- a/configure/os/CONFIG.Common.RHEL7-x86_64-clang +++ b/configure/os/CONFIG.Common.RHEL7-x86_64-clang @@ -1,3 +1 @@ include $(CONFIG)/os/CONFIG.Common.linux-clang - -COMMANDLINE_LIBRARY = READLINE diff --git a/configure/os/CONFIG.Common.SL6-x86 b/configure/os/CONFIG.Common.SL6-x86 index e5d9c2804..434c55396 100644 --- a/configure/os/CONFIG.Common.SL6-x86 +++ b/configure/os/CONFIG.Common.SL6-x86 @@ -1,6 +1,4 @@ # Include definitions common to linux pentium targets include $(CONFIG)/os/CONFIG.Common.linux-x86 -COMMANDLINE_LIBRARY = READLINE - ARCH_DEP_CFLAGS += -march=i686 diff --git a/configure/os/CONFIG.Common.SL6-x86_64 b/configure/os/CONFIG.Common.SL6-x86_64 index 083caea5f..757bcb323 100644 --- a/configure/os/CONFIG.Common.SL6-x86_64 +++ b/configure/os/CONFIG.Common.SL6-x86_64 @@ -1,4 +1,2 @@ # Include definitions common to linux pentium targets include $(CONFIG)/os/CONFIG.Common.linux-x86_64 - -COMMANDLINE_LIBRARY = READLINE diff --git a/configure/os/CONFIG.Common.SL6-x86_64-clang b/configure/os/CONFIG.Common.SL6-x86_64-clang index 57f57aa53..fa50b4f9c 100644 --- a/configure/os/CONFIG.Common.SL6-x86_64-clang +++ b/configure/os/CONFIG.Common.SL6-x86_64-clang @@ -1,3 +1 @@ include $(CONFIG)/os/CONFIG.Common.linux-clang - -COMMANDLINE_LIBRARY = READLINE diff --git a/configure/os/CONFIG.Common.eldk51-ppc4xxSF b/configure/os/CONFIG.Common.eldk51-ppc4xxSF index 276e5b99e..48b3e7e3b 100644 --- a/configure/os/CONFIG.Common.eldk51-ppc4xxSF +++ b/configure/os/CONFIG.Common.eldk51-ppc4xxSF @@ -3,8 +3,6 @@ # Include definitions common to all Linux targets include $(CONFIG)/os/CONFIG.Common.linuxCommon -COMMANDLINE_LIBRARY = READLINE - ARCH_CLASS = ppc SDK = eldk diff --git a/configure/os/CONFIG.Common.eldk52-e500v2 b/configure/os/CONFIG.Common.eldk52-e500v2 index fc6e21e9e..ff1d5ffd6 100644 --- a/configure/os/CONFIG.Common.eldk52-e500v2 +++ b/configure/os/CONFIG.Common.eldk52-e500v2 @@ -3,8 +3,6 @@ # Include definitions common to all Linux targets include $(CONFIG)/os/CONFIG.Common.linuxCommon -COMMANDLINE_LIBRARY = READLINE - ARCH_CLASS = ppc SDK = eldk diff --git a/configure/os/CONFIG.Common.eldk53-ppc4xxFP b/configure/os/CONFIG.Common.eldk53-ppc4xxFP index e8454cf91..554b9d918 100644 --- a/configure/os/CONFIG.Common.eldk53-ppc4xxFP +++ b/configure/os/CONFIG.Common.eldk53-ppc4xxFP @@ -3,8 +3,6 @@ # Include definitions common to all Linux targets include $(CONFIG)/os/CONFIG.Common.linuxCommon -COMMANDLINE_LIBRARY = READLINE - ARCH_CLASS = ppc SDK = eldk diff --git a/configure/os/CONFIG.Common.fslqoriq20-e6500_64 b/configure/os/CONFIG.Common.fslqoriq20-e6500_64 index ba173bbd9..1e3ba7e61 100644 --- a/configure/os/CONFIG.Common.fslqoriq20-e6500_64 +++ b/configure/os/CONFIG.Common.fslqoriq20-e6500_64 @@ -3,8 +3,6 @@ # Include definitions common to all Linux targets include $(CONFIG)/os/CONFIG.Common.linuxCommon -COMMANDLINE_LIBRARY = READLINE - ARCH_CLASS = ppc SDK = fslsdk diff --git a/configure/os/CONFIG.Common.raspbian-arm b/configure/os/CONFIG.Common.raspbian-arm index c2f6ca3c4..6c69dcfe7 100644 --- a/configure/os/CONFIG.Common.raspbian-arm +++ b/configure/os/CONFIG.Common.raspbian-arm @@ -8,7 +8,7 @@ include $(CONFIG)/os/CONFIG.Common.linuxCommon # Using readline: # Due to missing/messed up libs in the toolchain, readline needs copies of -# libtinfo.so.5.9 and libreadline.so.6.2 from a Raspbian 7 rootfs +# libtinfo.so.5.9 and libreadline.so.6.2 from a Raspbian 7 rootfs # /lib/arm-linux-gnueabihf/ to the toolchain, e.g. # $(SDK_DIR)/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/libc/lib/arm-linux-gnueabihf/ # and manually created links libtinfo.so.5 and libreadline.so. @@ -18,8 +18,6 @@ include $(CONFIG)/os/CONFIG.Common.linuxCommon # Also copy /usr/include/readline/ directory from some readline 6 installation # to $(SDK_DIR)/gcc-linaro-arm-linux-gnueabihf-raspbian/arm-linux-gnueabihf/libc/usr/include/ -COMMANDLINE_LIBRARY = READLINE - ARCH_CLASS = arm SDK_DIR = /opt/raspberrypi/arm-bcm2708 diff --git a/configure/os/CONFIG.Common.yocto21-aarch64 b/configure/os/CONFIG.Common.yocto21-aarch64 index 417e11a4c..7a06651ef 100644 --- a/configure/os/CONFIG.Common.yocto21-aarch64 +++ b/configure/os/CONFIG.Common.yocto21-aarch64 @@ -3,8 +3,6 @@ # Include definitions common to all Linux targets include $(CONFIG)/os/CONFIG.Common.linuxCommon -COMMANDLINE_LIBRARY = READLINE - ARCH_CLASS = arm64 SDK = petalinux diff --git a/configure/os/CONFIG_SITE.Common.linuxCommon b/configure/os/CONFIG_SITE.Common.linuxCommon new file mode 100644 index 000000000..30cfd903b --- /dev/null +++ b/configure/os/CONFIG_SITE.Common.linuxCommon @@ -0,0 +1 @@ +COMMANDLINE_LIBRARY = READLINE From 9a3f7e3c52335ffc8d05f7125c55e96d882e6885 Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Tue, 3 Sep 2019 09:23:52 +0200 Subject: [PATCH 13/20] : in version string gives problems with tar --- configure/CONFIG_SITE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure/CONFIG_SITE b/configure/CONFIG_SITE index d3bf9128d..12a8603af 100644 --- a/configure/CONFIG_SITE +++ b/configure/CONFIG_SITE @@ -191,7 +191,7 @@ USE_POSIX_THREAD_PRIORITY_SCHEDULING = YES # Site version number, if set will append '-' and this string to the # EPICS version number string that is reported by many tools -EPICS_SITE_VERSION=$(shell $(PERL) -MPOSIX -e 'print strftime "%Y-%m-%d $(shell git describe --tags --dirty)", localtime') +EPICS_SITE_VERSION=$(shell $(PERL) -MPOSIX -e 'print strftime "%Y-%m-%d_$(shell git describe --tags --dirty)", localtime') # For GNU compiler, use pipes rather than temporary files for communication # between the various stages of compilation. From 795e1a9368f7f93b7246087fa6ae2a08c55074ea Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Tue, 3 Sep 2019 09:24:03 +0200 Subject: [PATCH 14/20] don't rebuild befor making tar --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ea402a75d..bc54193a3 100644 --- a/Makefile +++ b/Makefile @@ -29,5 +29,5 @@ UNINSTALL_DIRS += $(INSTALL_LOCATION)/src copysrc: tar cf - --exclude=CVS --exclude=O.* src | tar xf - -C $(INSTALL_LOCATION) -tar: install copysrc - tar cfjP epics_base-3.14.12.tar.bz2 $(INSTALL_LOCATION) --exclude=*.o +tar: + tar cfjP epics_base-$(EPICS_VERSION_NUMBER).tar.bz2 $(INSTALL_LOCATION) --exclude=*.o From 172f1702302d02020aecc153bd3b9d8430212894 Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Tue, 3 Sep 2019 09:33:44 +0200 Subject: [PATCH 15/20] commit d0e831 was wrong --- src/libCom/logClient/iocLog.c | 14 +++ src/libCom/logClient/logClient.c | 179 +++++++++++-------------------- 2 files changed, 75 insertions(+), 118 deletions(-) diff --git a/src/libCom/logClient/iocLog.c b/src/libCom/logClient/iocLog.c index e62da2050..d835e3c2c 100644 --- a/src/libCom/logClient/iocLog.c +++ b/src/libCom/logClient/iocLog.c @@ -18,8 +18,10 @@ #define epicsExportSharedSymbols #include "envDefs.h" +#include "errlog.h" #include "logClient.h" #include "iocLog.h" +#include "epicsExit.h" int iocLogDisable = 0; @@ -74,6 +76,14 @@ void epicsShareAPI epicsShareAPI iocLogFlush (void) } } +/* + * logClientDestroy() + */ +static void iocLogClientDestroy (logClientId id) +{ + errlogRemoveListener (logClientSendMessage); +} + /* * iocLogClientInit() */ @@ -89,6 +99,10 @@ static logClientId iocLogClientInit (void) return NULL; } id = logClientCreate (addr, port); + if (id != NULL) { + errlogAddListener (logClientSendMessage, id); + epicsAtExit (iocLogClientDestroy, id); + } return id; } diff --git a/src/libCom/logClient/logClient.c b/src/libCom/logClient/logClient.c index 99ee671d9..0056a21fe 100644 --- a/src/libCom/logClient/logClient.c +++ b/src/libCom/logClient/logClient.c @@ -44,6 +44,7 @@ typedef struct { SOCKET sock; epicsThreadId restartThreadId; epicsEventId stateChangeNotify; + epicsEventId shutdownNotify; unsigned connectCount; unsigned nextMsgIndex; unsigned connected; @@ -53,7 +54,6 @@ typedef struct { } logClient; static const double LOG_RESTART_DELAY = 5.0; /* sec */ -static const double LOG_SERVER_CREATE_CONNECT_SYNC_TIMEOUT = 5.0; /* sec */ static const double LOG_SERVER_SHUTDOWN_TIMEOUT = 30.0; /* sec */ /* @@ -84,8 +84,6 @@ static void logClientClose ( logClient *pClient ) pClient->sock = INVALID_SOCKET; } - pClient->nextMsgIndex = 0u; - memset ( pClient->msgBuf, '\0', sizeof ( pClient->msgBuf ) ); pClient->connected = 0u; /* @@ -113,6 +111,7 @@ static void logClientDestroy (logClientId id) epicsMutexMustLock ( pClient->mutex ); pClient->shutdown = 1u; epicsMutexUnlock ( pClient->mutex ); + epicsEventSignal ( pClient->shutdownNotify ); /* unblock log client thread blocking in send() or connect() */ interruptInfo = @@ -154,13 +153,11 @@ static void logClientDestroy (logClientId id) return; } - errlogRemoveListeners ( logClientSendMessage, (void *) pClient ); - logClientClose ( pClient ); epicsMutexDestroy ( pClient->mutex ); - epicsEventDestroy ( pClient->stateChangeNotify ); + epicsEventDestroy ( pClient->shutdownNotify ); free ( pClient ); } @@ -176,57 +173,23 @@ static void sendMessageChunk(logClient * pClient, const char * message) { unsigned msgBufBytesLeft = sizeof ( pClient->msgBuf ) - pClient->nextMsgIndex; - if ( strSize > msgBufBytesLeft ) { - int status; - - if ( ! pClient->connected ) { - break; - } - - if ( msgBufBytesLeft > 0u ) { - memcpy ( & pClient->msgBuf[pClient->nextMsgIndex], - message, msgBufBytesLeft ); - pClient->nextMsgIndex += msgBufBytesLeft; - strSize -= msgBufBytesLeft; - message += msgBufBytesLeft; - } - - status = send ( pClient->sock, pClient->msgBuf, - pClient->nextMsgIndex, 0 ); - if ( status > 0 ) { - unsigned nSent = (unsigned) status; - if ( nSent < pClient->nextMsgIndex ) { - unsigned newNextMsgIndex = pClient->nextMsgIndex - nSent; - memmove ( pClient->msgBuf, & pClient->msgBuf[nSent], - newNextMsgIndex ); - pClient->nextMsgIndex = newNextMsgIndex; - } - else { - pClient->nextMsgIndex = 0u; - } - } - else { - if ( ! pClient->shutdown ) { - char sockErrBuf[64]; - if ( status ) { - epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) ); - } - else { - strcpy ( sockErrBuf, "server initiated disconnect" ); - } - fprintf ( stderr, "log client: lost contact with log server at \"%s\" because \"%s\"\n", - pClient->name, sockErrBuf ); - } - logClientClose ( pClient ); - break; - } + if ( msgBufBytesLeft < strSize && pClient->nextMsgIndex != 0u && pClient->connected) + { + /* buffer is full, thus flush it */ + logClientFlush ( pClient ); + msgBufBytesLeft = sizeof ( pClient->msgBuf ) - pClient->nextMsgIndex; } - else { - memcpy ( & pClient->msgBuf[pClient->nextMsgIndex], - message, strSize ); - pClient->nextMsgIndex += strSize; + if ( msgBufBytesLeft == 0u ) { + fprintf ( stderr, "log client: messages to \"%s\" are lost\n", + pClient->name ); break; } + if ( msgBufBytesLeft > strSize) msgBufBytesLeft = strSize; + memcpy ( & pClient->msgBuf[pClient->nextMsgIndex], + message, msgBufBytesLeft ); + pClient->nextMsgIndex += msgBufBytesLeft; + strSize -= msgBufBytesLeft; + message += msgBufBytesLeft; } } @@ -255,28 +218,38 @@ void epicsShareAPI logClientSend ( logClientId id, const char * message ) void epicsShareAPI logClientFlush ( logClientId id ) { + unsigned nSent = 0u; + logClient * pClient = ( logClient * ) id; - if ( ! pClient ) { + if ( ! pClient || ! pClient->connected ) { return; } epicsMutexMustLock ( pClient->mutex ); - while ( pClient->nextMsgIndex && pClient->connected ) { - int status = send ( pClient->sock, pClient->msgBuf, - pClient->nextMsgIndex, 0 ); + while (1) { + struct timeval timeout = { 0, 0 }; + fd_set set; + char buffer[256]; + + FD_ZERO ( &set ); + FD_SET ( pClient->sock, &set ); + if ( select ( pClient->sock + 1, &set, NULL, NULL, &timeout ) == 0) + break; + if ( recv ( pClient->sock, buffer, sizeof ( buffer ), 0 ) == 0 ) { + fprintf ( stderr, "log client: connection closed by server \"%s\"\n", + pClient->name ); + logClientClose ( pClient ); + break; + } + } + + while ( nSent < pClient->nextMsgIndex && pClient->connected ) { + int status = send ( pClient->sock, pClient->msgBuf + nSent, + pClient->nextMsgIndex - nSent, 0 ); if ( status > 0 ) { - unsigned nSent = (unsigned) status; - if ( nSent < pClient->nextMsgIndex ) { - unsigned newNextMsgIndex = pClient->nextMsgIndex - nSent; - memmove ( pClient->msgBuf, & pClient->msgBuf[nSent], - newNextMsgIndex ); - pClient->nextMsgIndex = newNextMsgIndex; - } - else { - pClient->nextMsgIndex = 0u; - } + nSent += (unsigned) status; } else { if ( ! pClient->shutdown ) { @@ -294,6 +267,11 @@ void epicsShareAPI logClientFlush ( logClientId id ) break; } } + pClient->nextMsgIndex -= nSent; + if ( nSent > 0 && pClient->nextMsgIndex > 0 ) { + memmove ( pClient->msgBuf, & pClient->msgBuf[nSent], + pClient->nextMsgIndex ); + } epicsMutexUnlock ( pClient->mutex ); } @@ -398,20 +376,6 @@ static void logClientConnect (logClient *pClient) fprintf (stderr, "log client: unable to enable keepalive option because \"%s\"\n", sockErrBuf); } - /* - * we don't need full-duplex (clients only write), so we shutdown - * the read end of our socket - */ - status = shutdown (pClient->sock, SHUT_RD); - if (status < 0) { - char sockErrBuf[64]; - epicsSocketConvertErrnoToString ( - sockErrBuf, sizeof ( sockErrBuf ) ); - fprintf (stderr, "%s:%d shutdown(%d,SHUT_RD) error was \"%s\"\n", - __FILE__, __LINE__, pClient->sock, sockErrBuf); - /* not fatal (although it shouldn't happen) */ - } - /* * set how long we will wait for the TCP state machine * to clean up when we issue a close(). This @@ -457,14 +421,10 @@ static void logClientRestart ( logClientId id ) epicsMutexUnlock ( pClient->mutex ); - if ( isConn ) { - logClientFlush ( pClient ); - } - else { - logClientConnect ( pClient ); - } - - epicsThreadSleep ( LOG_RESTART_DELAY ); + if ( ! isConn ) logClientConnect ( pClient ); + logClientFlush ( pClient ); + + epicsEventWaitWithTimeout ( pClient->shutdownNotify, LOG_RESTART_DELAY); epicsMutexMustLock ( pClient->mutex ); } @@ -480,9 +440,7 @@ static void logClientRestart ( logClientId id ) logClientId epicsShareAPI logClientCreate ( struct in_addr server_addr, unsigned short server_port) { - epicsTimeStamp begin, current; logClient *pClient; - double diff; pClient = calloc (1, sizeof (*pClient)); if (pClient==NULL) { @@ -507,14 +465,22 @@ logClientId epicsShareAPI logClientCreate ( pClient->shutdownConfirm = 0; epicsAtExit (logClientDestroy, (void*) pClient); - + pClient->stateChangeNotify = epicsEventCreate (epicsEventEmpty); if ( ! pClient->stateChangeNotify ) { epicsMutexDestroy ( pClient->mutex ); free ( pClient ); return NULL; } - + + pClient->shutdownNotify = epicsEventCreate (epicsEventEmpty); + if ( ! pClient->shutdownNotify ) { + epicsMutexDestroy ( pClient->mutex ); + epicsEventDestroy ( pClient->stateChangeNotify ); + free ( pClient ); + return NULL; + } + pClient->restartThreadId = epicsThreadCreate ( "logRestart", epicsThreadPriorityLow, epicsThreadGetStackSize(epicsThreadStackSmall), @@ -522,35 +488,12 @@ logClientId epicsShareAPI logClientCreate ( if ( pClient->restartThreadId == NULL ) { epicsMutexDestroy ( pClient->mutex ); epicsEventDestroy ( pClient->stateChangeNotify ); + epicsEventDestroy ( pClient->shutdownNotify ); free (pClient); fprintf(stderr, "log client: unable to start log client connection watch dog thread\n"); return NULL; } - /* - * attempt to synchronize with circuit connect - */ - epicsTimeGetCurrent ( & begin ); - epicsMutexMustLock ( pClient->mutex ); - do { - epicsMutexUnlock ( pClient->mutex ); - epicsEventWaitWithTimeout ( - pClient->stateChangeNotify, - LOG_SERVER_CREATE_CONNECT_SYNC_TIMEOUT / 10.0 ); - epicsTimeGetCurrent ( & current ); - diff = epicsTimeDiffInSeconds ( & current, & begin ); - epicsMutexMustLock ( pClient->mutex ); - } - while ( ! pClient->connected && diff < LOG_SERVER_CREATE_CONNECT_SYNC_TIMEOUT ); - epicsMutexUnlock ( pClient->mutex ); - - if ( ! pClient->connected ) { - fprintf (stderr, "log client create: timed out synchronizing with circuit connect to \"%s\" after %.1f seconds\n", - pClient->name, LOG_SERVER_CREATE_CONNECT_SYNC_TIMEOUT ); - } - - errlogAddListener ( logClientSendMessage, (void *) pClient ); - return (void *) pClient; } From b8419ec17dad02a5f096233739875d3f6e483c25 Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Wed, 4 Sep 2019 10:27:10 +0200 Subject: [PATCH 16/20] don't reconnect to log server unnecessarily --- src/libCom/logClient/logClient.c | 55 ++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/src/libCom/logClient/logClient.c b/src/libCom/logClient/logClient.c index 0056a21fe..692ac3105 100644 --- a/src/libCom/logClient/logClient.c +++ b/src/libCom/logClient/logClient.c @@ -25,7 +25,6 @@ #include "dbDefs.h" #include "epicsEvent.h" #include "iocLog.h" -#include "errlog.h" #include "epicsMutex.h" #include "epicsThread.h" #include "epicsTime.h" @@ -162,6 +161,31 @@ static void logClientDestroy (logClientId id) free ( pClient ); } +/* + * logClientCheckConnection + */ +static void logClientCheckConnection( logClient * pClient ) +{ + epicsMutexMustLock ( pClient->mutex ); + while ( pClient->connected ) { + struct timeval timeout = { 0, 0 }; + fd_set set; + char buffer[256]; + + FD_ZERO ( &set ); + FD_SET ( pClient->sock, &set ); + if ( select ( pClient->sock + 1, &set, NULL, NULL, &timeout ) == 0) + break; + if ( recv ( pClient->sock, buffer, sizeof ( buffer ), 0 ) == 0 ) { + fprintf ( stderr, "log client: connection closed by server \"%s\"\n", + pClient->name ); + logClientClose ( pClient ); + break; + } + } + epicsMutexUnlock ( pClient->mutex ); +} + /* * This method requires the pClient->mutex be owned already. */ @@ -176,6 +200,7 @@ static void sendMessageChunk(logClient * pClient, const char * message) { if ( msgBufBytesLeft < strSize && pClient->nextMsgIndex != 0u && pClient->connected) { /* buffer is full, thus flush it */ + logClientCheckConnection( pClient ); logClientFlush ( pClient ); msgBufBytesLeft = sizeof ( pClient->msgBuf ) - pClient->nextMsgIndex; } @@ -228,23 +253,6 @@ void epicsShareAPI logClientFlush ( logClientId id ) epicsMutexMustLock ( pClient->mutex ); - while (1) { - struct timeval timeout = { 0, 0 }; - fd_set set; - char buffer[256]; - - FD_ZERO ( &set ); - FD_SET ( pClient->sock, &set ); - if ( select ( pClient->sock + 1, &set, NULL, NULL, &timeout ) == 0) - break; - if ( recv ( pClient->sock, buffer, sizeof ( buffer ), 0 ) == 0 ) { - fprintf ( stderr, "log client: connection closed by server \"%s\"\n", - pClient->name ); - logClientClose ( pClient ); - break; - } - } - while ( nSent < pClient->nextMsgIndex && pClient->connected ) { int status = send ( pClient->sock, pClient->msgBuf + nSent, pClient->nextMsgIndex - nSent, 0 ); @@ -415,14 +423,19 @@ static void logClientRestart ( logClientId id ) /* SMP safe state inspection */ epicsMutexMustLock ( pClient->mutex ); while ( ! pClient->shutdown ) { - unsigned isConn; + unsigned isConn, dataToSend; + + logClientCheckConnection( pClient ); isConn = pClient->connected; + dataToSend = pClient->nextMsgIndex; epicsMutexUnlock ( pClient->mutex ); - if ( ! isConn ) logClientConnect ( pClient ); - logClientFlush ( pClient ); + if ( dataToSend ) { + if ( ! isConn ) logClientConnect ( pClient ); + logClientFlush ( pClient ); + } epicsEventWaitWithTimeout ( pClient->shutdownNotify, LOG_RESTART_DELAY); From b62938af2f233271916df4b8e653090410e98b32 Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Wed, 23 Oct 2019 11:30:26 +0200 Subject: [PATCH 17/20] use only 2 component VXWORKS_VERSION else VX_GNU_VERSION will not be set correctly --- configure/os/CONFIG.Common.T2-ppc604 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure/os/CONFIG.Common.T2-ppc604 b/configure/os/CONFIG.Common.T2-ppc604 index 52c0650b5..99deb1567 100644 --- a/configure/os/CONFIG.Common.T2-ppc604 +++ b/configure/os/CONFIG.Common.T2-ppc604 @@ -1,5 +1,5 @@ include $(CONFIG)/os/CONFIG.Common.vxWorks-ppc604_long -VXWORKS_VERSION = 5.5.1 +VXWORKS_VERSION = 5.5 WIND_BASE = /afs/psi.ch/project/vxworks/Tornado2.2.1 #there is a problem with our ccppc and optimization From ed1944c54b8abfa6284fe72be56531e5f00d7010 Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Thu, 24 Oct 2019 16:17:23 +0200 Subject: [PATCH 18/20] allow to add new error symbols from dynamicly loaded modules --- src/libCom/error/errSymLib.c | 53 +++++++++++++++++------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/src/libCom/error/errSymLib.c b/src/libCom/error/errSymLib.c index 84c093c9b..9acd280b3 100644 --- a/src/libCom/error/errSymLib.c +++ b/src/libCom/error/errSymLib.c @@ -51,9 +51,8 @@ typedef struct errnumnode { #define NHASH 256 -static ELLLIST errnumlist = ELLLIST_INIT; -static ERRNUMNODE **hashtable; -static int initialized = FALSE; +static ERRNUMNODE **hashtable = NULL; +#define initialized (hashtable!=NULL) extern ERRSYMTAB_ID errSymTbl; /**************************************************************** @@ -67,12 +66,8 @@ extern ERRSYMTAB_ID errSymTbl; int epicsShareAPI errSymBld(void) { ERRSYMBOL *errArray = errSymTbl->symbols; - ERRNUMNODE *perrNumNode = NULL; - ERRNUMNODE *pNextNode = NULL; - ERRNUMNODE **phashnode = NULL; int i; int modnum; - unsigned short hashInd; if(initialized) return(0); hashtable = (ERRNUMNODE**)callocMustSucceed @@ -89,21 +84,6 @@ int epicsShareAPI errSymBld(void) continue; } } - perrNumNode = (ERRNUMNODE *) ellFirst(&errnumlist); - while (perrNumNode) { - /* hash each perrNumNode->errNum */ - hashInd = errhash(perrNumNode->errNum); - phashnode = (ERRNUMNODE**)&hashtable[hashInd]; - pNextNode = (ERRNUMNODE*) *phashnode; - /* search for last node (NULL) of hashnode linked list */ - while (pNextNode) { - phashnode = &pNextNode->hashnode; - pNextNode = *phashnode; - } - *phashnode = perrNumNode; - perrNumNode = (ERRNUMNODE *) ellNext((ELLNODE *) perrNumNode); - } - initialized = TRUE; return(0); } @@ -125,16 +105,33 @@ unsigned short errnum; /**************************************************************** * ERRSYMBOLADD - * adds symbols to the master errnumlist as compiled from errSymTbl.c + * adds symbols to the master hashtable as compiled from errSymTbl.c ***************************************************************/ int epicsShareAPI errSymbolAdd (long errNum,char *name) { - ERRNUMNODE *pNew; + ERRNUMNODE *perrNumNode; + ERRNUMNODE *pNextNode = NULL; + ERRNUMNODE **phashnode = NULL; + unsigned short hashInd; + + if(!initialized) errSymBld(); + + perrNumNode = (ERRNUMNODE*)callocMustSucceed(1,sizeof(ERRNUMNODE),"errSymbolAdd"); + perrNumNode->errNum = errNum; + perrNumNode->message = name; + + /* hash each perrNumNode->errNum */ + hashInd = errhash(perrNumNode->errNum); + phashnode = (ERRNUMNODE**)&hashtable[hashInd]; + pNextNode = (ERRNUMNODE*) *phashnode; + /* search for last node (NULL) of hashnode linked list */ + while (pNextNode) { + phashnode = &pNextNode->hashnode; + pNextNode = *phashnode; + } + *phashnode = perrNumNode; + perrNumNode = (ERRNUMNODE *) ellNext((ELLNODE *) perrNumNode); - pNew = (ERRNUMNODE*)callocMustSucceed(1,sizeof(ERRNUMNODE),"errSymbolAdd"); - pNew->errNum = errNum; - pNew->message = name; - ellAdd(&errnumlist,(ELLNODE*)pNew); return(0); } From e7a300bf9e639b2d38db2d39a72b72cbd1c30337 Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Tue, 3 Mar 2020 16:51:34 +0100 Subject: [PATCH 19/20] fix potential crash --- src/libCom/logClient/logClient.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libCom/logClient/logClient.c b/src/libCom/logClient/logClient.c index 692ac3105..f7c9b9ca0 100644 --- a/src/libCom/logClient/logClient.c +++ b/src/libCom/logClient/logClient.c @@ -516,6 +516,9 @@ logClientId epicsShareAPI logClientCreate ( void epicsShareAPI logClientShow (logClientId id, unsigned level) { logClient *pClient = (logClient *) id; + if ( ! pClient ) { + return; + } if ( pClient->connected ) { printf ("log client: connected to log server at \"%s\"\n", pClient->name); From a441443bd077cb40b732021ce5da99f82777ec3c Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Wed, 4 Mar 2020 08:43:51 +0100 Subject: [PATCH 20/20] try to harden seqRecord against race condition --- src/rec/seqRecord.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/rec/seqRecord.c b/src/rec/seqRecord.c index 7627f44e3..9d20726c0 100644 --- a/src/rec/seqRecord.c +++ b/src/rec/seqRecord.c @@ -174,6 +174,7 @@ static long process(seqRecord *prec) linkDesc *plink; unsigned short lmask; int tmp; + int index; if(seqRecDebug > 10) printf("seqRecord: process(%s) pact = %d\n", prec->name, prec->pact); @@ -230,6 +231,7 @@ static long process(seqRecord *prec) } /* Figure out which links are going to be processed */ pcb->index = 0; + index = 0; plink = (linkDesc *)(&(prec->dly1)); tmp = 1; while (lmask) @@ -241,23 +243,21 @@ static long process(seqRecord *prec) if ((lmask & 1) && ((plink->lnk.type != CONSTANT)||(plink->dol.type != CONSTANT))) { if (seqRecDebug > 4) - printf(" seqRec-process Adding link %d at index %d\n", tmp, pcb->index); + printf(" seqRec-process Adding link %d at index %d\n", tmp, index); - pcb->plinks[pcb->index] = plink; - pcb->index++; + pcb->plinks[index++] = plink; } lmask >>= 1; plink++; tmp++; } - pcb->plinks[pcb->index] = NULL; /* mark the bottom of the list */ + pcb->plinks[index] = NULL; /* mark the bottom of the list */ - if (!pcb->index) + if (!index) { /* There was nothing to do, finish record processing here */ return(asyncFinish(prec)); } - pcb->index = 0; /* Start doing the first forward link (We have at least one for sure) */ processNextLink(prec); @@ -367,6 +367,14 @@ static void processCallback(CALLBACK *arg) if (seqRecDebug > 5) printf("processCallback(%s) processing field index %d\n", prec->name, pcb->index+1); + if (pcb->plinks[pcb->index] == NULL) + { + static int overrun = 0; + errlogPrintf("seq record %s: index overrun number %d in callback.\n", prec->name, ++overrun); + dbScanUnlock((struct dbCommon *)prec); + return; + } + /* Save the old value */ myDouble = pcb->plinks[pcb->index]->dov;