From 72205e6017733e8b719bf6f20bd530d0628454e0 Mon Sep 17 00:00:00 2001 From: Lennon Zamora Date: Wed, 20 Nov 2024 12:20:29 -0600 Subject: [PATCH 1/2] added OpenBSD dependencies section to get onedrive to build and run on that platform --- docs/install.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/install.md b/docs/install.md index 1fddce404..990f27ec7 100644 --- a/docs/install.md +++ b/docs/install.md @@ -170,6 +170,36 @@ For notifications the following is also necessary: sudo zypper install libnotify-devel ``` +### Dependencies: OpenBSD +Generally you will want to install the same dependencies as the [FreeBSD port](https://www.freshports.org/net/onedrive/) +> [!CAUTION] +> Not all FreeBSD port paths and names are exactly the same but they are close enough that you should be able to find the equivalent in the OpenBSD port tree + +1. Install either DMD or LDC compiler via ports. Have not tested using LDC but contrary to other OS instructions, DMD does not need to be "activated" on OpenBSD. After installing from ports, it will just work. +2. Install `git` from ports +3. Install dependencies listed for FreeBSD. Some are installed in the baseline system, others are packages, and still others are ports. +4. Install `libinotify` from ports. + +The base installation of OpenBSD uses `ksh` instead of `bash` so when running the `configure` scripts from the repo, be sure to run them something like this: +```text +$bash configure +``` +After configuring the `Makefile` with the `configure` script, you will need to modify it manually. +1. On line 110, remove the section `-L-ldl`. This library is Linux only and OpenBSD already has the necessary equivilant as part of the base system libraries. +2. On line 27 (`notify_LIBS` var), add `-L/usr/local/lib/inotify -linotify` to the line. + +At this point, you should be able to: +> [!CAUTION] +> Using DMD, you may run into an "our of memory" type error during compile. This is due to the extra security layers of OpenBSD and their "login class database" parameters. Check out `man login.conf` for more details but generally you will be looking for a `datasize-cur` and `datasize-max` setting under whichever login class your build user belongs to; most likely `default:`, so start there. + +```text +$gmake clean; gmake; +``` +As instructed in the installation documentation (swaping `make` for `gmake` as is necessary for OpenBSD). However, you will not be able to run `onedrive` yet as there is a minor `ld.so` quirk you need to fix: +1. The `libinotify` port installs into a subdirectory of `/usr/local/lib` so it is not picked up by the default `ld.so` "hints" or search paths. +2. Use `ldconfig` to modify the shared library search path. There are a number of ways to do this so check out `man ldconfig` for your prefered way to do it. +3. `ldconfig -m /usr/local/lib/inotify` is one simple way for example + ## Compilation & Installation ### High Level Steps 1. Install the platform dependencies for your Linux OS From cf9102b914ee7ec85feb66acc0c921612c838562 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Wed, 11 Dec 2024 06:42:30 +1100 Subject: [PATCH 2/2] Update how maximum open files and watches is determined * Use getMaxOpenFiles() to get the maximum number of open files allowed by the system, supporting Linux, OpenBSD and FreeBSD * Use getMaxInotifyWatches() to get the maximum inotify watches allowed (Linux) or advise kqueue is used for OpenBSD or FreeBSD --- src/main.d | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/src/main.d b/src/main.d index ebbae39fb..d2bd9983f 100644 --- a/src/main.d +++ b/src/main.d @@ -867,11 +867,9 @@ int main(string[] cliArgs) { performFileSystemMonitoring = true; // What are the current values for the platform we are running on - // Max number of open files /proc/sys/fs/file-max - string maxOpenFiles = strip(readText("/proc/sys/fs/file-max")); + string maxOpenFiles = strip(getMaxOpenFiles()); // What is the currently configured maximum inotify watches that can be used - // /proc/sys/fs/inotify/max_user_watches - string maxInotifyWatches = strip(readText("/proc/sys/fs/inotify/max_user_watches")); + string maxInotifyWatches = strip(getMaxInotifyWatches()); // Start the monitor process addLogEntry("OneDrive synchronisation interval (seconds): " ~ to!string(appConfig.getValueLong("monitor_interval"))); @@ -1236,6 +1234,55 @@ int main(string[] cliArgs) { } } +// Retrieves the maximum number of open files allowed by the system. +string getMaxOpenFiles() { + version (Linux) { + try { + // Read max open files from procfs on Linux + return strip(readText("/proc/sys/fs/file-max")); + } catch (Exception e) { + return "Unknown (Error reading /proc/sys/fs/file-max)"; + } + } else version (FreeBSD) { + try { + // Read max open files using sysctl on FreeBSD + return strip(executeShell("sysctl -n kern.maxfiles").output); + } catch (Exception e) { + return "Unknown (sysctl error)"; + } + } else version (OpenBSD) { + try { + // Read max open files using sysctl on OpenBSD + return strip(executeShell("sysctl -n kern.maxfiles").output); + } catch (Exception e) { + return "Unknown (sysctl error)"; + } + } else { + return "Unsupported platform"; + } +} + +// Retrieves the maximum inotify watches allowed (Linux) or a placeholder for other platforms. +string getMaxInotifyWatches() { + version (Linux) { + try { + // Read max inotify watches from procfs on Linux + return strip(readText("/proc/sys/fs/inotify/max_user_watches")); + } catch (Exception e) { + return "Unknown (Error reading /proc/sys/fs/inotify/max_user_watches)"; + } + } else version (FreeBSD) { + // FreeBSD uses kqueue instead of inotify, no direct equivalent + return "N/A (uses kqueue)"; + } else version (OpenBSD) { + // OpenBSD uses kqueue instead of inotify, no direct equivalent + return "N/A (uses kqueue)"; + } else { + return "Unsupported platform"; + } +} + + // Print error message when --sync or --monitor has not been used and no valid 'no-sync' operation was requested void printMissingOperationalSwitchesError() { // notify the user that --sync or --monitor were missing