[MDEV-23589] portability: use `uname -n` instead of `hostname` Created: 2020-08-26  Updated: 2020-12-08  Resolved: 2020-09-10

Status: Closed
Project: MariaDB Server
Component/s: Scripts & Clients
Affects Version/s: 10.5.5
Fix Version/s: 10.4.16, 10.5.7

Type: Bug Priority: Trivial
Reporter: Geert Hendrickx Assignee: Anel Husakovic
Resolution: Fixed Votes: 0
Labels: portability

Attachments: File mariadb-hostname.diff    

 Description   

Scripts included with mariadb use `hostname` to query the hostname, used to create logfiles, pidfiles, etc. However this command is not defined by POSIX and thus not guaranteed to work.

Better use portable `uname -n` instead.

See attached patch.



 Comments   
Comment by Anel Husakovic [ 2020-08-27 ]

Hi ghen thanks for the patch.
I suggest you to raise an PR https://github.com/MariaDB/server/pulls so your patch could be more visible and more developers could look into.

Comment by Sergei Golubchik [ 2020-08-27 ]

Where does hostname not exist? We'd need at least one platform where your patch makes a difference, for testing.

Comment by Geert Hendrickx [ 2020-08-27 ]

Arch Linux default install (without inetutils pkg, no longer part of base OS. uname is part of coreutils)

Comment by Faustin Lammler [ 2020-08-27 ]

Indeed and not only on arch, see bellow:

for os in debian ubuntu archlinux fedora centos ; do echo $os: && docker run -it ${os}:latest /bin/bash -c "uname -n; hostname"; done
debian:
a22a4f5dd91b
a22a4f5dd91b
ubuntu:
37ecd90c8a07
37ecd90c8a07
archlinux:
95435e433627
/bin/bash: hostname: command not found
fedora:
9bccea21bb4f
/bin/bash: hostname: command not found
centos:
4a9a34aab63e
4a9a34aab63e

So `uname -n` seems to be a good alternative for very basic and clean OS installations (and docker).

Comment by Geert Hendrickx [ 2020-08-27 ]

anel PR is here: https://github.com/MariaDB/server/pull/1663

Comment by Anel Husakovic [ 2020-08-27 ]

ghen great thanks for raising the patch. We will take a look.
danblack what should be the fix version for this?

Comment by Daniel Black [ 2020-08-28 ]

Thanks faust that clearly shows what's in the minimal install and the two gaps.

https://www.archlinux.org/packages/extra/x86_64/mariadb/ (10.5) has the inetutils dependency I assume solely for this. eworm I assuming this is safe and drops a dependency for archlinux so is a gain?

Fedora, https://src.fedoraproject.org/rpms/mariadb, no dependency listed (in any branch aka release) on hostname package (that contains hostname).
https://bugzilla.redhat.com/show_bug.cgi?id=1317907 old closed bug that is related to hostname in fedora scripts that like this bugs replaces it with uname (https://src.fedoraproject.org/rpms/mariadb/c/f61d6f22879ff7825cd656dda4859c6357280762) rather than add a dependency. There are no outstanding distro bugs about this and `hostnames` minimal use in mysql_install_db/mysqld_safe means no-one noticed or cared.

Fedora 31 (has 10.3) will EOL about the same time as MariaDB's release so no-one will care.
Fedora 32 (has 10.4) will EOL mid next year. fc33/fc34 also have 10.4
FYI mschorm

So target 10.4 unless serg has a different option.

Comment by Christian Hesse [ 2020-08-28 ]

I will happily drop the dependency, especially as it's old inetutils.
Thanks!

Comment by Daniel Black [ 2020-08-28 ]

scripts/wsrep_sst_mysqldump.sh

    [ "$1" = "$(hostname -s)" ] && return 0
    [ "$1" = "$(hostname -f)" ] && return 0
    [ "$1" = "$(hostname -d)" ] && return 0

Is the donor name passed though wsrep.

https://galeracluster.com/library/documentation/scriptable-sst.html its specified as an IP.

Comment by Geert Hendrickx [ 2020-08-28 ]

I didn't verify that particular functionality, just added another item to that list of "anything that could match the local host". It's equivalent to the hostname -f that was already there, regardless of whether an FQDN would be valid input or not.

Comment by Anel Husakovic [ 2020-09-04 ]

jplindst can you please take a look in wsrep change?

Comment by Anel Husakovic [ 2020-09-10 ]

Pushed with 1bb3ad6dfc885112d to 10.4.
Note: wsrep change not pushed yet.

Generated at Thu Feb 08 09:23:32 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.