The issue is with the systemd resolver not with glibc.
With systemd-resolve IP in /etc/resolv.conf:
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.
nameserver 127.0.0.53
$ time ./test not-a-hostname
Trying to resolve: not-a-hostname
getaddrinfo errno: No such file or directory
getaddrinfo() return value: -2 (Name or service not known)
real 0m10.076s
user 0m0.001s
sys 0m0.000s
Without systemd-resolve in /etc/resolv.conf. I changed it to point to my local DNS server directly.
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.
#nameserver 127.0.0.53
nameserver 192.168.1.1
$ time ./test not-a-hostname
Trying to resolve: not-a-hostname
getaddrinfo errno: No such file or directory
getaddrinfo() return value: -2 (Name or service not known)
The issue is with the systemd resolver not with glibc.
With systemd-resolve IP in /etc/resolv.conf:
# This file is managed by man:systemd- resolved( 8). Do not edit.
#
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.
nameserver 127.0.0.53
$ time ./test not-a-hostname
Trying to resolve: not-a-hostname
getaddrinfo errno: No such file or directory
getaddrinfo() return value: -2 (Name or service not known)
real 0m10.076s
user 0m0.001s
sys 0m0.000s
Without systemd-resolve in /etc/resolv.conf. I changed it to point to my local DNS server directly.
# This file is managed by man:systemd- resolved( 8). Do not edit.
#
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.
#nameserver 127.0.0.53
nameserver 192.168.1.1
$ time ./test not-a-hostname
Trying to resolve: not-a-hostname
getaddrinfo errno: No such file or directory
getaddrinfo() return value: -2 (Name or service not known)
real 0m0.097s
user 0m0.001s
sys 0m0.000s