mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-02-15 18:08:41 +01:00
Experimental support for using the client on macOS (Darwin) (#1321)
* shorter SHM names on macOS * fix segfault on macOS when string is empty * apple version of read exe path * ifdef for linux specific API * fixed test for shm and udp socket * updated release notes
This commit is contained in:
@@ -10,11 +10,16 @@
|
||||
#include <ios>
|
||||
#include <iostream>
|
||||
#include <libgen.h> // dirname
|
||||
#include <limits.h>
|
||||
#include <sstream>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h> //readlink
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <mach-o/dyld.h>
|
||||
#endif
|
||||
|
||||
namespace sls {
|
||||
|
||||
int readDataFile(std::ifstream &infile, short int *data, int nch, int offset) {
|
||||
@@ -246,21 +251,40 @@ std::vector<int> getChannelsFromFile(const std::string &fname) {
|
||||
}
|
||||
|
||||
std::string getAbsolutePathFromCurrentProcess(const std::string &fname) {
|
||||
|
||||
if (fname[0] == '/') {
|
||||
return fname;
|
||||
}
|
||||
|
||||
// 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);
|
||||
//in case PATH_MAX defines the longest possible path on linux and macOS
|
||||
//use string instead of char array to avoid overflow
|
||||
std::string path(PATH_MAX, '\0');
|
||||
|
||||
|
||||
#if defined(__APPLE__)
|
||||
uint32_t size = PATH_MAX;
|
||||
if (_NSGetExecutablePath(path.data(), &size) != 0) {
|
||||
throw std::runtime_error("Failed to get executable path");
|
||||
}
|
||||
// Resolve any symlinks and .. components
|
||||
std::string resolved(PATH_MAX, '\0');
|
||||
if (!realpath(path.data(), resolved.data())) {
|
||||
throw std::runtime_error("realpath failed for executable");
|
||||
}
|
||||
path = resolved;
|
||||
#else
|
||||
|
||||
|
||||
ssize_t len = readlink("/proc/self/exe", path.data(), PATH_MAX - 1);
|
||||
if (len < 0) {
|
||||
throw RuntimeError("Could not get absolute path for " + fname);
|
||||
}
|
||||
path[len] = '\0';
|
||||
|
||||
#endif
|
||||
|
||||
// get dir path and attach file name
|
||||
std::string absPath = (std::string(dirname(path)) + '/' + fname);
|
||||
std::string absPath = (std::string(dirname(path.data())) + '/' + fname);
|
||||
return absPath;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#include <netdb.h>
|
||||
#include <sstream>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
@@ -178,6 +177,12 @@ IpAddr InterfaceNameToIp(const std::string &ifn) {
|
||||
}
|
||||
|
||||
MacAddr InterfaceNameToMac(const std::string &inf) {
|
||||
|
||||
#ifdef __APPLE__
|
||||
throw RuntimeError(
|
||||
"InterfaceNameToMac not implemented on macOS yet");
|
||||
#else
|
||||
|
||||
// TODO! Copied from genericSocket needs to be refactored!
|
||||
struct ifreq ifr;
|
||||
char mac[32];
|
||||
@@ -203,6 +208,7 @@ MacAddr InterfaceNameToMac(const std::string &inf) {
|
||||
close(sock);
|
||||
}
|
||||
return MacAddr(mac);
|
||||
#endif
|
||||
}
|
||||
|
||||
void validatePortNumber(uint16_t port) {
|
||||
|
||||
Reference in New Issue
Block a user