@@ -867,11 +867,9 @@ int main(string[] cliArgs) {
867
867
performFileSystemMonitoring = true ;
868
868
869
869
// What are the current values for the platform we are running on
870
- // Max number of open files /proc/sys/fs/file-max
871
- string maxOpenFiles = strip(readText(" /proc/sys/fs/file-max" ));
870
+ string maxOpenFiles = strip(getMaxOpenFiles());
872
871
// What is the currently configured maximum inotify watches that can be used
873
- // /proc/sys/fs/inotify/max_user_watches
874
- string maxInotifyWatches = strip(readText(" /proc/sys/fs/inotify/max_user_watches" ));
872
+ string maxInotifyWatches = strip(getMaxInotifyWatches());
875
873
876
874
// Start the monitor process
877
875
addLogEntry(" OneDrive synchronisation interval (seconds): " ~ to! string (appConfig.getValueLong(" monitor_interval" )));
@@ -1238,6 +1236,54 @@ int main(string[] cliArgs) {
1238
1236
}
1239
1237
}
1240
1238
1239
+ // Retrieves the maximum number of open files allowed by the system
1240
+ string getMaxOpenFiles () {
1241
+ version (Linux) {
1242
+ try {
1243
+ // Read max open files from procfs on Linux
1244
+ return strip (readText(" /proc/sys/fs/file-max" ));
1245
+ } catch (Exception e) {
1246
+ return " Unknown (Error reading /proc/sys/fs/file-max)" ;
1247
+ }
1248
+ } else version (FreeBSD ) {
1249
+ try {
1250
+ // Read max open files using sysctl on FreeBSD
1251
+ return strip (executeShell(" sysctl -n kern.maxfiles" ).output);
1252
+ } catch (Exception e) {
1253
+ return " Unknown (sysctl error)" ;
1254
+ }
1255
+ } else version (OpenBSD ) {
1256
+ try {
1257
+ // Read max open files using sysctl on OpenBSD
1258
+ return strip (executeShell(" sysctl -n kern.maxfiles" ).output);
1259
+ } catch (Exception e) {
1260
+ return " Unknown (sysctl error)" ;
1261
+ }
1262
+ } else {
1263
+ return " Unsupported platform" ;
1264
+ }
1265
+ }
1266
+
1267
+ // Retrieves the maximum inotify watches allowed (Linux) or a placeholder for other platforms
1268
+ string getMaxInotifyWatches () {
1269
+ version (Linux) {
1270
+ try {
1271
+ // Read max inotify watches from procfs on Linux
1272
+ return strip (readText(" /proc/sys/fs/inotify/max_user_watches" ));
1273
+ } catch (Exception e) {
1274
+ return " Unknown (Error reading /proc/sys/fs/inotify/max_user_watches)" ;
1275
+ }
1276
+ } else version (FreeBSD ) {
1277
+ // FreeBSD uses kqueue instead of inotify, no direct equivalent
1278
+ return " N/A (uses kqueue)" ;
1279
+ } else version (OpenBSD ) {
1280
+ // OpenBSD uses kqueue instead of inotify, no direct equivalent
1281
+ return " N/A (uses kqueue)" ;
1282
+ } else {
1283
+ return " Unsupported platform" ;
1284
+ }
1285
+ }
1286
+
1241
1287
// Print error message when --sync or --monitor has not been used and no valid 'no-sync' operation was requested
1242
1288
void printMissingOperationalSwitchesError () {
1243
1289
// notify the user that --sync or --monitor were missing
0 commit comments