aboutsummaryrefslogtreecommitdiff
path: root/sys/contrib/openzfs/lib/libspl/os/linux/gethostid.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/contrib/openzfs/lib/libspl/os/linux/gethostid.c')
-rw-r--r--sys/contrib/openzfs/lib/libspl/os/linux/gethostid.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/sys/contrib/openzfs/lib/libspl/os/linux/gethostid.c b/sys/contrib/openzfs/lib/libspl/os/linux/gethostid.c
index c04b7fd3eef3..d39f3dda3b8d 100644
--- a/sys/contrib/openzfs/lib/libspl/os/linux/gethostid.c
+++ b/sys/contrib/openzfs/lib/libspl/os/linux/gethostid.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: CDDL-1.0
/*
* CDDL HEADER START
*
@@ -6,7 +7,7 @@
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
@@ -59,6 +60,7 @@ unsigned long
get_system_hostid(void)
{
unsigned long hostid = get_spl_hostid();
+ uint32_t system_hostid;
/*
* We do not use gethostid(3) because it can return a bogus ID,
@@ -69,8 +71,11 @@ get_system_hostid(void)
if (hostid == 0) {
int fd = open("/etc/hostid", O_RDONLY | O_CLOEXEC);
if (fd >= 0) {
- if (read(fd, &hostid, 4) < 0)
+ if (read(fd, &system_hostid, sizeof (system_hostid))
+ != sizeof (system_hostid))
hostid = 0;
+ else
+ hostid = system_hostid;
(void) close(fd);
}
}