mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-05 17:40:40 +02:00
delete old servers, wip
This commit is contained in:
parent
8b1851e652
commit
cf6423dbbe
@ -60,7 +60,7 @@ int getAbsPath(char *buf, size_t bufSize, char *fname) {
|
|||||||
}
|
}
|
||||||
path[len] = '\0';
|
path[len] = '\0';
|
||||||
|
|
||||||
// get dir path and attach config file name
|
// get dir path and attach file name
|
||||||
char *dir = dirname(path);
|
char *dir = dirname(path);
|
||||||
memset(buf, 0, bufSize);
|
memset(buf, 0, bufSize);
|
||||||
sprintf(buf, "%s/%s", dir, fname);
|
sprintf(buf, "%s/%s", dir, fname);
|
||||||
@ -635,13 +635,17 @@ int createEmptyFile(char *mess, char *fname, char *errorPrefix) {
|
|||||||
int deleteFile(char *mess, char *fname, char *errorPrefix) {
|
int deleteFile(char *mess, char *fname, char *errorPrefix) {
|
||||||
const int fileNameSize = 128;
|
const int fileNameSize = 128;
|
||||||
char fullname[fileNameSize];
|
char fullname[fileNameSize];
|
||||||
if (getAbsPath(fullname, fileNameSize, fname) == FAIL) {
|
strcpy(fullname, fname);
|
||||||
sprintf(mess,
|
|
||||||
"Could not %s. Could not get abs path of current "
|
if (fname[0] != '/') {
|
||||||
"process\n",
|
if (getAbsPath(fullname, fileNameSize, fname) == FAIL) {
|
||||||
errorPrefix);
|
sprintf(mess,
|
||||||
LOG(logERROR, (mess));
|
"Could not %s. Could not get abs path of current "
|
||||||
return FAIL;
|
"process\n",
|
||||||
|
errorPrefix);
|
||||||
|
LOG(logERROR, (mess));
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (access(fullname, F_OK) == 0) {
|
if (access(fullname, F_OK) == 0) {
|
||||||
@ -674,11 +678,29 @@ int deleteFile(char *mess, char *fname, char *errorPrefix) {
|
|||||||
int deleteOldServers(char *mess, char *newServerName, char *errorPrefix) {
|
int deleteOldServers(char *mess, char *newServerName, char *errorPrefix) {
|
||||||
LOG(logINFOBLUE, ("newserver name:%s\n", newServerName));
|
LOG(logINFOBLUE, ("newserver name:%s\n", newServerName));
|
||||||
|
|
||||||
// if it exists
|
// get path of current binary
|
||||||
if (access(newServerName, F_OK) == 0) {
|
char path[MAX_STR_LENGTH];
|
||||||
LOG(logINFO,
|
memset(path, 0, MAX_STR_LENGTH);
|
||||||
("\tOld server does exist: %s (%s)\n", newServerName, errorPrefix));
|
ssize_t len = readlink("/proc/self/exe", path, MAX_STR_LENGTH - 1);
|
||||||
|
if (len < 0) {
|
||||||
|
LOG(logWARNING, ("(%s): Could not delete old servers. Could not "
|
||||||
|
"readlink current binary\n",
|
||||||
|
errorPrefix));
|
||||||
|
return FAIL;
|
||||||
}
|
}
|
||||||
exit(-1);
|
path[len] = '\0';
|
||||||
|
LOG(logINFO, ("Current binary:%s\n", path));
|
||||||
|
|
||||||
|
// if current binary same as new server name, replaced anyway
|
||||||
|
if (strcmp(path, newServerName)) {
|
||||||
|
if (deleteFile(mess, path, errorPrefix) == FAIL) {
|
||||||
|
LOG(logWARNING,
|
||||||
|
("(%s). Could not delete old servers\n", errorPrefix));
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOG(logINFO, ("Current binary same as server name\n"));
|
||||||
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
@ -9601,11 +9601,10 @@ void receive_program_via_blackfin(int file_des, enum PROGRAM_INDEX index,
|
|||||||
totalsize, forceDeleteNormalFile);
|
totalsize, forceDeleteNormalFile);
|
||||||
break;
|
break;
|
||||||
case PROGRAM_SERVER:
|
case PROGRAM_SERVER:
|
||||||
ret = deleteOldServers(mess, serverName, "update detector server");
|
// a fail here is not a show stopper (just for memory)
|
||||||
if (ret == OK) {
|
deleteOldServers(mess, serverName, "update detector server");
|
||||||
ret = moveBinaryFile(mess, serverName, TEMP_PROG_FILE_NAME,
|
ret = moveBinaryFile(mess, serverName, TEMP_PROG_FILE_NAME,
|
||||||
"update detector server");
|
"update detector server");
|
||||||
}
|
|
||||||
if (ret == OK) {
|
if (ret == OK) {
|
||||||
ret = setupDetectorServer(mess, serverName);
|
ret = setupDetectorServer(mess, serverName);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user