aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/src
diff options
context:
space:
mode:
authorLukas Larsson <[email protected]>2016-09-02 14:29:26 +0200
committerLukas Larsson <[email protected]>2016-09-02 16:34:56 +0200
commitc0ed19c1261ee281d3c8f36ec3f28fa7328f0f39 (patch)
treec0bc86162e6a429289245b0da5cfc0901f9ebfbf /lib/kernel/src
parent71894a879d6254693791585246ce340dd7414b82 (diff)
downloadotp-c0ed19c1261ee281d3c8f36ec3f28fa7328f0f39.tar.gz
otp-c0ed19c1261ee281d3c8f36ec3f28fa7328f0f39.tar.bz2
otp-c0ed19c1261ee281d3c8f36ec3f28fa7328f0f39.zip
kernel: Close stdin of commands run in os:cmd
This is needed when running programs that only exit when stdin has been closed, e.g. 'more'.
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) ->