Don't use select() in interactive python shell

This fixes the python interactive shell when running under
sel_ldr (in this case select() will always return ENOSYS
which python doesn't handle and we end up an infinite loop).

This wasn't a problem in the past since we didn't include
nacl_io on the link line, and hence python didn't compile
with select() support.

R=bradnelson@google.com

Review URL: https://codereview.chromium.org/1066763002
diff --git a/ports/python/nacl.patch b/ports/python/nacl.patch
index 674bd35..0f6d064 100644
--- a/ports/python/nacl.patch
+++ b/ports/python/nacl.patch
@@ -409,7 +409,7 @@
  int
  main(int argc, char **argv)
  {
-@@ -20,5 +43,9 @@ main(int argc, char **argv)
+@@ -20,5 +49,9 @@ main(int argc, char **argv)
  	m = fpgetmask();
  	fpsetmask(m & ~FP_X_OFL);
  #endif
@@ -419,6 +419,23 @@
 +#endif
  	return Py_Main(argc, argv);
  }
+diff --git a/Modules/readline.c b/Modules/readline.c
+--- a/Modules/readline.c
++++ b/Modules/readline.c
+@@ -950,7 +950,12 @@ setup_readline(void)
+ /* Wrapper around GNU readline that handles signals differently. */
+ 
+ 
+-#if defined(HAVE_RL_CALLBACK) && defined(HAVE_SELECT)
++/*
++ * Don't use the select()-based readline under Native Client. While select()
++ * is available and compile and link time it will fail at runtime under sel_ldr
++ * since there is no IRT/syscall implemenation of select().
++ */
++#if defined(HAVE_RL_CALLBACK) && defined(HAVE_SELECT) && !defined(__native_client__)
+ 
+ static  char *completed_input_string;
+ static void
 diff --git a/Modules/timemodule.c b/Modules/timemodule.c
 --- a/Modules/timemodule.c
 +++ b/Modules/timemodule.c
diff --git a/ports/python3/nacl.patch b/ports/python3/nacl.patch
index 0325956..e350581 100644
--- a/ports/python3/nacl.patch
+++ b/ports/python3/nacl.patch
@@ -172,6 +172,24 @@
  int
  main(int argc, char **argv)
  {
+diff --git a/Modules/readline.c b/Modules/readline.c
+--- a/Modules/readline.c
++++ b/Modules/readline.c
+@@ -1051,8 +1051,12 @@ setup_readline(readlinestate *mod_state)
+ 
+ /* Wrapper around GNU readline that handles signals differently. */
+ 
+-
+-#if defined(HAVE_RL_CALLBACK) && defined(HAVE_SELECT)
++/*
++ * Don't use the select()-based readline under Native Client. While select()
++ * is available and compile and link time it will fail at runtime under sel_ldr
++ * since there is no IRT/syscall implemenation of select().
++ */
++#if defined(HAVE_RL_CALLBACK) && defined(HAVE_SELECT) && !defined(__native_client__)
+ 
+ static  char *completed_input_string;
+ static void
 diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
 --- a/Modules/signalmodule.c
 +++ b/Modules/signalmodule.c
@@ -265,14 +283,27 @@
 diff --git a/Python/fileutils.c b/Python/fileutils.c
 --- a/Python/fileutils.c
 +++ b/Python/fileutils.c
-@@ -707,6 +707,12 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works)
+@@ -599,6 +599,12 @@ get_inheritable(int fd, int raise)
+ 
+     flags = fcntl(fd, F_GETFD, 0);
+     if (flags == -1) {
++#if defined(__native_client__) && !defined(__GLIBC__)
++        /* When running under NaCl within the sel_ldr this fcntl() will always
++           fail.  However we don't want to completely remove this block since
++           fcntl() is emulated using nacl_io when running within chrome. */
++        return 0;
++#endif
+         if (raise)
+             PyErr_SetFromErrno(PyExc_OSError);
+         return -1;
+@@ -707,6 +713,12 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works)
      /* slow-path: fcntl() requires two syscalls */
      flags = fcntl(fd, F_GETFD);
      if (flags < 0) {
 +#if defined(__native_client__) && !defined(__GLIBC__)
-+        /* When running under NaCl within the sel_ldr this fcntl() will always fail.
-+        i  However we don't want to completely remove this block since fcntl() is
-+           emulated using nacl_io when running within chrome. */
++        /* When running under NaCl within the sel_ldr this fcntl() will always
++           fail.  However we don't want to completely remove this block since
++           fcntl() is emulated using nacl_io when running within chrome. */
 +        return 0;
 +#endif
          if (raise)