From owner-svn-src-stable-12@freebsd.org Sun Oct 6 03:59:06 2019 Return-Path: Delivered-To: svn-src-stable-12@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 5BBC4F9B1C; Sun, 6 Oct 2019 03:59:06 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46m8xQ1Nmyz4WjQ; Sun, 6 Oct 2019 03:59:06 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EB7041F6D9; Sun, 6 Oct 2019 03:59:05 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x963x5Sv035451; Sun, 6 Oct 2019 03:59:05 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x963x5b9035450; Sun, 6 Oct 2019 03:59:05 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201910060359.x963x5b9035450@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Sun, 6 Oct 2019 03:59:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r353135 - in stable: 11/lib/libusb 12/lib/libusb X-SVN-Group: stable-12 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable: 11/lib/libusb 12/lib/libusb X-SVN-Commit-Revision: 353135 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Oct 2019 03:59:06 -0000 Author: kevans Date: Sun Oct 6 03:59:05 2019 New Revision: 353135 URL: https://svnweb.freebsd.org/changeset/base/353135 Log: MFC r353009: libusb: LIBUSB_DEBUG env var override of libusb_set_debug The debug level generally just controls verbosity of libusb for debugging libusb devices/usage. We allow the environment to set the debug level independent of the application, but the application will always override this if it explicitly sets the debug level. Changing the environment is easy, but patching the software to change the debug level isn't necessarily easy or possible. Further, there's this write-only debug_fixed variable that would seem to imply that the debug level should be fixed, but it isn't currently used. Change the logic to use strtol() so we can detect real 0 vs. conversion failure, then honor debug_fixed in libusb_set_debug. Modified: stable/12/lib/libusb/libusb10.c Directory Properties: stable/12/ (props changed) Changes in other areas also in this revision: Modified: stable/11/lib/libusb/libusb10.c Directory Properties: stable/11/ (props changed) Modified: stable/12/lib/libusb/libusb10.c ============================================================================== --- stable/12/lib/libusb/libusb10.c Sun Oct 6 03:56:02 2019 (r353134) +++ stable/12/lib/libusb/libusb10.c Sun Oct 6 03:59:05 2019 (r353135) @@ -91,7 +91,8 @@ void libusb_set_debug(libusb_context *ctx, int level) { ctx = GET_CONTEXT(ctx); - if (ctx) + /* debug_fixed is set when the environment overrides libusb_set_debug */ + if (ctx && ctx->debug_fixed == 0) ctx->debug = level; } @@ -132,7 +133,7 @@ libusb_init(libusb_context **context) { struct libusb_context *ctx; pthread_condattr_t attr; - char *debug; + char *debug, *ep; int ret; ctx = malloc(sizeof(*ctx)); @@ -143,9 +144,23 @@ libusb_init(libusb_context **context) debug = getenv("LIBUSB_DEBUG"); if (debug != NULL) { - ctx->debug = atoi(debug); - if (ctx->debug != 0) + /* + * If LIBUSB_DEBUG is set, we'll honor that and use it to + * override libusb_set_debug calls. + */ + errno = 0; + ctx->debug = strtol(debug, &ep, 10); + if (errno == 0 && *ep == '\0') { ctx->debug_fixed = 1; + } else { + /* + * LIBUSB_DEBUG conversion failed for some reason, but + * we don't care about the specifics all that much. We + * can't use it either way. Force it to the default, + * 0, in case we had a partial number. + */ + ctx->debug = 0; + } } TAILQ_INIT(&ctx->pollfds); TAILQ_INIT(&ctx->tr_done);