File otp_src_19.3.4-shell-history-path.patch of Package erlang
diff -Ndurp otp_src_19.3.4-shell-history/lib/kernel/doc/src/kernel_app.xml otp_src_19.3.4-shell-history-path/lib/kernel/doc/src/kernel_app.xml
--- otp_src_19.3.4-shell-history/lib/kernel/doc/src/kernel_app.xml 2017-05-11 18:41:34.000000000 +0300
+++ otp_src_19.3.4-shell-history-path/lib/kernel/doc/src/kernel_app.xml 2017-05-22 17:52:09.922658789 +0300
@@ -365,6 +365,29 @@ MaxT = TickTime + TickTime / 4</code>
using this service.</p>
<p>Defaults to <c>false</c>.</p>
</item>
+ <tag><c>shell_history = enabled | disabled </c></tag>
+ <item>
+ <p>Specifies whether shell history should be logged to disk
+ between usages of <c>erl</c>.</p>
+ </item>
+ <tag><c>shell_history_drop = [string()]</c></tag>
+ <item>
+ <p>Specific log lines that should not be persisted. For
+ example <c>["q().", "init:stop()."]</c> will allow to
+ ignore commands that shut the node down. Defaults to
+ <c>[]</c>.</p>
+ </item>
+ <tag><c>shell_history_file_bytes = integer()</c></tag>
+ <item>
+ <p>how many bytes the shell should remember. By default, the
+ value is set to 512kb, and the minimal value is 50kb.</p>
+ </item>
+ <tag><c>shell_history_path = string()</c></tag>
+ <item>
+ <p>Specifies where the shell history files will be stored.
+ defaults to the user's cache directory as returned by
+ <c>filename:basedir(user_cache, "erlang-history")</c>.</p>
+ </item>
<tag><c>shutdown_func = {Mod, Func}</c></tag>
<item>
<p>Where:</p>
diff -Ndurp otp_src_19.3.4-shell-history/lib/kernel/src/group_history.erl otp_src_19.3.4-shell-history-path/lib/kernel/src/group_history.erl
--- otp_src_19.3.4-shell-history/lib/kernel/src/group_history.erl 2017-05-22 14:49:49.755572832 +0300
+++ otp_src_19.3.4-shell-history-path/lib/kernel/src/group_history.erl 2017-05-22 17:49:38.280128304 +0300
@@ -1,12 +1,31 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2017. All Rights Reserved.
+%%
+%% Licensed under the Apache License, Version 2.0 (the "License");
+%% you may not use this file except in compliance with the License.
+%% You may obtain a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing, software
+%% distributed under the License is distributed on an "AS IS" BASIS,
+%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+%% See the License for the specific language governing permissions and
+%% limitations under the License.
+%%
+%% %CopyrightEnd%
+%%
-module(group_history).
-export([load/0, add/1]).
%% Make a minimal size that should encompass set of lines and then make
%% a file rotation for N files of this size.
--define(DEFAULT_HISTORY_FILE, ".erlang-history/log").
+-define(DEFAULT_HISTORY_FILE, "erlang-shell-log").
-define(MAX_HISTORY_FILES, 10).
-define(DEFAULT_SIZE, 1024*512). % 512 kb total default
--define(DEFAULT_STATUS, enabled).
+-define(DEFAULT_STATUS, disabled).
-define(MIN_HISTORY_SIZE, (50*1024)). % 50 kb, in bytes
-define(DEFAULT_DROP, []).
-define(DISK_LOG_FORMAT, internal). % since we want repairs
@@ -158,12 +177,18 @@ matches_log(Txt) ->
%% Return whether the shell history is enabled or not
-spec history_status() -> enabled | disabled.
history_status() ->
- case application:get_env(kernel, shell_history) of
+ case is_user() orelse application:get_env(kernel, shell_history) of
+ true -> disabled; % don't run for user proc
{ok, enabled} -> enabled;
undefined -> ?DEFAULT_STATUS;
_ -> disabled
end.
+%% Return whether the user process is running this
+-spec is_user() -> boolean().
+is_user() ->
+ process_info(self(), registered_name) =:= {registered_name, user}.
+
%% Open a disk_log file while ensuring the required path is there.
open_log() ->
Opts = log_options(),
@@ -175,8 +200,8 @@ log_options() -> log_options(false).
%% Return logger options (with repairs configurable)
log_options(Repair) ->
- Home = home(),
- File = filename:join([Home, ?DEFAULT_HISTORY_FILE]),
+ Path = find_path(),
+ File = filename:join([Path, ?DEFAULT_HISTORY_FILE]),
Size = find_wrap_values(),
[{name, ?LOG_NAME},
{file, File},
@@ -187,6 +212,7 @@ log_options(Repair) ->
{distributed, []},
{notify, false},
{head, {vsn, ?VSN}},
+ {quiet, true},
{mode, read_write}].
-spec ensure_path([{file, string()} | {atom(), _}, ...]) -> ok | {error, term()}.
@@ -306,13 +332,10 @@ disable_history() ->
show('$#erlang-history-disable', "Disabling shell history logging.~n", []),
application:set_env(kernel, shell_history, force_disabled).
-home() ->
- case init:get_argument(home) of
- {ok, [[Home]]} ->
- Home;
- _ ->
- error_logger:error_msg("No home directory found"),
- error(badarg)
+find_path() ->
+ case application:get_env(kernel, shell_history_path) of
+ undefined -> filename:basedir(user_cache, "erlang-history");
+ {ok, Path} -> Path
end.
to_drop() ->