resolve for doubel slashes, wip

This commit is contained in:
maliakal_d 2022-04-04 11:17:41 +02:00
parent 1826dd46cb
commit 9d2d8fe1d7
2 changed files with 15 additions and 9 deletions

View File

@ -67,4 +67,4 @@ int moveBinaryFile(char *mess, char *dest, char *src, char *errorPrefix);
int createEmptyFile(char *mess, char *fname, char *errorPrefix); int createEmptyFile(char *mess, char *fname, char *errorPrefix);
int deleteFile(char *mess, char *fname, char *errorPrefix); int deleteFile(char *mess, char *fname, char *errorPrefix);
int deleteOldServers(char *mess, char *newServerName, char *errorPrefix); int deleteOldServers(char *mess, char *newServerPath, char *errorPrefix);

View File

@ -675,23 +675,29 @@ int deleteFile(char *mess, char *fname, char *errorPrefix) {
return OK; return OK;
} }
int deleteOldServers(char *mess, char *newServerName, char *errorPrefix) { int deleteOldServers(char *mess, char *newServerPath, char *errorPrefix) {
// get path of current binary // get path of current binary
char path[MAX_STR_LENGTH]; char currentBinary[MAX_STR_LENGTH];
memset(path, 0, MAX_STR_LENGTH); memset(currentBinary, 0, MAX_STR_LENGTH);
ssize_t len = readlink("/proc/self/exe", path, MAX_STR_LENGTH - 1); ssize_t len = readlink("/proc/self/exe", currentBinary, MAX_STR_LENGTH - 1);
if (len < 0) { if (len < 0) {
LOG(logWARNING, ("(%s): Could not delete old servers. Could not " LOG(logWARNING, ("(%s): Could not delete old servers. Could not "
"readlink current binary\n", "readlink current binary\n",
errorPrefix)); errorPrefix));
return FAIL; return FAIL;
} }
path[len] = '\0'; currentBinary[len] = '\0';
LOG(logINFO, ("Current binary:%s\n", path)); LOG(logDEBUG1, ("Current binary:%s\n", currentBinary));
// resolve double slashes to compare
char *newBinary = newServerPath;
while (newBinary[0] == '/' && newBinary[1] == '/') {
++newBinary;
}
// if current binary same as new server name, replaced anyway // if current binary same as new server name, replaced anyway
if (strcmp(path, newServerName)) { if (strcmp(currentBinary, newBinary)) {
if (deleteFile(mess, path, errorPrefix) == FAIL) { if (deleteFile(mess, currentBinary, errorPrefix) == FAIL) {
LOG(logWARNING, LOG(logWARNING,
("(%s). Could not delete old servers\n", errorPrefix)); ("(%s). Could not delete old servers\n", errorPrefix));
return FAIL; return FAIL;