Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4570244ybi; Sat, 6 Jul 2019 08:01:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqy2djLybhAGGubM8PcLHFgI+egxDXAAGWPIlj7paQIA1P5nU9kjQsB2U84fHKynXN07fM8T X-Received: by 2002:a17:90a:8b98:: with SMTP id z24mr4799978pjn.77.1562425290668; Sat, 06 Jul 2019 08:01:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562425290; cv=none; d=google.com; s=arc-20160816; b=GFQu/q0ctnWh+laKQZBmRFdRUjY9jRqo7efVfT8IiKLRvm+J04uUJZqvAB+lSDOKpU exs6+6Z+AlmpTubkkGSg4qSZn1uznKh2/+jrB9TMc4UmlYLnWzpoQniAMf0Vi2SpaslP r7ps8el+0SnqxxhiQ/Y1ebOJY+U3fnyeWaosDdxu6VRoNLqEOTD47k2WrAjIODNS6ej4 mf20mKngRznwzpivRVlxdXSIFDD4AEEiT4D9cGxQkhuqmMjyim3HGRAsWE3NCBSPGqia huW/IGIW+JlajkvCIBN2MKtKYahHplP/sd7CkiXXeKMskRen9dSJSXl4bMb81mf5N4bo lcSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=apOirA2hWPW71sWOOEQUqGCfpaFXf8vZNuHznjNoz+s=; b=p8ADNeKE5os8yG294h4L1axXLm+0NZeKoO/+bQt3SfhfzEABBjMG+CMqsNlLiqOBiW a/xR2ES3KeFwh7xfRoiMyYGeobvulqNHjg/zVYXw2O5ScDNx5Ci4cj4bwxVehEmYuJ4v Cp7P7sXQe1RD0YJ94PVoRcIbOL83TpKoeoANOs9C7rg/dDLpsutjfss3xoX7e+uLCTCe c4kFb9tfpZeYu/e/z1bvURjBfcsakxQOcPA0w+ALxYLdNPcD7y12Brg9G9DBRBx7EVyu L1DLSGdZTlJHryDC/8KY1moSx9h1jj/47pB+ehgflYIOXghNMhdDCjpDgiWr+u6iOSZ4 qpbw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b11si5963513plz.307.2019.07.06.08.01.16; Sat, 06 Jul 2019 08:01:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727236AbfGFPAz (ORCPT + 99 others); Sat, 6 Jul 2019 11:00:55 -0400 Received: from mx1.mailbox.org ([80.241.60.212]:43204 "EHLO mx1.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726607AbfGFPAy (ORCPT ); Sat, 6 Jul 2019 11:00:54 -0400 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id 5557250266; Sat, 6 Jul 2019 17:00:50 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by hefe.heinlein-support.de (hefe.heinlein-support.de [91.198.250.172]) (amavisd-new, port 10030) with ESMTP id AhUDKWrxSzUZ; Sat, 6 Jul 2019 17:00:43 +0200 (CEST) From: Aleksa Sarai To: Al Viro , Jeff Layton , "J. Bruce Fields" , Arnd Bergmann , David Howells , Shuah Khan , Shuah Khan Cc: Aleksa Sarai , Eric Biederman , Andy Lutomirski , Andrew Morton , Alexei Starovoitov , Kees Cook , Jann Horn , Christian Brauner , Tycho Andersen , David Drysdale , Chanho Min , Oleg Nesterov , Aleksa Sarai , Linus Torvalds , containers@lists.linux-foundation.org, linux-alpha@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, linux-xtensa@linux-xtensa.org, sparclinux@vger.kernel.org Subject: [PATCH v9 09/10] kselftest: save-and-restore errno to allow for %m formatting Date: Sun, 7 Jul 2019 00:57:36 +1000 Message-Id: <20190706145737.5299-10-cyphar@cyphar.com> In-Reply-To: <20190706145737.5299-1-cyphar@cyphar.com> References: <20190706145737.5299-1-cyphar@cyphar.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Previously, using "%m" in a ksft_* format string can result in strange output because the errno value wasn't saved before calling other libc functions. The solution is to simply save and restore the errno before we format the user-supplied format string. Signed-off-by: Aleksa Sarai --- tools/testing/selftests/kselftest.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h index ec15c4f6af55..0ac49d91a260 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h @@ -10,6 +10,7 @@ #ifndef __KSELFTEST_H #define __KSELFTEST_H +#include #include #include #include @@ -81,58 +82,68 @@ static inline void ksft_print_cnts(void) static inline void ksft_print_msg(const char *msg, ...) { + int saved_errno = errno; va_list args; va_start(args, msg); printf("# "); + errno = saved_errno; vprintf(msg, args); va_end(args); } static inline void ksft_test_result_pass(const char *msg, ...) { + int saved_errno = errno; va_list args; ksft_cnt.ksft_pass++; va_start(args, msg); printf("ok %d ", ksft_test_num()); + errno = saved_errno; vprintf(msg, args); va_end(args); } static inline void ksft_test_result_fail(const char *msg, ...) { + int saved_errno = errno; va_list args; ksft_cnt.ksft_fail++; va_start(args, msg); printf("not ok %d ", ksft_test_num()); + errno = saved_errno; vprintf(msg, args); va_end(args); } static inline void ksft_test_result_skip(const char *msg, ...) { + int saved_errno = errno; va_list args; ksft_cnt.ksft_xskip++; va_start(args, msg); printf("not ok %d # SKIP ", ksft_test_num()); + errno = saved_errno; vprintf(msg, args); va_end(args); } static inline void ksft_test_result_error(const char *msg, ...) { + int saved_errno = errno; va_list args; ksft_cnt.ksft_error++; va_start(args, msg); printf("not ok %d # error ", ksft_test_num()); + errno = saved_errno; vprintf(msg, args); va_end(args); } @@ -152,10 +163,12 @@ static inline int ksft_exit_fail(void) static inline int ksft_exit_fail_msg(const char *msg, ...) { + int saved_errno = errno; va_list args; va_start(args, msg); printf("Bail out! "); + errno = saved_errno; vprintf(msg, args); va_end(args); @@ -178,10 +191,12 @@ static inline int ksft_exit_xpass(void) static inline int ksft_exit_skip(const char *msg, ...) { if (msg) { + int saved_errno = errno; va_list args; va_start(args, msg); printf("not ok %d # SKIP ", 1 + ksft_test_num()); + errno = saved_errno; vprintf(msg, args); va_end(args); } else { -- 2.22.0