aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libzfs/os/freebsd/libzfs_compat.c
diff options
context:
space:
mode:
authorнаб <[email protected]>2022-04-15 00:00:02 +0200
committerBrian Behlendorf <[email protected]>2022-05-18 12:52:10 -0700
commit2b4f2fc93c4298415c5bc70554514c3e8892e5d5 (patch)
tree6dacd72befb51adf0f0fc500b42ad0fe9edebf83 /lib/libzfs/os/freebsd/libzfs_compat.c
parent38f4d99f769efbb472ab3c35558700163e4f023c (diff)
libzfs: return (allocated) strings instead of filling buffers
This also expands the zfs version output from 127 characters to However Many Are Actually Set Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes #13330
Diffstat (limited to 'lib/libzfs/os/freebsd/libzfs_compat.c')
-rw-r--r--lib/libzfs/os/freebsd/libzfs_compat.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/lib/libzfs/os/freebsd/libzfs_compat.c b/lib/libzfs/os/freebsd/libzfs_compat.c
index d2bc6ddfc..289c6703c 100644
--- a/lib/libzfs/os/freebsd/libzfs_compat.c
+++ b/lib/libzfs/os/freebsd/libzfs_compat.c
@@ -351,14 +351,22 @@ zpool_nextboot(libzfs_handle_t *hdl, uint64_t pool_guid, uint64_t dev_guid,
}
/*
- * Fill given version buffer with zfs kernel version.
- * Returns 0 on success, and -1 on error (with errno set)
+ * Return allocated loaded module version, or NULL on error (with errno set)
*/
-int
-zfs_version_kernel(char *version, int len)
+char *
+zfs_version_kernel(void)
{
- size_t l = len;
-
- return (sysctlbyname("vfs.zfs.version.module",
- version, &l, NULL, 0));
+ size_t l;
+ if (sysctlbyname("vfs.zfs.version.module",
+ NULL, &l, NULL, 0) == -1)
+ return (NULL);
+ char *version = malloc(l);
+ if (version == NULL)
+ return (NULL);
+ if (sysctlbyname("vfs.zfs.version.module",
+ version, &l, NULL, 0) == -1) {
+ free(version);
+ return (NULL);
+ }
+ return (version);
}