aboutsummaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2024-01-10 11:17:08 +0100
committerDaniel Lange <DLange@git.local>2024-01-10 11:17:08 +0100
commite7372d18a1a661d8c3dba9f51e1f17b5f94171a7 (patch)
treee8270dd60ec096bee8157dbadf029e15ed584592 /generic
parent937052b231259a47d881d539ad5748245ef55b99 (diff)
downloaddebian_htop-e7372d18a1a661d8c3dba9f51e1f17b5f94171a7.tar.gz
debian_htop-e7372d18a1a661d8c3dba9f51e1f17b5f94171a7.tar.bz2
debian_htop-e7372d18a1a661d8c3dba9f51e1f17b5f94171a7.zip
New upstream version 3.3.0
Diffstat (limited to 'generic')
-rw-r--r--generic/fdstat_sysctl.c80
-rw-r--r--generic/fdstat_sysctl.h13
-rw-r--r--generic/gettime.c1
-rw-r--r--generic/hostname.c1
-rw-r--r--generic/uname.c1
5 files changed, 96 insertions, 0 deletions
diff --git a/generic/fdstat_sysctl.c b/generic/fdstat_sysctl.c
new file mode 100644
index 0000000..ea374fb
--- /dev/null
+++ b/generic/fdstat_sysctl.c
@@ -0,0 +1,80 @@
+/*
+htop - generic/fdstat_sysctl.c
+(C) 2022-2023 htop dev team
+Released under the GNU GPLv2+, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "config.h" // IWYU pragma: keep
+
+#include "generic/fdstat_sysctl.h"
+
+#include <math.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#include <sys/types.h> // Shitty FreeBSD upstream headers
+#include <sys/sysctl.h>
+
+
+static void Generic_getFileDescriptors_sysctl_internal(
+ const char* sysctlname_maxfiles,
+ const char* sysctlname_numfiles,
+ size_t size_header,
+ size_t size_entry,
+ double* used,
+ double* max
+) {
+ *used = NAN;
+ *max = 65536;
+
+ int max_fd, open_fd;
+ size_t len;
+
+ len = sizeof(max_fd);
+ if (sysctlname_maxfiles && sysctlbyname(sysctlname_maxfiles, &max_fd, &len, NULL, 0) == 0) {
+ if (max_fd) {
+ *max = max_fd;
+ } else {
+ *max = NAN;
+ }
+ }
+
+ len = sizeof(open_fd);
+ if (sysctlname_numfiles && sysctlbyname(sysctlname_numfiles, &open_fd, &len, NULL, 0) == 0) {
+ *used = open_fd;
+ return;
+ }
+
+ // If no sysctl arc available, try to guess from the file table size at kern.file
+ // The size per entry differs per OS, thus skip if we don't know:
+ if (!size_entry)
+ return;
+
+ len = 0;
+ if (sysctlbyname("kern.file", NULL, &len, NULL, 0) < 0)
+ return;
+
+ if (len < size_header)
+ return;
+
+ *used = (len - size_header) / size_entry;
+}
+
+void Generic_getFileDescriptors_sysctl(double* used, double* max) {
+#if defined(HTOP_DARWIN)
+ Generic_getFileDescriptors_sysctl_internal(
+ "kern.maxfiles", "kern.num_files", 0, 0, used, max);
+#elif defined(HTOP_DRAGONFLY)
+ Generic_getFileDescriptors_sysctl_internal(
+ "kern.maxfiles", NULL, 0, sizeof(struct kinfo_file), used, max);
+#elif defined(HTOP_FREEBSD)
+ Generic_getFileDescriptors_sysctl_internal(
+ "kern.maxfiles", "kern.openfiles", 0, 0, used, max);
+#elif defined(HTOP_NETBSD)
+ Generic_getFileDescriptors_sysctl_internal(
+ "kern.maxfiles", NULL, 0, sizeof(struct kinfo_file), used, max);
+#else
+#error Unknown platform: Please implement proper way to query open/max file information
+#endif
+}
diff --git a/generic/fdstat_sysctl.h b/generic/fdstat_sysctl.h
new file mode 100644
index 0000000..107fcab
--- /dev/null
+++ b/generic/fdstat_sysctl.h
@@ -0,0 +1,13 @@
+#ifndef HEADER_fdstat_sysctl
+#define HEADER_fdstat_sysctl
+/*
+htop - generic/fdstat_sysctl.h
+(C) 2022-2023 htop dev team
+Released under the GNU GPLv2+, see the COPYING file
+in the source distribution for its full text.
+*/
+
+
+void Generic_getFileDescriptors_sysctl(double* used, double* max);
+
+#endif
diff --git a/generic/gettime.c b/generic/gettime.c
index b7c4885..209f523 100644
--- a/generic/gettime.c
+++ b/generic/gettime.c
@@ -4,6 +4,7 @@ htop - generic/gettime.c
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
+
#include "config.h" // IWYU pragma: keep
#include "generic/gettime.h"
diff --git a/generic/hostname.c b/generic/hostname.c
index 69a4146..e327582 100644
--- a/generic/hostname.c
+++ b/generic/hostname.c
@@ -4,6 +4,7 @@ htop - generic/hostname.c
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
+
#include "config.h" // IWYU pragma: keep
#include "generic/hostname.h"
diff --git a/generic/uname.c b/generic/uname.c
index 2a734dc..b5bb583 100644
--- a/generic/uname.c
+++ b/generic/uname.c
@@ -4,6 +4,7 @@ htop - generic/uname.c
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
+
#include "config.h" // IWYU pragma: keep
#include "generic/uname.h"

© 2014-2024 Faster IT GmbH | imprint | privacy policy