From owner-svn-src-head@FreeBSD.ORG Mon Aug 4 18:52:27 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 535C51E8 for ; Mon, 4 Aug 2014 18:52:27 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1692929D4 for ; Mon, 4 Aug 2014 18:52:27 +0000 (UTC) Received: from markj (uid 1309) (envelope-from markj@FreeBSD.org) id 5d3f by svn.freebsd.org (DragonFly Mail Agent v0.9+); Mon, 04 Aug 2014 18:52:26 +0000 From: Mark Johnston Date: Mon, 4 Aug 2014 18:52:26 +0000 (UTC) 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 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <53dfd66a.5d3f.43006441@svn.freebsd.org> X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Aug 2014 18:52:27 -0000 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)