- implemented suggestion by Michael Davidsaver: when reading ELF files

check modifification time against program start time and warn if the
   file was modified more recently since it could be out of date.
This commit is contained in:
Till Straumann
2014-09-18 12:19:47 -07:00
parent 012ee68199
commit bbfb69ed8d

View File

@@ -24,6 +24,9 @@
#include <elf.h>
#include <errno.h>
#include <inttypes.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#ifdef _POSIX_MAPPED_FILES
#include <sys/mman.h>
@@ -112,6 +115,18 @@ static ESyms elfs = 0;
static epicsMutexId listMtx;
static epicsThreadOnceId listMtxInitId = EPICS_THREAD_ONCE_INIT;
static time_t getStartTime()
{
struct timespec ts;
if ( clock_gettime(CLOCK_REALTIME, &ts) )
return (time_t)0;
return ts.tv_sec;
}
static time_t prog_start_time = getStartTime();
static void listMtxInit(void *unused)
{
listMtx = epicsMutexMustCreate();
@@ -350,6 +365,12 @@ struct stat stat_b;
}
n -= EI_NIDENT;
if ( 0 == fstat(es->fd, &stat_b) ) {
if ( stat_b.st_mtime > prog_start_time ) {
errlogPrintf("elfRead() -- WARNING: '%s' was modified after program start -- symbol information may be inaccurate or invalid\n", fname);
}
}
/* read rest */
if ( n != do_read(es->fd, ehdr.e32.e_ident + EI_NIDENT, n) ) {
errlogPrintf("elfRead() -- unable to read ELF ehdr: %s\n", strerror(errno));