Skip to content

Commit

Permalink
Don't do /proc file hack if system doesn't support /proc.
Browse files Browse the repository at this point in the history
Assume system supports /proc only if statfs & PROC_SUPER_MAGIC exist.
  • Loading branch information
gwsw committed Aug 24, 2021
1 parent d458cdf commit 004d241
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 33 deletions.
41 changes: 12 additions & 29 deletions ch.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern dev_t curr_dev;
extern ino_t curr_ino;
#endif

#if HAVE_STATFS
#if HAVE_PROCFS
#include <sys/statfs.h>
#endif

Expand Down Expand Up @@ -688,30 +688,6 @@ ch_setbufspace(bufspace)
}
}

/*
*/
static int
trust_size(file, fsize)
int file;
POSITION fsize;
{
if (fsize != 0)
{
/* Nontrustable files always say their size is 0, so this isn't one. */
return 1;
}
#if HAVE_STATFS
/* Cannot trust procfs files. */
struct statfs st;
if (fstatfs(file, &st) == 0)
return (st.f_type != PROC_SUPER_MAGIC);
#else
(void) file;
#endif
/* If we can't tell the file type, be safe and say it's not trustable. */
return 0;
}

/*
* Flush (discard) any saved file state, including buffer contents.
*/
Expand Down Expand Up @@ -753,17 +729,24 @@ ch_flush(VOID_PARAM)
ch_block = 0; /* ch_fpos / LBUFSIZE; */
ch_offset = 0; /* ch_fpos % LBUFSIZE; */

#if 1
#if HAVE_PROCFS
/*
* This is a kludge to workaround a Linux kernel bug: files in
* /proc have a size of 0 according to fstat() but have readable
* data. They are sometimes, but not always, seekable.
* Force them to be non-seekable here.
*/
if (!trust_size(ch_file, ch_fsize))
if (ch_fsize == 0)
{
ch_fsize = NULL_POSITION;
ch_flags &= ~CH_CANSEEK;
struct statfs st;
if (fstatfs(ch_file, &st) == 0)
{
if (st.f_type == PROC_SUPER_MAGIC)
{
ch_fsize = NULL_POSITION;
ch_flags &= ~CH_CANSEEK;
}
}
}
#endif

Expand Down
8 changes: 4 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,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_STATFS],
[Define HAVE_STATFS if have have fstatfs with f_type.])
AH_TEMPLATE([HAVE_PROCFS],
[Define HAVE_PROCFS if have have fstatfs with f_type and PROC_SUPER_MAGIC.])

This comment has been minimized.

Copy link
@polluks2

polluks2 Aug 31, 2021

"have have"?

AH_TEMPLATE([HAVE_TIME_T],
[Define HAVE_TIME_T if your system supports the "time_t" type.])
AH_TEMPLATE([HAVE_STRERROR],
Expand Down Expand Up @@ -268,10 +268,10 @@ 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 statfs)
AC_MSG_CHECKING(for procfs)
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_STATFS)], [AC_MSG_RESULT(no)])
[AC_MSG_RESULT(yes); AC_DEFINE(HAVE_PROCFS)], [AC_MSG_RESULT(no)])

# Checks for ANSI function prototypes.
AC_MSG_CHECKING(for ANSI function prototypes)
Expand Down

0 comments on commit 004d241

Please sign in to comment.