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
_______________________________________________
sup-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/sup-talk