Skip to content

Commit

Permalink
Allow use of poll() on APPLE systems if first component of
Browse files Browse the repository at this point in the history
uname release string is 20 or greater.
The poll() bug seems to be fixed on 20.6.0.
I don't know exactly which release fixed in, but assume that
all 20.x releases are fixed and all earlier releases are not.
  • Loading branch information
gwsw committed Dec 10, 2022
1 parent b2e24ea commit fe1526f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ main(argc, argv)
is_tty = isatty(1);
init_mark();
init_cmds();
init_poll();
get_term();
init_charset();
init_line();
Expand Down
22 changes: 19 additions & 3 deletions os.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@
#include <values.h>
#endif

#if HAVE_POLL && !MSDOS_COMPILER && !defined(__APPLE__)
#if defined(__APPLE__)
#include <sys/utsname.h>
#endif

#if HAVE_POLL && !MSDOS_COMPILER
#define USE_POLL 1
static int use_poll = TRUE;
#else
#define USE_POLL 0
#endif
Expand Down Expand Up @@ -78,6 +83,17 @@ extern char *ttyin_name;
#endif /*LESSTEST*/

#if USE_POLL
public void
init_poll(VOID_PARAM)
{
#if defined(__APPLE__)
/* In old versions of MacOS, poll() does not work with /dev/tty. */
struct utsname uts;
if (uname(&uts) < 0 || lstrtoi(uts.release, NULL, 10) < 20)
use_poll = FALSE;
#endif
}

/*
* Check whether data is available, either from a file/pipe or from the tty.
* Return READ_AGAIN if no data currently available, but caller should retry later.
Expand Down Expand Up @@ -120,7 +136,7 @@ check_poll(fd, tty)
supports_ctrl_x(VOID_PARAM)
{
#if USE_POLL
return (TRUE);
return (use_poll);
#else
return (FALSE);
#endif /* USE_POLL */
Expand Down Expand Up @@ -203,7 +219,7 @@ iread(fd, buf, len)
}
#endif
#if USE_POLL
if (fd != tty)
if (fd != tty && use_poll)
{
int ret = check_poll(fd, tty);
if (ret != 0)
Expand Down

0 comments on commit fe1526f

Please sign in to comment.