Mercurial > hg > octave-terminal
changeset 10212:56f7734f5448
fix process creation failure handling in system()
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 28 Jan 2010 07:12:59 +0100 |
parents | 1ca904d74f78 |
children | f7ba6cfe7fb7 |
files | src/ChangeLog src/toplev.cc |
diffstat | 2 files changed, 37 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2010-01-28 Jaroslav Hajek <highegg@gmail.com> + + * toplev.cc (run_command_and_return_output): Fix testing of failed + process creation, simplify. + (cleanup_iprocstream): Remove. + 2010-01-27 Jaroslav Hajek <highegg@gmail.com> * pt-eval.cc (do_unwind_protect_cleanup_code): Save
--- a/src/toplev.cc +++ b/src/toplev.cc @@ -753,16 +753,6 @@ // Execute a shell command. -static void -cleanup_iprocstream (void *p) -{ - iprocstream *cmd = static_cast<iprocstream *> (p); - - octave_child_list::remove (cmd->pid ()); - - delete cmd; -} - static int wait_for_input (int fid) { @@ -789,50 +779,48 @@ run_command_and_return_output (const std::string& cmd_str) { octave_value_list retval; + unwind_protect frame; iprocstream *cmd = new iprocstream (cmd_str.c_str ()); - if (cmd) - { - unwind_protect frame; - frame.add (cleanup_iprocstream, cmd); + frame.add_delete (cmd); + frame.add_fcn (octave_child_list::remove, cmd->pid ()); - if (*cmd) - { - int fid = cmd->file_number (); + if (*cmd) + { + int fid = cmd->file_number (); - std::ostringstream output_buf; + std::ostringstream output_buf; - char ch; + char ch; - for (;;) - { - if (cmd->get (ch)) - output_buf.put (ch); - else - { - if (! cmd->eof () && errno == EAGAIN) - { - cmd->clear (); + for (;;) + { + if (cmd->get (ch)) + output_buf.put (ch); + else + { + if (! cmd->eof () && errno == EAGAIN) + { + cmd->clear (); - if (wait_for_input (fid) != 1) - break; - } - else - break; - } - } + if (wait_for_input (fid) != 1) + break; + } + else + break; + } + } - int cmd_status = cmd->close (); + int cmd_status = cmd->close (); - if (WIFEXITED (cmd_status)) - cmd_status = WEXITSTATUS (cmd_status); - else - cmd_status = 127; + if (WIFEXITED (cmd_status)) + cmd_status = WEXITSTATUS (cmd_status); + else + cmd_status = 127; - retval(0) = cmd_status; - retval(1) = output_buf.str (); - } + retval(0) = cmd_status; + retval(1) = output_buf.str (); } else error ("unable to start subprocess for `%s'", cmd_str.c_str ());