diff --git a/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer b/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer index 583f6bda8..91643315f 100755 Binary files a/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer and b/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer differ diff --git a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c index be677b186..6dbebe529 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c @@ -181,19 +181,7 @@ int checkKernelVersion() { #ifdef VIRTUAL return OK; #endif - char output[256]; - memset(output, 0, 256); - FILE *sysFile = popen("uname -a | cut -d ' ' -f5-10", "r"); - fgets(output, sizeof(output), sysFile); - pclose(sysFile); - - if (strstr(output, KERNEL_DATE_VRSN) == NULL) { - LOG(logERROR, ("Kernel Version Incompatible! Expected: %s, Got: %s\n", - KERNEL_DATE_VRSN, output)); - return FAIL; - } - LOG(logINFO, ("Kernel Version Compatible: %s\n", output)); - return OK; + return Nios_checkKernelVersion(KERNEL_DATE_VRSN); } int checkType() { diff --git a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer b/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer index e4075386f..b1c9c72b5 100755 Binary files a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer and b/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer differ diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index 500c7420f..4b6238b64 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -167,19 +167,7 @@ int checkKernelVersion() { #ifdef VIRTUAL return OK; #endif - char output[256]; - memset(output, 0, 256); - FILE *sysFile = popen("uname -a | cut -d ' ' -f5-10", "r"); - fgets(output, sizeof(output), sysFile); - pclose(sysFile); - - if (strstr(output, KERNEL_DATE_VRSN) == NULL) { - LOG(logERROR, ("Kernel Version Incompatible! Expected: %s, Got: %s\n", - KERNEL_DATE_VRSN, output)); - return FAIL; - } - LOG(logINFO, ("Kernel Version Compatible: %s\n", output)); - return OK; + return Nios_checkKernelVersion(KERNEL_DATE_VRSN); } int checkType() { diff --git a/slsDetectorServers/slsDetectorServer/include/common.h b/slsDetectorServers/slsDetectorServer/include/common.h index fed3cbbf2..1f2ebbe42 100644 --- a/slsDetectorServers/slsDetectorServer/include/common.h +++ b/slsDetectorServers/slsDetectorServer/include/common.h @@ -1,6 +1,7 @@ #pragma once #include +#include /** * Convert a value from a range to a different range (eg voltage to dac or vice @@ -16,4 +17,6 @@ int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin, int outputMax, int inputValue, int *outputValue); -int getAbsPath(char *buf, size_t bufSize, char *fname); \ No newline at end of file +int getAbsPath(char *buf, size_t bufSize, char *fname); + +int GetTimeFromString(char *buf, time_t *result); \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/include/nios.h b/slsDetectorServers/slsDetectorServer/include/nios.h index d8b0ac2b4..128f556cf 100644 --- a/slsDetectorServers/slsDetectorServer/include/nios.h +++ b/slsDetectorServers/slsDetectorServer/include/nios.h @@ -87,3 +87,7 @@ int mapCSP0(void); * Get Nios base address */ u_int32_t *Nios_getBaseAddress(); + +/** check kernel version against expected version string (complain if too old) + * @returns OK or FAIL */ +int Nios_checkKernelVersion(char *expectedVersion); \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/common.c b/slsDetectorServers/slsDetectorServer/src/common.c index 04af3bb11..5d2cb5c1a 100644 --- a/slsDetectorServers/slsDetectorServer/src/common.c +++ b/slsDetectorServers/slsDetectorServer/src/common.c @@ -1,3 +1,4 @@ +#define _GNU_SOURCE // needed for strptime to be at the top #include "common.h" #include "clogger.h" #include "sls_detector_defs.h" @@ -59,4 +60,13 @@ int getAbsPath(char *buf, size_t bufSize, char *fname) { sprintf(buf, "%s/%s", dir, fname); LOG(logDEBUG1, ("full path for %s: %s\n", fname, buf)); return OK; +} + +int GetTimeFromString(char *buf, time_t *result) { + struct tm t; + if (NULL == strptime(buf, "%a %b %d %H:%M:%S %Z %Y", &t)) { + return FAIL; + } + *result = mktime(&t); + return OK; } \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/nios.c b/slsDetectorServers/slsDetectorServer/src/nios.c index 7a1e4b619..82fbbcc07 100644 --- a/slsDetectorServers/slsDetectorServer/src/nios.c +++ b/slsDetectorServers/slsDetectorServer/src/nios.c @@ -2,10 +2,13 @@ #include "RegisterDefs.h" #include "ansi.h" #include "clogger.h" +#include "common.h" #include "sls_detector_defs.h" -#include // open -#include // mmap +#include // open +#include +#include // mmap +#include // uname /* global variables */ u_int32_t *csp0base = 0; @@ -126,4 +129,50 @@ int mapCSP0(void) { return OK; } -u_int32_t *Nios_getBaseAddress() { return csp0base; } \ No newline at end of file +u_int32_t *Nios_getBaseAddress() { return csp0base; } + +int Nios_checkKernelVersion(char *expectedVersion) { + // extract kernel date string + struct utsname buf; + if (uname(&buf) == -1) { + LOG(logERROR, ("Could not get kernel version\n")); + return FAIL; + } + + // remove first word (#version number) + const char *ptr = strchr(buf.version, ' '); + if (ptr == NULL) { + LOG(logERROR, ("Could not parse kernel version\n")); + return FAIL; + } + char output[256]; + memset(output, 0, 256); + strcpy(output, buf.version + (ptr - buf.version + 1)); + + // convert kernel date string into time + time_t kernelDate; + if (GetTimeFromString(output, &kernelDate) == FAIL) { + LOG(logERROR, ("Could not parse retrieved kernel date, %s\n", output)); + return FAIL; + } + + // convert expected date into time + time_t expDate; + if (GetTimeFromString(expectedVersion, &expDate) == FAIL) { + LOG(logERROR, + ("Could not parse expected kernel date, %s\n", expectedVersion)); + return FAIL; + } + + // compare if kernel time is older than expected time + if (kernelDate < expDate) { + LOG(logERROR, ("Kernel Version Incompatible (too old)! Expected: [%s], " + "Got [%s]\n", + expectedVersion, output)); + return FAIL; + } + + LOG(logINFOBLUE, ("Kernel Version Compatible: %s [min.: %s]\n", output, + expectedVersion)); + return OK; +} \ No newline at end of file diff --git a/slsSupportLib/include/versionAPI.h b/slsSupportLib/include/versionAPI.h index 17e69aee6..09936fb19 100644 --- a/slsSupportLib/include/versionAPI.h +++ b/slsSupportLib/include/versionAPI.h @@ -6,8 +6,8 @@ #define APICTB 0x200910 #define APIGOTTHARD 0x200910 -#define APIGOTTHARD2 0x200910 #define APIJUNGFRAU 0x200910 -#define APIMYTHEN3 0x200910 #define APIMOENCH 0x200910 #define APIEIGER 0x200910 +#define APIGOTTHARD2 0x200910 +#define APIMYTHEN3 0x200910