Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15224
| Path | csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail |
|---|---|
| From | Thomas Deutschmann <whissi@gentoo.org> |
| Newsgroups | gnu.bash.bug |
| Subject | [PATCH] Fix \H: Use getaddrinfo to get full hostname |
| Date | Wed, 24 Jul 2019 15:58:35 +0200 |
| Lines | 62 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.2133.1563976752.2688.bug-bash@gnu.org> (permalink) |
| References | <20190724135835.110473-1-whissi@gentoo.org> |
| NNTP-Posting-Host | lists.gnu.org |
| Mime-Version | 1.0 |
| Content-Transfer-Encoding | quoted-printable |
| X-Trace | usenet.stanford.edu 1563976753 31083 209.51.188.17 (24 Jul 2019 13:59:13 GMT) |
| X-Complaints-To | action@cs.stanford.edu |
| To | bug-bash@gnu.org |
| Envelope-to | bug-bash@gnu.org |
| X-Mailer | git-send-email 2.22.0 |
| X-detected-operating-system | by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] |
| X-Received-From | 140.211.166.183 |
| X-BeenThere | bug-bash@gnu.org |
| X-Mailman-Version | 2.1.23 |
| Precedence | list |
| List-Id | Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org> |
| List-Unsubscribe | <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe> |
| List-Archive | <https://lists.gnu.org/archive/html/bug-bash> |
| List-Post | <mailto:bug-bash@gnu.org> |
| List-Help | <mailto:bug-bash-request@gnu.org?subject=help> |
| List-Subscribe | <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <20190724135835.110473-1-whissi@gentoo.org> |
| Xref | csiph.com gnu.bash.bug:15224 |
Show key headers only | View raw
At the moment, \h and \H used in prompt PS1 or PS2 will actually return
the same value while manpage claims that \h should return hostname up to
the first '.' (like `hostname`) and \H should return full hostname (like
`hostname -f`).
This commit will make bash use the same API like hostname command to
return full hostname like intended.
This patch is based on the original work from Renato Silva [Link 1].
Link 1: https://lists.gnu.org/archive/html/bug-bash/2014-06/msg00021.html
---
shell.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/shell.c b/shell.c
index a2b2a55e..28e89a2b 100644
--- a/shell.c
+++ b/shell.c
@@ -37,6 +37,7 @@
#include <stdio.h>
#include <signal.h>
#include <errno.h>
+#include <netdb.h>
#include "filecntl.h"
#if defined (HAVE_PWD_H)
# include <pwd.h>
@@ -1839,6 +1840,8 @@ get_current_user_info ()
static void
shell_initialize ()
{
+ struct addrinfo *addr_info;
+ struct addrinfo addr_hints;
char hostname[256];
int should_be_restricted;
@@ -1864,10 +1867,17 @@ shell_initialize ()
if (current_host_name == 0)
{
/* Initialize current_host_name. */
- if (gethostname (hostname, 255) < 0)
- current_host_name = "??host??";
+ memset(&addr_hints, 0, sizeof(struct addrinfo));
+ addr_hints.ai_flags = AI_CANONNAME;
+
+ if (gethostname (hostname, 255) >= 0)
+ {
+ if (getaddrinfo (hostname, NULL, &addr_hints, &addr_info) == 0)
+ strncpy (hostname, addr_info->ai_canonname, 255);
+ current_host_name = savestring (hostname);
+ }
else
- current_host_name = savestring (hostname);
+ current_host_name = "??host??";
}
/* Initialize the stuff in current_user that comes from the password
--
2.22.0
Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread
[PATCH] Fix \H: Use getaddrinfo to get full hostname Thomas Deutschmann <whissi@gentoo.org> - 2019-07-24 15:58 +0200
csiph-web