From 0331d2fac4edea78c760c909bbdf4d7c18e0b4b4 Mon Sep 17 00:00:00 2001 From: Ryan Moeller Date: Thu, 5 Aug 2021 15:29:24 +0000 Subject: [PATCH] libzfs_sendrecv: Style pass on dump_ioctl * Don't bother building a debug nvlist if we can't return it. * Save errno after ioctl failure in case snprintf clobbers it. Reviewed-by: Brian Behlendorf Signed-off-by: Ryan Moeller Closes #12967 --- lib/libzfs/libzfs_sendrecv.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/libzfs/libzfs_sendrecv.c b/lib/libzfs/libzfs_sendrecv.c index 1ef5fe4f45c9..fea49e3ab1b3 100644 --- a/lib/libzfs/libzfs_sendrecv.c +++ b/lib/libzfs/libzfs_sendrecv.c @@ -795,23 +795,26 @@ dump_ioctl(zfs_handle_t *zhp, const char *fromsnap, uint64_t fromsnap_obj, zc.zc_fromobj = fromsnap_obj; zc.zc_flags = flags; - thisdbg = fnvlist_alloc(); - if (fromsnap && fromsnap[0] != '\0') { - fnvlist_add_string(thisdbg, "fromsnap", fromsnap); + if (debugnv != NULL) { + thisdbg = fnvlist_alloc(); + if (fromsnap != NULL && fromsnap[0] != '\0') + fnvlist_add_string(thisdbg, "fromsnap", fromsnap); } if (zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_SEND, &zc) != 0) { char errbuf[1024]; + int error = errno; + (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, "warning: cannot send '%s'"), zhp->zfs_name); - fnvlist_add_uint64(thisdbg, "error", errno); - if (debugnv) { + if (debugnv != NULL) { + fnvlist_add_uint64(thisdbg, "error", error); fnvlist_add_nvlist(debugnv, zhp->zfs_name, thisdbg); + fnvlist_free(thisdbg); } - fnvlist_free(thisdbg); - switch (errno) { + switch (error) { case EXDEV: zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "not an earlier snapshot from the same fs")); @@ -851,9 +854,10 @@ dump_ioctl(zfs_handle_t *zhp, const char *fromsnap, uint64_t fromsnap_obj, } } - if (debugnv) + if (debugnv != NULL) { fnvlist_add_nvlist(debugnv, zhp->zfs_name, thisdbg); - fnvlist_free(thisdbg); + fnvlist_free(thisdbg); + } return (0); }