logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git
commit: 708242e74bc7ae6283c0cec80528562257361dc0
parent 91568cf63c4a3a8774ab1e63aae905db04d2608b
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun, 18 Dec 2022 08:49:05 +0100

cmd/sname: Add linux-specific domainname entry

Diffstat:

Mcmd/sname.c5++++-
Mtest-cmd/sname8+++++++-
2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/cmd/sname.c b/cmd/sname.c @@ -1,7 +1,7 @@ // Collection of Unix tools, comparable to coreutils // SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - +#define _GNU_SOURCE #include <stdio.h> // printf(), perror() #include <stdlib.h> // exit() #include <sys/utsname.h> // utsname, uname() @@ -26,6 +26,9 @@ main() return 1; } +#ifdef __linux__ + print_kv("domainname", name.domainname); +#endif print_kv("machine", name.machine); print_kv("nodename", name.nodename); print_kv("release", name.release); diff --git a/test-cmd/sname b/test-cmd/sname @@ -4,8 +4,14 @@ atf_test_case generic generic_body() { + domainname="" + if [ "$(uname -s)" = "Linux" ]; then + domainanme="$(hostname -d)" + domainname="domainname ${domainname:-(none)}\n" + fi + # sed is because of FreeBSD - atf_check -o "inline:\ + atf_check -o "inline:${domainname}\ machine $(uname -m) nodename $(uname -n) release $(uname -r)