bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Patch for full hostname in PS1


From: Renato Silva
Subject: Patch for full hostname in PS1
Date: Sun, 8 Jun 2014 15:47:10 -0300

Hi all.

There is a problem with the \H placeholder in PS1 where sometimes it won't
show the full hostname as we sort of imply from the man page (\h is "the
hostname up to the first '.'" while \H is just "the hostname"). This is
reproducible for example on my Ubuntu 14.04 server installation, and has
been previously reported [1]. They are not adding the full name anymore to
/etc/hostname, which seems why gethostname [2] (current implementation of
\H) is not making any difference when compared to lowercase \h.

Take it as a bug or a possible improvement, attached is a patch using a
better API [3] to retrieve the "canonical name" on \H. Works for me, as in
the screenshot below. This API is the same used by Ubuntu's hostname
utility when provided with the -f option [4] (FQDN or long host name),
which is the current workaround we can use for the misbehavior of \H. For
those of you maintainers which won't possibly agree to see this as a
problem, I wonder how useful current implementation is. I would guess most
users expect, for a long hostname, that either the short name or the long
name is returned, deterministically, not either the short name or
(depending on random distro specifics) a possible long name.

Along with the patch I'm attaching the *nix build I used in my tests. The
patch is against current head [5]. I'm also attaching a sample program
"canonname" demonstrating the use of the new API (web [6], source code,
windows, *nix). Feedback is welcome. Thanks in advance.




[1] https://bugs.launchpad.net/ubuntu/+source/bash/+bug/1276796
[2] http://linux.die.net/man/2/gethostname
[3] http://linux.die.net/man/3/getaddrinfo
[4]
http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/trusty/hostname/trusty/view/18/hostname.c#L339
[5]
http://git.savannah.gnu.org/gitweb/?p=bash.git;a=commit;h=35751626eebdec08c6ac8600b33477e6db31988a
[6] http://ideone.com/JOvt1P

PNG image

Attachment: bash.canonname
Description: Binary data

Attachment: bash-HEAD-3575162-canonname.patch
Description: Text Data

Attachment: canonname
Description: Binary data

Attachment: canonname.c
Description: Text Data

Attachment: canonname.exe.7z
Description: application/7z-compressed


reply via email to

[Prev in Thread] Current Thread [Next in Thread]