Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 655942 - sys-apps/net-tools: hostname returns success on failure
Summary: sys-apps/net-tools: hostname returns success on failure
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-17 09:58 UTC by Gustav Schaffter
Modified: 2018-06-26 07:35 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gustav Schaffter 2018-05-17 09:58:29 UTC
if 'hostname' is called with unrecognised cli flags/options it produces an error message plus it's 'usage' information and terminates with success (0).

When called with unrecognised flags/options, it should terminate with an error code. Especially so since it produces the error message.

(Agreed, it successfully produces the 'usage' information, but that is probably as expected and only marginally helpful for a bash script calling 'hostname'.)


Example:

# hostname --version
net-tools 1.60_p20161110235919

# hostname --xyz; echo ${?};
hostname: unrecognized option '--xyz'    <======== Note! Error message!
Usage: hostname [-v] {hostname|-F file}      set hostname (from file)
       domainname [-v] {nisdomain|-F file}   set NIS domainname (from file)
       hostname [-v] [-d|-f|-s|-a|-i|-y|-n]  display formatted name
       hostname [-v]                         display hostname

       hostname -V|--version|-h|--help       print info and exit

    dnsdomainname=hostname -d, {yp,nis,}domainname=hostname -y

    -s, --short           short host name
    -a, --alias           alias names
    -i, --ip-address      addresses for the hostname
    -f, --fqdn, --long    long host name (FQDN)
    -d, --domain          DNS domain name
    -y, --yp, --nis       NIS/YP domainname
    -F, --file            read hostname or NIS domainname from given file

   This command can read or set the hostname or the NIS domainname. You can
   also read the DNS domain or the FQDN (fully qualified domain name).
   Unless you are using bind or NIS for host lookups you can change the
   FQDN (Fully Qualified Domain Name) and the DNS domain name (which is
   part of the FQDN) in the /etc/hosts file.
0  # <========== Note return code '0',
   # which "by convention" is interpreted as success.



I fully recognise that 'man hostname' doesn't document any return codes at all, but there is this nagging feeling that a program should return '0' on success and something else (in worst case just '1') on failure.
Comment 1 SpanKY gentoo-dev 2018-06-26 07:35:54 UTC
this was broken in 2012 here:
  https://sourceforge.net/p/net-tools/code/ci/699e5db88236deff1ff4cc657a8d978c25790587

i've fixed it upstream here:
  https://sourceforge.net/p/net-tools/code/ci/aebd88ef8d6e15f673b62a649a50d07ed727c888

so it'll make it into the next snapshot at some point.