diff options
author | Daniel Black <daniel@mariadb.org> | 2022-12-21 14:04:48 +1100 |
---|---|---|
committer | Daniel Black <daniel@mariadb.org> | 2023-01-24 20:22:23 +1100 |
commit | f8ca355ed80786f45b2ca11499a716255ebb6616 (patch) | |
tree | bddd1522128e235afa2c9daeadeaf4614112ae23 /client/mysql.cc | |
parent | aafe85ecb1cc887e2e48a62550d876647658deea (diff) | |
download | mariadb-git-f8ca355ed80786f45b2ca11499a716255ebb6616.tar.gz |
MDEV-26548: replace .mysql_history with .mariadb_history
Fall back to using .mysql_history if .mariadb_history isn't
present and .mysql_history is present.
Also replace the use of MYSQL_HISTFILE as an environment variable
with MARIADB_HISTFILE and fall back to using MYSQL_HISTFILE if
MARIADB_HISTFILE isn't present.
Diffstat (limited to 'client/mysql.cc')
-rw-r--r-- | client/mysql.cc | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/client/mysql.cc b/client/mysql.cc index 06e662ad860..363677785d5 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -1337,26 +1337,38 @@ int main(int argc,char *argv[]) initialize_readline(); if (!status.batch && !quick && !opt_html && !opt_xml) { - /* read-history from file, default ~/.mysql_history*/ - if (getenv("MYSQL_HISTFILE")) - histfile=my_strdup(PSI_NOT_INSTRUMENTED, getenv("MYSQL_HISTFILE"),MYF(MY_WME)); - else if (getenv("HOME")) + const char *home; + /* read-history from file, default ~/.mariadb_history*/ + if ((histfile= getenv("MARIADB_HISTFILE")) + || (histfile= getenv("MYSQL_HISTFILE"))) + histfile=my_strdup(PSI_NOT_INSTRUMENTED, histfile, MYF(MY_WME)); + else if ((home= getenv("HOME"))) { histfile=(char*) my_malloc(PSI_NOT_INSTRUMENTED, - strlen(getenv("HOME")) + strlen("/.mysql_history")+2, MYF(MY_WME)); + strlen(home) + strlen("/.mariadb_history")+2, MYF(MY_WME)); if (histfile) - sprintf(histfile,"%s/.mysql_history",getenv("HOME")); - char link_name[FN_REFLEN]; - if (my_readlink(link_name, histfile, 0) == 0 && - strncmp(link_name, "/dev/null", 10) == 0) { - /* The .mysql_history file is a symlink to /dev/null, don't use it */ - my_free(histfile); - histfile= 0; + sprintf(histfile,"%s/.mariadb_history", home); + if (my_access(histfile, F_OK)) + { + /* no .mariadb_history, look for historical name and use if present */ + sprintf(histfile,"%s/.mysql_history", home); + /* and go back to original if not found */ + if (my_access(histfile, F_OK)) + sprintf(histfile,"%s/.mariadb_history", home); + } + char link_name[FN_REFLEN]; + if (my_readlink(link_name, histfile, 0) == 0 && + strncmp(link_name, "/dev/null", 10) == 0) + { + /* The .mariadb_history file is a symlink to /dev/null, don't use it */ + my_free(histfile); + histfile= 0; + } } } - /* We used to suggest setting MYSQL_HISTFILE=/dev/null. */ + /* We used to suggest setting MARIADB_HISTFILE=/dev/null. */ if (histfile && strncmp(histfile, "/dev/null", 10) == 0) histfile= NULL; |