aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/src
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2016-09-05 17:08:40 +0200
committerLukas Larsson <[email protected]>2016-09-05 17:08:40 +0200
commitbb8d105fd6d5b09097dc64b341d63f0f8d7e8906 (patch)
treec3525db7d9b99e3048eedf3f6a16fe2cb46689e9 /lib/kernel/src
parentc26f34c7c8940de2ade904d86e581f2c7463549f (diff)
parentc0ed19c1261ee281d3c8f36ec3f28fa7328f0f39 (diff)
downloadotp-bb8d105fd6d5b09097dc64b341d63f0f8d7e8906.tar.gz
otp-bb8d105fd6d5b09097dc64b341d63f0f8d7e8906.tar.bz2
otp-bb8d105fd6d5b09097dc64b341d63f0f8d7e8906.zip
Merge branch 'lukas/kernel/os_cmd_fix_stdin_close/OTP-13867' into maint
* lukas/kernel/os_cmd_fix_stdin_close/OTP-13867: kernel: Close stdin of commands run in os:cmd
Diffstat (limited to 'lib/kernel/src')
-rw-r--r--lib/kernel/src/os.erl14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/kernel/src/os.erl b/lib/kernel/src/os.erl
index 05bbf1069e..f8519d3a5e 100644
--- a/lib/kernel/src/os.erl
+++ b/lib/kernel/src/os.erl
@@ -254,7 +254,19 @@ mk_cmd(_,Cmd) ->
{"/bin/sh -s unix:cmd", [out],
%% We insert a new line after the command, in case the command
%% contains a comment character.
- ["(", unicode:characters_to_binary(Cmd), "\n); echo \"\^D\"\n"],
+ %%
+ %% The </dev/null closes stdin, which means that programs
+ %% that use a closed stdin as an termination indicator works.
+ %% An example of such a program is 'more'.
+ %%
+ %% The "echo ^D" is used to indicate that the program has executed
+ %% and we should return any output we have gotten. We cannot use
+ %% termination of the child or closing of stdin/stdout as then
+ %% starting background jobs from os:cmd will block os:cmd.
+ %%
+ %% I tried changing this to be "better", but got bombarded with
+ %% backwards incompatibility bug reports, so leave this as it is.
+ ["(", unicode:characters_to_binary(Cmd), "\n) </dev/null; echo \"\^D\"\n"],
<<$\^D>>}.
validate(Atom) when is_atom(Atom) ->