Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v592+ breaks procfs reads #282

Closed
xpenev opened this issue Sep 20, 2022 · 1 comment
Closed

v592+ breaks procfs reads #282

xpenev opened this issue Sep 20, 2022 · 1 comment

Comments

@xpenev
Copy link

xpenev commented Sep 20, 2022

Files like /proc/cpuinfo cannot be read starting v592

$ echo $(./less --version | sed q; ./less /proc/cpuinfo | wc -c) bytes read
less 609x (POSIX regular expressions) 0 bytes read

In older versions, this used to work

$ echo $(less --version | sed q; less /proc/cpuinfo | wc -c) bytes read
less 590 (PCRE2 regular expressions) 12528 bytes read

The HAVE_PROCFS check added in v592 fails[1] on Linux

AC_TRY_COMPILE([#include <sys/statfs.h>],
  [struct statfs s; s.f_type = PROC_SUPER_MAGIC; (void) fstatfs(0,&s); ],
  [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_PROCFS)], [AC_MSG_RESULT(no)])

[1] Tested on:
Linux Bullseye 5.10.0-18-amd64 #1 SMP Debian 5.10.140-1 (2022-09-02) x86_64 GNU/Linux
Linux Gentoo 5.19.9-gentoo

$ gcc -E -fdirectives-only - <<< '#include <sys/statfs.h>' | grep PROC_SUPER_MAGIC
$ gcc -E -fdirectives-only - <<< '#include <linux/magic.h>' | grep PROC_SUPER_MAGIC
#define PROC_SUPER_MAGIC 0x9fa0

Potential Fix:

diff --git a/ch.c b/ch.c
index bfad09c..c5317ba 100644
--- a/ch.c
+++ b/ch.c
@@ -28,6 +28,9 @@ extern ino_t curr_ino;

 #if HAVE_PROCFS
 #include <sys/statfs.h>
+#if HAVE_LINUX_MAGIC
+#include <linux/magic.h>
+#endif
 #endif

 typedef POSITION BLOCKNUM;
diff --git a/configure.ac b/configure.ac
index f7c6481..f849134 100644
--- a/configure.ac
+++ b/configure.ac
@@ -219,6 +219,8 @@ AH_TEMPLATE([HAVE_CONST],
        [Define HAVE_CONST if your compiler supports the "const" modifier.])
 AH_TEMPLATE([HAVE_STAT_INO],
        [Define HAVE_STAT_INO if your struct stat has st_ino and st_dev.])
+AH_TEMPLATE([HAVE_LINUX_MAGIC],
+       [Define HAVE_LINUX_MAGIC if you have linux/magic.h.])
 AH_TEMPLATE([HAVE_PROCFS],
        [Define HAVE_PROCFS if have have fstatfs with f_type and PROC_SUPER_MAGIC.])
 AH_TEMPLATE([HAVE_TIME_T],
@@ -270,8 +272,15 @@ AC_TRY_COMPILE([#include <sys/types.h>
 #include <sys/stat.h>],
   [struct stat s; dev_t dev = s.st_dev; ino_t ino = s.st_ino;],
   [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_STAT_INO)], [AC_MSG_RESULT(no)])
+AC_MSG_CHECKING(for magic.h)
+AC_TRY_COMPILE([#include <linux/magic.h>], [int magic = PROC_SUPER_MAGIC;],
+  [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_LINUX_MAGIC)], [AC_MSG_RESULT(no)])
 AC_MSG_CHECKING(for procfs)
-AC_TRY_COMPILE([#include <sys/statfs.h>],
+AC_TRY_COMPILE([
+#include <sys/statfs.h>
+#ifdef HAVE_LINUX_MAGIC
+#include <linux/magic.h>
+#endif],
   [struct statfs s; s.f_type = PROC_SUPER_MAGIC; (void) fstatfs(0,&s); ],
   [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_PROCFS)], [AC_MSG_RESULT(no)])

@xpenev xpenev changed the title v592 breaks procfs reads v592+ breaks procfs reads Sep 20, 2022
@gwsw
Copy link
Owner

gwsw commented Sep 25, 2022

This should be fixed in 03f011f.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants