diff --git a/slsDetectorServers/slsDetectorServer/src/common.c b/slsDetectorServers/slsDetectorServer/src/common.c index e60734cb7..17f21d517 100644 --- a/slsDetectorServers/slsDetectorServer/src/common.c +++ b/slsDetectorServers/slsDetectorServer/src/common.c @@ -60,7 +60,7 @@ int getAbsPath(char *buf, size_t bufSize, char *fname) { } path[len] = '\0'; - // get dir path and attach config file name + // get dir path and attach file name char *dir = dirname(path); memset(buf, 0, bufSize); 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) { const int fileNameSize = 128; char fullname[fileNameSize]; - if (getAbsPath(fullname, fileNameSize, fname) == FAIL) { - sprintf(mess, - "Could not %s. Could not get abs path of current " - "process\n", - errorPrefix); - LOG(logERROR, (mess)); - return FAIL; + strcpy(fullname, fname); + + if (fname[0] != '/') { + if (getAbsPath(fullname, fileNameSize, fname) == FAIL) { + sprintf(mess, + "Could not %s. Could not get abs path of current " + "process\n", + errorPrefix); + LOG(logERROR, (mess)); + return FAIL; + } } 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) { LOG(logINFOBLUE, ("newserver name:%s\n", newServerName)); - // if it exists - if (access(newServerName, F_OK) == 0) { - LOG(logINFO, - ("\tOld server does exist: %s (%s)\n", newServerName, errorPrefix)); + // get path of current binary + char path[MAX_STR_LENGTH]; + memset(path, 0, MAX_STR_LENGTH); + 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; } \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index 18caccbec..270742949 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -9601,11 +9601,10 @@ void receive_program_via_blackfin(int file_des, enum PROGRAM_INDEX index, totalsize, forceDeleteNormalFile); break; case PROGRAM_SERVER: - ret = deleteOldServers(mess, serverName, "update detector server"); - if (ret == OK) { - ret = moveBinaryFile(mess, serverName, TEMP_PROG_FILE_NAME, - "update detector server"); - } + // a fail here is not a show stopper (just for memory) + deleteOldServers(mess, serverName, "update detector server"); + ret = moveBinaryFile(mess, serverName, TEMP_PROG_FILE_NAME, + "update detector server"); if (ret == OK) { ret = setupDetectorServer(mess, serverName); }