mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-21 17:18:00 +02:00
Readlink (#117)
* gotthard config file path using readlink * gotthard2 * eiger * eieger, mnythen3, moench * binaries in * moved readlink to a common function * binaries in
This commit is contained in:
@ -2,6 +2,10 @@
|
||||
#include "clogger.h"
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <libgen.h> // dirname
|
||||
#include <unistd.h> // readlink
|
||||
|
||||
int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin,
|
||||
int outputMax, int inputValue, int *outputValue) {
|
||||
LOG(logDEBUG1, (" Input Value: %d (Input:(%d - %d), Output:(%d - %d))\n",
|
||||
@ -37,3 +41,23 @@ int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin,
|
||||
LOG(logDEBUG1, (" Converted Output Value: %d\n", *outputValue));
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int getAbsPath(char* buf, size_t bufSize, char* fname) {
|
||||
// get path of current binary
|
||||
char path[bufSize];
|
||||
memset(path, 0, bufSize);
|
||||
ssize_t len = readlink("/proc/self/exe", path, bufSize - 1);
|
||||
if (len < 0) {
|
||||
LOG(logWARNING, ("Could not readlink current binary for %s\n", fname));
|
||||
return FAIL;
|
||||
}
|
||||
path[len] = '\0';
|
||||
|
||||
// get dir path and attach config file name
|
||||
char *dir = dirname(path);
|
||||
memset(buf, 0, bufSize);
|
||||
sprintf(buf, "%s/%s", dir, fname);
|
||||
LOG(logDEBUG1, ("full path for %s: %s\n", fname, buf));
|
||||
return OK;
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
#include "clogger.h"
|
||||
#include "slsDetectorServer_defs.h"
|
||||
#include "sls_detector_defs.h"
|
||||
#include "common.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@ -18,19 +19,26 @@ extern uint64_t setPatternWaitTime(int level, uint64_t t);
|
||||
extern void setPatternLoop(int level, int *startAddr, int *stopAddr,
|
||||
int *nLoop);
|
||||
|
||||
int loadDefaultPattern(char *fname) {
|
||||
int loadDefaultPattern(char *patFname) {
|
||||
if (initError == FAIL) {
|
||||
return initError;
|
||||
}
|
||||
|
||||
char fname[128];
|
||||
if (getAbsPath(fname, 128, patFname) == FAIL) {
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
// open config file
|
||||
FILE *fd = fopen(fname, "r");
|
||||
if (fd == NULL) {
|
||||
sprintf(initErrorMessage, "Could not open pattern file [%s].\n", fname);
|
||||
sprintf(initErrorMessage, "Could not open pattern file [%s].\n",
|
||||
patFname);
|
||||
initError = FAIL;
|
||||
LOG(logERROR, ("%s\n\n", initErrorMessage));
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logINFOBLUE, ("Reading default pattern file %s\n", fname));
|
||||
LOG(logINFOBLUE, ("Reading default pattern file %s\n", patFname));
|
||||
|
||||
// Initialization
|
||||
const size_t LZ = 256;
|
||||
|
Reference in New Issue
Block a user