[LTP] [PATCH v1 1/2] Add SAFE_SETHOSTNAME macro
Andrea Cervesato
andrea.cervesato@suse.com
Thu Aug 18 13:01:16 CEST 2022
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
include/tst_safe_net.h | 3 +++
lib/safe_net.c | 17 +++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/include/tst_safe_net.h b/include/tst_safe_net.h
index e85b79a3e..98f0256fd 100644
--- a/include/tst_safe_net.h
+++ b/include/tst_safe_net.h
@@ -68,6 +68,9 @@
#define SAFE_GETHOSTNAME(name, size) \
safe_gethostname(__FILE__, __LINE__, name, size)
+#define SAFE_SETHOSTNAME(name, size) \
+ safe_sethostname(__FILE__, __LINE__, name, size)
+
#define TST_GETSOCKPORT(sockfd) \
tst_getsockport(__FILE__, __LINE__, sockfd)
diff --git a/lib/safe_net.c b/lib/safe_net.c
index 1717f0745..5dec0de11 100644
--- a/lib/safe_net.c
+++ b/lib/safe_net.c
@@ -469,6 +469,23 @@ int safe_gethostname(const char *file, const int lineno,
return rval;
}
+int safe_sethostname(const char *file, const int lineno,
+ const char *name, size_t size)
+{
+ int rval = sethostname(name, size);
+
+ if (rval == -1) {
+ tst_brkm_(file, lineno, TBROK | TERRNO, NULL,
+ "sethostname(%p, %zu) failed", name, size);
+ } else if (rval) {
+ tst_brkm_(file, lineno, TBROK | TERRNO, NULL,
+ "Invalid sethostname(%p, %zu) return value %d", name,
+ size, rval);
+ }
+
+ return rval;
+}
+
/*
* @return port in network byte order.
*/
--
2.35.3
More information about the ltp
mailing list