Skip to content

Commit

Permalink
MDEV-505 - feature request: add \H option for mysql client prompt
Browse files Browse the repository at this point in the history
An addition to original patch:
- use FN_REFLEN instead of HOST_NAME_MAX (the latter can be undefined)
- avoid calling gethostname() on every prompt construction by caching it
  • Loading branch information
Sergey Vojtovich committed May 10, 2016
1 parent eca0607 commit 1c68b9e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions client/mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5122,8 +5122,10 @@ static const char *construct_prompt()
processed_prompt.append("localhost");
else
{
char hostname[HOST_NAME_MAX];
if (gethostname(hostname, sizeof(hostname)) == 0)
static char hostname[FN_REFLEN];
if (hostname[0])
processed_prompt.append(hostname);
else if (gethostname(hostname, sizeof(hostname)) == 0)
processed_prompt.append(hostname);
else
processed_prompt.append("gethostname(2) failed");
Expand Down

0 comments on commit 1c68b9e

Please sign in to comment.