diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-02-04 11:28:20 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-04-12 14:58:13 +0900 |
commit | e6551d835febe00fce6c6a3b12c4e394d2a05bd6 (patch) | |
tree | 52face52cd84ec7406e993d5bd227c0d902c9946 /ruby.c | |
parent | f22c4ff359498ab342e4b6d6feb21af6004ee270 (diff) | |
download | ruby-e6551d835febe00fce6c6a3b12c4e394d2a05bd6.tar.gz |
PAGER without fork&exec too [Feature #16754]
Diffstat (limited to 'ruby.c')
-rw-r--r-- | ruby.c | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -1606,12 +1606,12 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) (argc > 0 && argv && argv[0] ? argv[0] : origarg.argc > 0 && origarg.argv && origarg.argv[0] ? origarg.argv[0] : ruby_engine); -#ifdef HAVE_WORKING_FORK if (opt->dump & DUMP_BIT(help)) { const char *pager_env = getenv("RUBY_PAGER"); if (!pager_env) pager_env = getenv("PAGER"); if (pager_env && *pager_env && isatty(0) && isatty(1)) { VALUE pager = rb_str_new_cstr(pager_env); +#ifdef HAVE_WORKING_FORK int fds[2]; if (rb_pipe(fds) == 0) { rb_pid_t pid = fork(); @@ -1632,9 +1632,24 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) rb_waitpid(pid, 0, 0); } } +#else + VALUE port = rb_io_popen(pager, rb_str_new_lit("w"), Qnil, Qnil); + if (!NIL_P(port)) { + int oldout = dup(1); + int olderr = dup(2); + int fd = RFILE(port)->fptr->fd; + dup2(fd, 1); + dup2(fd, 2); + usage(progname, 1); + fflush(stdout); + dup2(oldout, 1); + dup2(olderr, 2); + rb_io_close(port); + return Qtrue; + } +#endif } } -#endif usage(progname, (opt->dump & DUMP_BIT(help))); return Qtrue; } |