From: chrisw@rice.edu (Christopher Warrington)
Subject: [sup-talk] [PATCH] shell commands are now run in a child process
Date: Sun, 3 Feb 2008 02:11:12 -0600 [thread overview]
Message-ID: <1202026272-3432-2-git-send-email-chrisw@rice.edu> (raw)
When shelling out, the external command is now run in a child process.
Before the external command is run, all (I hope) of sup's open files are
closed first.
This should fix the ferret "Permission denied" errors on Windows.
---
lib/sup/buffer.rb | 27 ++++++++++++++++++++++++++-
1 files changed, 26 insertions(+), 1 deletions(-)
diff --git a/lib/sup/buffer.rb b/lib/sup/buffer.rb
index 4374fa8..7768011 100644
--- a/lib/sup/buffer.rb
+++ b/lib/sup/buffer.rb
@@ -696,11 +696,36 @@ EOS
draw_screen :refresh => true
end
+ ## There is no good way that I can find the get the maximum fd allowed.
+ ## On the POSIX systems I have played with, 500 seems to be the maximum. On Windows,
+ ## 2048 is the documented maximum (for the C Runtime Library).
+ MAX_FD = 2048
+
def shell_out command
@shelled = true
Ncurses.sync do
Ncurses.endwin
- system command
+
+ child_pid = fork
+ if child_pid == nil
+ ## child process
+
+ start_fd = 1 + [STDIN.fileno, STDOUT.fileno, STDERR.fileno].max # don't close these
+ start_fd.upto(MAX_FD) do |fd|
+ begin
+ IO.for_fd(fd).close
+ rescue Errno::EBADF
+ ## fd is not open: ignore and move on
+ end
+ end
+
+ exec(command)
+ ## never gets here
+ else
+ ## sup process
+ Process.waitpid(child_pid, Process::WUNTRACED) # catch an already dead child
+ end
+
Ncurses.refresh
Ncurses.curs_set 0
end
--
1.5.3.8
next reply other threads:[~2008-02-03 8:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-03 8:11 Christopher Warrington [this message]
2008-02-05 17:34 ` William Morgan
2008-02-05 19:29 ` Christopher Warrington
2008-02-05 20:12 ` William Morgan
2008-02-08 9:40 ` Christopher Warrington
2008-02-19 17:48 ` William Morgan
2008-02-25 17:48 William Morgan
2008-03-01 4:42 ` Christopher Warrington
2008-03-01 20:37 ` William Morgan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1202026272-3432-2-git-send-email-chrisw@rice.edu \
--to=chrisw@rice.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox