mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-24 10:31:09 +02:00
actually writing the server binary from memory to file before linking, sycing, permissions etc
This commit is contained in:
@ -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;
|
||||
}
|
Reference in New Issue
Block a user