summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-10-26 21:16:43 +0100
committercgzones <cgzones@googlemail.com>2020-10-29 22:21:42 +0100
commitbbf01054bf943db4394027d77915f9625ebde81e (patch)
treeee5e94bd207c2c0df8e11792064c694b27de8d02
parent049046c700ea42e8f9bb77f5efbb5a66ed3c4651 (diff)
Add compat wrapper for fstatat
-rw-r--r--Compat.c46
-rw-r--r--Compat.h19
-rw-r--r--Makefile.am2
-rw-r--r--configure.ac2
-rw-r--r--freebsd/FreeBSDProcessList.c5
5 files changed, 71 insertions, 3 deletions
diff --git a/Compat.c b/Compat.c
new file mode 100644
index 00000000..25aa9f73
--- /dev/null
+++ b/Compat.c
@@ -0,0 +1,46 @@
+/*
+htop - Compat.c
+(C) 2020 Christian Göttsche
+Released under the GNU GPLv2, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "config.h" // IWYU pragma: keep
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "Compat.h"
+#ifndef HAVE_FSTATAT
+#include "XUtils.h"
+#endif
+
+
+int Compat_fstatat(int dirfd,
+ const char* dirpath,
+ const char* pathname,
+ struct stat* statbuf,
+ int flags) {
+
+#ifdef HAVE_FSTATAT
+
+ (void)dirpath;
+
+ return fstatat(dirfd, pathname, statbuf, flags);
+
+#else
+
+ (void)dirfd;
+
+ char path[4096];
+ xSnprintf(path, sizeof(path), "%s/%s", dirpath, pathname);
+
+ if (flags & AT_SYMLINK_NOFOLLOW)
+ return lstat(path, statbuf);
+
+ return stat(path, statbuf);
+
+#endif
+}
diff --git a/Compat.h b/Compat.h
new file mode 100644
index 00000000..c9fd0e62
--- /dev/null
+++ b/Compat.h
@@ -0,0 +1,19 @@
+#ifndef HEADER_Compat
+#define HEADER_Compat
+/*
+htop - Compat.h
+(C) 2020 Christian Göttsche
+Released under the GNU GPLv2, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include <sys/stat.h>
+
+
+int Compat_fstatat(int dirfd,
+ const char* dirpath,
+ const char* pathname,
+ struct stat* statbuf,
+ int flags);
+
+#endif /* HEADER_Compat */
diff --git a/Makefile.am b/Makefile.am
index d5b05d06..e7582e71 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -26,6 +26,7 @@ myhtopsources = \
ColorsPanel.c \
ColumnsPanel.c \
CommandScreen.c \
+ Compat.c \
CPUMeter.c \
CRT.c \
DateMeter.c \
@@ -79,6 +80,7 @@ myhtopheaders = \
ColorsPanel.h \
ColumnsPanel.h \
CommandScreen.h \
+ Compat.h \
DateMeter.h \
DateTimeMeter.h \
DiskIOMeter.h \
diff --git a/configure.ac b/configure.ac
index 70289a78..b70a509f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -88,7 +88,7 @@ AC_TYPE_UID_T
# ----------------------------------------------------------------------
AC_FUNC_CLOSEDIR_VOID
AC_FUNC_STAT
-AC_CHECK_FUNCS([memmove strncasecmp strstr strdup])
+AC_CHECK_FUNCS([fstatat memmove strncasecmp strstr strdup])
save_cflags="${CFLAGS}"
CFLAGS="${CFLAGS} -std=c99"
diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c
index 4c418114..df06546c 100644
--- a/freebsd/FreeBSDProcessList.c
+++ b/freebsd/FreeBSDProcessList.c
@@ -22,6 +22,7 @@ in the source distribution for its full text.
#include <sys/types.h>
#include <sys/user.h>
+#include "Compat.h"
#include "CRT.h"
#include "FreeBSDProcess.h"
#include "Macros.h"
@@ -338,7 +339,7 @@ static void FreeBSDProcessList_scanTTYs(ProcessList* pl) {
continue;
struct stat info;
- if (fstatat(dirFd, entry->d_name, &info, 0) < 0)
+ if (Compat_fstatat(dirFd, "/dev", entry->d_name, &info, 0) < 0)
continue;
if (!S_ISCHR(info.st_mode))
@@ -365,7 +366,7 @@ err1:
const struct dirent* entry;
while ((entry = readdir(dirPtr))) {
struct stat info;
- if (fstatat(dirFd, entry->d_name, &info, 0) < 0)
+ if (Compat_fstatat(dirFd, "/dev/pts", entry->d_name, &info, 0) < 0)
continue;
if (!S_ISCHR(info.st_mode))