mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 18:17:59 +02:00
addd kernel version
This commit is contained in:
@ -28,6 +28,8 @@ int getAbsPath(char *buf, size_t bufSize, char *fname);
|
||||
|
||||
int getTimeFromString(char *buf, time_t *result);
|
||||
|
||||
int getKernelVersion(char* retvals);
|
||||
|
||||
int validateKernelVersion(char *expectedVersion);
|
||||
|
||||
void validate(int *ret, char *mess, int arg, int retval, char *modename,
|
||||
|
@ -60,9 +60,7 @@ typedef struct udpStruct_s {
|
||||
int isInitCheckDone();
|
||||
int getInitResult(char **mess);
|
||||
void basictests();
|
||||
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
|
||||
int checkKernelVersion();
|
||||
#endif
|
||||
int getKernelVersion(char* retvals);
|
||||
#if defined(GOTTHARDD) || defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || \
|
||||
defined(MOENCHD) || defined(MYTHEN3D) || defined(GOTTHARD2D)
|
||||
int checkType();
|
||||
|
@ -276,4 +276,5 @@ int clear_all_udp_dst(int);
|
||||
int get_udp_first_dest(int);
|
||||
int set_udp_first_dest(int);
|
||||
int get_readout_speed(int);
|
||||
int set_readout_speed(int);
|
||||
int set_readout_speed(int);
|
||||
int get_kernel_version(int);
|
@ -96,28 +96,44 @@ int getTimeFromString(char *buf, time_t *result) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int validateKernelVersion(char *expectedVersion) {
|
||||
// extract kernel date string
|
||||
int getKernelVersion(char* retvals) {
|
||||
struct utsname buf = {0};
|
||||
if (uname(&buf) == -1) {
|
||||
LOG(logERROR, ("Could not get kernel version\n"));
|
||||
strcpy(retvals, "Failed to get utsname structure from uname\n");
|
||||
LOG(logERROR, (retvals));
|
||||
return FAIL;
|
||||
}
|
||||
strcpy(retvals, buf.version);
|
||||
LOG(logINFOBLUE, ("Kernel Version: %s\n", retvals));
|
||||
return OK;
|
||||
}
|
||||
|
||||
int validateKernelVersion(char *expectedVersion) {
|
||||
// extract kernel date string
|
||||
char version[255] = {0};
|
||||
if (getKernelVersion(version) == FAIL) {
|
||||
LOG(logERROR, ("Could not validate kernel version\n"));
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logDEBUG, ("utsname.version:%s\n", version));
|
||||
|
||||
char currentVersion[255] = {0};
|
||||
#ifdef VIRTUAL
|
||||
strcpy(currentVersion, expectedVersion);
|
||||
#else
|
||||
// remove first word (#version number)
|
||||
const char *ptr = strchr(buf.version, ' ');
|
||||
const char *ptr = strchr(version, ' ');
|
||||
if (ptr == NULL) {
|
||||
LOG(logERROR, ("Could not parse kernel version\n"));
|
||||
return FAIL;
|
||||
}
|
||||
char output[255];
|
||||
memset(output, 0, sizeof(output));
|
||||
strcpy(output, buf.version + (ptr - buf.version + 1));
|
||||
strcpy(currentVersion, version + (ptr - version + 1));
|
||||
#endif
|
||||
|
||||
// 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));
|
||||
if (getTimeFromString(currentVersion, &kernelDate) == FAIL) {
|
||||
LOG(logERROR, ("Could not parse retrieved kernel date, %s\n", currentVersion));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
@ -133,11 +149,11 @@ int validateKernelVersion(char *expectedVersion) {
|
||||
if (kernelDate < expDate) {
|
||||
LOG(logERROR, ("Kernel Version Incompatible (too old)! Expected: [%s], "
|
||||
"Got [%s]\n",
|
||||
expectedVersion, output));
|
||||
expectedVersion, currentVersion));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
LOG(logINFOBLUE, ("Kernel Version Compatible: %s [min.: %s]\n", output,
|
||||
LOG(logINFOBLUE, ("Kernel Version Compatible: %s [min.: %s]\n", currentVersion,
|
||||
expectedVersion));
|
||||
return OK;
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ int main(int argc, char *argv[]) {
|
||||
memset(portCmd, 0, 256);
|
||||
sprintf(portCmd, "-p%d", portno);
|
||||
for (int i = 0; i < argc; ++i) {
|
||||
LOG(logINFOBLUE, ("i:%d argv[i]:%s\n", i, argv[i]));
|
||||
LOG(logDEBUG, ("i:%d argv[i]:%s\n", i, argv[i]));
|
||||
// remove port argument (--port) and [value]
|
||||
if (!strcasecmp(argv[i], "--port")) {
|
||||
++i;
|
||||
|
@ -414,6 +414,8 @@ void function_table() {
|
||||
flist[F_SET_UDP_FIRST_DEST] = &set_udp_first_dest;
|
||||
flist[F_GET_READOUT_SPEED] = &get_readout_speed;
|
||||
flist[F_SET_READOUT_SPEED] = &set_readout_speed;
|
||||
flist[F_GET_KERNEL_VERSION] = &get_kernel_version;
|
||||
|
||||
// check
|
||||
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
|
||||
LOG(logERROR, ("The last detector function enum has reached its "
|
||||
@ -9411,4 +9413,24 @@ int set_readout_speed(int file_des) {
|
||||
}
|
||||
#endif
|
||||
return Server_SendResult(file_des, INT32, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
int get_kernel_version(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
char retvals[MAX_STR_LENGTH];
|
||||
memset(retvals, 0, MAX_STR_LENGTH);
|
||||
|
||||
LOG(logDEBUG1, ("Getting kernel version\n"));
|
||||
|
||||
// get only
|
||||
ret = getKernelVersion(retvals);
|
||||
if (ret == FAIL) {
|
||||
snprintf(mess, MAX_STR_LENGTH,
|
||||
"Could not get kernel version. %s\n", retvals);
|
||||
LOG(logERROR, (mess));
|
||||
} else {
|
||||
LOG(logDEBUG1, ("kernel version: [%s]\n", retvals));
|
||||
}
|
||||
return Server_SendResult(file_des, OTHER, retvals, sizeof(retvals));
|
||||
}
|
||||
|
Reference in New Issue
Block a user