actually writing the server binary from memory to file before linking, sycing, permissions etc

This commit is contained in:
2021-11-10 17:48:18 +01:00
parent 4a8c365447
commit 32d664a77d
11 changed files with 39 additions and 5 deletions

View File

@ -493,4 +493,27 @@ int setupDetectorServer(char *mess, char *sname) {
}
LOG(logINFO, ("\tsync\n"));
return OK;
}
int writeBinaryFile(char* mess, char* fname, char* buffer, uint64_t filesize) {
FILE *fp = fopen(fname, "wb");
if (fp == NULL) {
sprintf(mess, "Could not copy detector server. (writing to file)\n");
LOG(logERROR, (mess));
return FAIL;
}
size_t bytesWritten = fwrite(buffer, 1, filesize, fp);
if (bytesWritten != (size_t)filesize) {
sprintf(mess, "Could not copy detector server. Expected to write %lu bytes, wrote %lu bytes)\n", (long unsigned int)filesize, (long unsigned int)bytesWritten);
LOG(logERROR, (mess));
return FAIL;
}
if (fclose(fp) != 0) {
sprintf(mess, "Could not copy detector server. (closing file pointer)\n");
LOG(logERROR, (mess));
return FAIL;
}
LOG(logINFO, ("\tWritten server binary to %s (%lu bytes)\n", fname, (long unsigned int)bytesWritten));
return OK;
}