saleyn / erlexec

Execute and control OS processes from Erlang/OTP
https://hexdocs.pm/erlexec/readme.html
Other
541 stars 141 forks source link

empty input breaks the driver #119

Closed xinhaoyuan closed 5 years ago

xinhaoyuan commented 5 years ago

Example:

test_empty_data() ->
    {ok, P, I} = exec:run("/bin/bash --norc -i", [stdin, stdout, pty, monitor]),
    exec:send(I, <<>>),
    exec:send(I, <<"exit\n">>),
    ?receiveMatch({'DOWN', _, process, P, normal}, 1000).

One way to fix it is simply ignoring any zero-length input. Here is my patch:

diff --git a/c_src/exec.cpp b/c_src/exec.cpp
index 405b3f5..752e371 100644
--- a/c_src/exec.cpp
+++ b/c_src/exec.cpp
@@ -442,6 +442,13 @@ bool process_command()
                 break;
             }

+            if (data.size() == 0) {
+                if (debug) {
+                    fprintf(stderr, "Warning: ignore empty input.\r\n");
+                }
+                break;
+            }
+
             it->second.stdin_queue.push_front(data);
             process_pid_input(it->second);
             break;
saleyn commented 5 years ago

Thank you. Fixed.