From bee1e06055234fa413034e632ec1d6a9f7d4451f Mon Sep 17 00:00:00 2001 From: Maciej Zygmanowski Date: Fri, 4 Jun 2021 17:10:24 +0200 Subject: [PATCH] hostname: Handle 'sethostname' errors --- Userland/Utilities/hostname.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Userland/Utilities/hostname.cpp b/Userland/Utilities/hostname.cpp index 4694480903..b620242f50 100644 --- a/Userland/Utilities/hostname.cpp +++ b/Userland/Utilities/hostname.cpp @@ -31,7 +31,11 @@ int main(int argc, char** argv) warnln("Hostname must be less than {} characters", HOST_NAME_MAX); return 1; } - sethostname(hostname, strlen(hostname)); + int rc = sethostname(hostname, strlen(hostname)); + if (rc < 0) { + perror("sethostname"); + return 1; + } } return 0; }