Date: Mon, 4 Aug 2014 18:52:26 +0000 (UTC) From: Mark Johnston <markj@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r269524 - head/cddl/contrib/opensolaris/lib/libdtrace/common Message-ID: <53dfd66a.5d3f.43006441@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: markj Date: Mon Aug 4 18:52:26 2014 New Revision: 269524 URL: http://svnweb.freebsd.org/changeset/base/269524 Log: Preserve the errno value of an ioctl before calling free(3). Previously, errno was very occasionally being clobbered, resulting in a bogus error from dt_consume() and thus an error from dtrace(1). MFC after: 2 weeks Modified: head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_consume.c head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_map.c head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_work.c Modified: head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_consume.c ============================================================================== --- head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_consume.c Mon Aug 4 16:41:06 2014 (r269523) +++ head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_consume.c Mon Aug 4 18:52:26 2014 (r269524) @@ -2944,7 +2944,7 @@ dt_get_buf(dtrace_hdl_t *dtp, int cpu, d { dtrace_optval_t size; dtrace_bufdesc_t *buf = dt_zalloc(dtp, sizeof (*buf)); - int error; + int error, rval; if (buf == NULL) return (-1); @@ -2963,7 +2963,6 @@ dt_get_buf(dtrace_hdl_t *dtp, int cpu, d #else if (dt_ioctl(dtp, DTRACEIOC_BUFSNAP, &buf) == -1) { #endif - dt_put_buf(dtp, buf); /* * If we failed with ENOENT, it may be because the * CPU was unconfigured -- this is okay. Any other @@ -2971,10 +2970,12 @@ dt_get_buf(dtrace_hdl_t *dtp, int cpu, d */ if (errno == ENOENT) { *bufp = NULL; - return (0); - } + rval = 0; + } else + rval = dt_set_errno(dtp, errno); - return (dt_set_errno(dtp, errno)); + dt_put_buf(dtp, buf); + return (rval); } error = dt_unring_buf(dtp, buf); Modified: head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_map.c ============================================================================== --- head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_map.c Mon Aug 4 16:41:06 2014 (r269523) +++ head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_map.c Mon Aug 4 18:52:26 2014 (r269524) @@ -39,7 +39,7 @@ static int dt_strdata_add(dtrace_hdl_t *dtp, dtrace_recdesc_t *rec, void ***data, int *max) { - int maxformat; + int maxformat, rval; dtrace_fmtdesc_t fmt; void *result; @@ -63,8 +63,9 @@ dt_strdata_add(dtrace_hdl_t *dtp, dtrace return (dt_set_errno(dtp, EDT_NOMEM)); if (dt_ioctl(dtp, DTRACEIOC_FORMAT, &fmt) == -1) { + rval = dt_set_errno(dtp, errno); free(fmt.dtfd_string); - return (dt_set_errno(dtp, errno)); + return (rval); } while (rec->dtrd_format > (maxformat = *max)) { Modified: head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_work.c ============================================================================== --- head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_work.c Mon Aug 4 16:41:06 2014 (r269523) +++ head/cddl/contrib/opensolaris/lib/libdtrace/common/dt_work.c Mon Aug 4 18:52:26 2014 (r269524) @@ -184,7 +184,7 @@ dtrace_go(dtrace_hdl_t *dtp) { dtrace_enable_io_t args; void *dof; - int err; + int error, r; if (dtp->dt_active) return (dt_set_errno(dtp, EINVAL)); @@ -206,11 +206,12 @@ dtrace_go(dtrace_hdl_t *dtp) args.dof = dof; args.n_matched = 0; - err = dt_ioctl(dtp, DTRACEIOC_ENABLE, &args); + r = dt_ioctl(dtp, DTRACEIOC_ENABLE, &args); + error = errno; dtrace_dof_destroy(dtp, dof); - if (err == -1 && (errno != ENOTTY || dtp->dt_vector == NULL)) - return (dt_set_errno(dtp, errno)); + if (r == -1 && (error != ENOTTY || dtp->dt_vector == NULL)) + return (dt_set_errno(dtp, error)); if (dt_ioctl(dtp, DTRACEIOC_GO, &dtp->dt_beganon) == -1) { if (errno == EACCES)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?53dfd66a.5d3f.43006441>