This commit is contained in:
maliakal_d 2021-11-10 10:58:29 +01:00
parent 14ee2087dc
commit 15aa42d328
7 changed files with 131 additions and 106 deletions

View File

@ -46,4 +46,5 @@ int verifyChecksumFromFile(char *mess, char *functionType, char *clientChecksum,
int verifyChecksumFromFlash(char *mess, char *functionType,
char *clientChecksum, char *fname, ssize_t fsize);
int verifyChecksum(char *mess, char *functionType, char *clientChecksum,
MD5_CTX *c, char *msg);
MD5_CTX *c, char *msg);
int setupDetectorServer(char *mess, char *sname);

View File

@ -283,7 +283,7 @@ int update_detector_server(int);
int receive_program(int file_des, enum PROGRAM_INDEX index);
void receive_program_via_blackfin(int file_des, enum PROGRAM_INDEX index,
char *functionType, uint64_t filesize,
char *checksum);
char *checksum, char *serverName);
void receive_program_default(int file_des, enum PROGRAM_INDEX index,
char *functionType, uint64_t filesize,
char *checksum);
char *checksum, char *serverName);

View File

@ -406,4 +406,86 @@ int verifyChecksum(char *mess, char *functionType, char *clientChecksum,
}
LOG(logINFO, ("\tChecksum of %s verified\n", msg));
return OK;
}
int setupDetectorServer(char *mess, char *sname) {
char cmd[MAX_STR_LENGTH] = {0};
char retvals[MAX_STR_LENGTH] = {0};
// give permissions
if (snprintf(cmd, MAX_STR_LENGTH, "chmod 777 %s", sname) >=
MAX_STR_LENGTH) {
strcpy(mess, "Could not copy detector server. Command to give "
"permissions to server is too long\n");
LOG(logERROR, (mess));
return FAIL;
}
if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
snprintf(mess, MAX_STR_LENGTH,
"Could not copy detector server (permissions). %s\n", retvals);
LOG(logERROR, (mess));
return FAIL;
}
LOG(logINFO, ("\tPermissions modified\n"));
// symbolic link
if (snprintf(cmd, MAX_STR_LENGTH, "ln -sf %s %s", sname,
LINKED_SERVER_NAME) >= MAX_STR_LENGTH) {
strcpy(mess, "Could not copy detector server. Command to "
"create symbolic link too long\n");
LOG(logERROR, (mess));
return FAIL;
}
if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
snprintf(mess, MAX_STR_LENGTH,
"Could not copy detector server (symbolic link). %s\n",
retvals);
LOG(logERROR, (mess));
return FAIL;
}
LOG(logINFO, ("\tSymbolic link created\n"));
// blackfin boards (respawn) (only kept for backwards compatibility)
#if defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || defined(MOENCHD) || \
defined(GOTTHARDD)
// delete every line with DetectorServer in /etc/inittab
strcpy(cmd, "sed -i '/DetectorServer/d' /etc/inittab");
if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
snprintf(mess, MAX_STR_LENGTH,
"Could not copy detector server (del respawning). %s\n",
retvals);
LOG(logERROR, (mess));
return FAIL;
}
LOG(logINFO, ("\tinittab: DetectoServer line deleted\n"));
// add new link name to /etc/inittab
format = "echo 'ttyS0::respawn:/./%s' >> /etc/inittab";
if (snprintf(cmd, MAX_STR_LENGTH, format, LINKED_SERVER_NAME) >=
MAX_STR_LENGTH) {
strcpy(mess, "Could not copy detector server. Command "
"to add new server for spawning is too long\n");
LOG(logERROR, (mess));
return FAIL;
}
if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
snprintf(mess, MAX_STR_LENGTH,
"Could not copy detector server (respawning). %s\n", retvals);
LOG(logERROR, (mess));
return FAIL;
}
LOG(logINFO, ("\tinittab: updated for respawning\n"));
#endif
// sync
strcpy(cmd, "sync");
if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
snprintf(mess, MAX_STR_LENGTH,
"Could not copy detector server (sync). %s\n", retvals);
LOG(logERROR, (mess));
return FAIL;
}
LOG(logINFO, ("\tsync\n"));
}

View File

@ -4110,95 +4110,8 @@ int copy_detector_server(int file_des) {
LOG(logINFO, ("\tServer copied\n"));
}
// give permissions
if (ret == OK) {
if (snprintf(cmd, MAX_STR_LENGTH, "chmod 777 %s", sname) >=
MAX_STR_LENGTH) {
ret = FAIL;
strcpy(mess, "Could not copy detector server. Command to give "
"permissions to server is too long\n");
LOG(logERROR, (mess));
} else if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
ret = FAIL;
snprintf(mess, MAX_STR_LENGTH,
"Could not copy detector server (permissions). %s\n",
retvals);
// LOG(logERROR, (mess)); already printed in executecommand
} else {
LOG(logINFO, ("\tPermissions modified\n"));
}
}
// symbolic link
if (ret == OK) {
if (snprintf(cmd, MAX_STR_LENGTH, "ln -sf %s %s", sname,
LINKED_SERVER_NAME) >= MAX_STR_LENGTH) {
ret = FAIL;
strcpy(mess, "Could not copy detector server. Command to "
"create symbolic link too long\n");
LOG(logERROR, (mess));
} else if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
ret = FAIL;
snprintf(mess, MAX_STR_LENGTH,
"Could not copy detector server (symbolic link). %s\n",
retvals);
// LOG(logERROR, (mess)); already printed in executecommand
} else {
LOG(logINFO, ("\tSymbolic link created\n"));
}
}
// blackfin boards (respawn) (only kept for backwards compatibility)
#if defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || defined(MOENCHD) || \
defined(GOTTHARDD)
// delete every line with DetectorServer in /etc/inittab
if (ret == OK) {
strcpy(cmd, "sed -i '/DetectorServer/d' /etc/inittab");
if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
ret = FAIL;
snprintf(
mess, MAX_STR_LENGTH,
"Could not copy detector server (del respawning). %s\n",
retvals);
// LOG(logERROR, (mess)); already printed in executecommand
} else {
LOG(logINFO, ("\tinittab: DetectoServer line deleted\n"));
}
}
// add new link name to /etc/inittab
if (ret == OK) {
format = "echo 'ttyS0::respawn:/./%s' >> /etc/inittab";
if (snprintf(cmd, MAX_STR_LENGTH, format, LINKED_SERVER_NAME) >=
MAX_STR_LENGTH) {
ret = FAIL;
strcpy(mess, "Could not copy detector server. Command "
"to add new server for spawning is too long\n");
LOG(logERROR, (mess));
} else if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
ret = FAIL;
snprintf(mess, MAX_STR_LENGTH,
"Could not copy detector server (respawning). %s\n",
retvals);
// LOG(logERROR, (mess)); already printed in executecommand
} else {
LOG(logINFO, ("\tinittab: updated for respawning\n"));
}
}
#endif
// sync
if (ret == OK) {
strcpy(cmd, "sync");
if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
ret = FAIL;
snprintf(mess, MAX_STR_LENGTH,
"Could not copy detector server (sync). %s\n",
retvals);
// LOG(logERROR, (mess)); already printed in executecommand
} else {
LOG(logINFO, ("\tsync\n"));
}
ret = setupDetectorServer(mess, sname);
}
}
#endif
@ -9343,18 +9256,25 @@ int receive_program(int file_des, enum PROGRAM_INDEX index) {
LOG(logINFO, ("\tProgram size: %lld\n", (long long int)filesize));
// client checksum
char checksum[MAX_STR_LENGTH];
memset(checksum, 0, MAX_STR_LENGTH);
char checksum[MAX_STR_LENGTH] = {0};
if (receiveData(file_des, checksum, MAX_STR_LENGTH, OTHER) < 0)
return printSocketReadError();
LOG(logINFO, ("\tChecksum: %s\n", checksum));
// server name
char serverName[MAX_STR_LENGTH] = {0};
if (index == PROGRAM_SERVER) {
if (receiveData(file_des, serverName, MAX_STR_LENGTH, OTHER) < 0)
return printSocketReadError();
LOG(logINFO, ("\tServer Name: %s\n", serverName));
}
#if defined(GOTTHARD2D) || defined(MYTHEN3D) || defined(EIGERD)
receive_program_default(file_des, index, functionType, filesize,
checksum);
checksum, serverName);
#else
receive_program_via_blackfin(file_des, index, functionType, filesize,
checksum);
checksum, serverName);
#endif
if (ret == OK) {
@ -9369,7 +9289,7 @@ int receive_program(int file_des, enum PROGRAM_INDEX index) {
void receive_program_via_blackfin(int file_des, enum PROGRAM_INDEX index,
char *functionType, uint64_t filesize,
char *checksum) {
char *checksum, char* serverName) {
#if !defined(JUNGFRAUD) && !defined(CHIPTESTBOARDD) && !defined(MOENCHD) && \
!defined(GOTTHARDD)
@ -9461,6 +9381,7 @@ void receive_program_via_blackfin(int file_des, enum PROGRAM_INDEX index,
totalsize);
break;
case PROGRAM_SERVER:
ret = setupDetectorServer(mess, serverName);
break;
default:
modeNotImplemented("Program index", (int)index);
@ -9474,7 +9395,7 @@ void receive_program_via_blackfin(int file_des, enum PROGRAM_INDEX index,
void receive_program_default(int file_des, enum PROGRAM_INDEX index,
char *functionType, uint64_t filesize,
char *checksum) {
char *checksum, char* serverName) {
#if !defined(GOTTHARD2D) && !defined(MYTHEN3D) && !defined(EIGERD)
ret = FAIL;
sprintf(mess,
@ -9542,6 +9463,7 @@ void receive_program_default(int file_des, enum PROGRAM_INDEX index,
filesize);
break;
case PROGRAM_SERVER:
ret = setupDetectorServer(mess, serverName);
break;
default:
modeNotImplemented("Program index", (int)index);

View File

@ -2155,7 +2155,19 @@ void Detector::copyDetectorServer(const std::string &fname,
void Detector::updateDetectorServer(const std::string &fname, Positions pos) {
LOG(logINFO) << "Updating Detector Server...";
std::vector<char> buffer = readBinaryFile(fname, "Update Detector Server");
const std::string &serverName std::vector<char> buffer =
readBinaryFile(fname, "Update Detector Server");
// get file name
std::string filename(fname);
std::size_t pos = fname.rfind('/');
if (pos != std::string::npos) {
filename = filePath.substr(pos + 1, filePath.size() - 1);
}
LOG(logINFOBLUE) << "filename:" << filename;
exit(-1);
std::filesystem::path(fname).filename();
pimpl->Parallel(&Module::updateDetectorServer, pos, buffer);
if (getDetectorType().squash() != defs::EIGER) {
rebootController(pos);

View File

@ -2523,18 +2523,19 @@ void Module::copyDetectorServer(const std::string &fname,
<< "): detector server copied";
}
void Module::updateDetectorServer(std::vector<char> buffer) {
void Module::updateDetectorServer(std::vector<char> buffer,
const std::string &serverName) {
switch (shm()->detType) {
case JUNGFRAU:
case CHIPTESTBOARD:
case MOENCH:
sendProgram(true, buffer, F_UPDATE_DETECTOR_SERVER,
"Update Detector Server (no tftp)");
"Update Detector Server (no tftp)", serverName);
break;
case MYTHEN3:
case GOTTHARD2:
sendProgram(false, buffer, F_UPDATE_DETECTOR_SERVER,
"Update Detector Server (no tftp)");
"Update Detector Server (no tftp)", serverName);
break;
default:
throw RuntimeError("Updating Kernel via the package is not implemented "
@ -3464,7 +3465,8 @@ sls_detector_module Module::readSettingsFile(const std::string &fname,
void Module::sendProgram(bool blackfin, std::vector<char> buffer,
const int functionEnum,
const std::string &functionType) {
const std::string &functionType,
const std::string &serverName) {
LOG(logINFO) << "Module " << moduleIndex << " (" << shm()->hostname
<< "): Sending " << functionType;
@ -3477,11 +3479,15 @@ void Module::sendProgram(bool blackfin, std::vector<char> buffer,
// send checksum
std::string checksum = sls::md5_calculate_checksum(buffer.data(), filesize);
LOG(logDEBUG1) << "Checksum:" << checksum;
char cChecksum[MAX_STR_LENGTH];
memset(cChecksum, 0, MAX_STR_LENGTH);
char cChecksum[MAX_STR_LENGTH] = {0};
strcpy(cChecksum, checksum.c_str());
client.Send(cChecksum);
// send server name
char sname[MAX_STR_LENGTH] = {0};
strcpy(sname, serverName.c_str());
client.Send(sname);
// validate memory allocation etc in detector
if (client.Receive<int>() == FAIL) {
std::ostringstream os;

View File

@ -541,7 +541,8 @@ class Module : public virtual slsDetectorDefs {
void resetFPGA();
void copyDetectorServer(const std::string &fname,
const std::string &hostname);
void updateDetectorServer(std::vector<char> buffer);
void updateDetectorServer(std::vector<char> buffer,
const std::string &serverName);
void updateKernel(std::vector<char> buffer);
void rebootController();
uint32_t readRegister(uint32_t addr) const;
@ -749,7 +750,8 @@ class Module : public virtual slsDetectorDefs {
sls_detector_module readSettingsFile(const std::string &fname,
bool trimbits = true);
void sendProgram(bool blackfin, std::vector<char> buffer,
const int functionEnum, const std::string &functionType);
const int functionEnum, const std::string &functionType,
const std::string &serverName = nullptr);
void simulatingActivityinDetector(const std::string &functionType,
const int timeRequired);