Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp16332ybm; Mon, 20 May 2019 11:03:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqztlnTa9FLMVO2rOrJTsmWlRApLQvvhyUM0QC1ZDj1e87ptH9tRZSnaNCGLJ4FP9/1lPFsn X-Received: by 2002:a17:902:e108:: with SMTP id cc8mr66537671plb.145.1558375414800; Mon, 20 May 2019 11:03:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558375414; cv=none; d=google.com; s=arc-20160816; b=zelRnv/8n23W/3Olyj9mwqVj9MkHD4YpKPasim7ZPAdk3InkRvAQDAypMydL5vjY0L F09VVU6Pd/twfSys4ur3a3LhT4M1t6FTrh2cEzJUjgSw5TqT0oR9Jk1yAT44uI9tkC3v mzFMAJZ1xJBZb+mBSra7EqZDFynsa/4LD7An040ht9ebjNM3/mwxBycayI3PQQl3vIRB 5klZBVMzxG0Q+gbzW8GK6XtIny2VV+o1dl6jQn3US76sF2y8K5vZvaxiyGrLrvr8L0Dm LWzPotBuNUpcinnkNJAbpxwwSuoyFz4mKej48jSX181WKP//6OEqUSv+pto50yUJohct 9LYA== 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=GAdvMCUvuLwRT1yh39Xe7KIp1qU1DN3MbLxBH+bnmbA=; b=ru5lexGvRhZJq1ZlcSk3+FlE38+9Bje2YD89CF3s0nXP0xxG6qoDUwb4nx7oOgepDa HnS4seCSNDDeBJspuFdQn5wBse+VCHJzgxMJCrUezWASWPXInW3UFQDPsGu7yKdPY8Aw JrKjv5AgOIjumjAjtunfcKSjYvF7aA/nCDqQ/A4Q9yU+BXI4Er5LuzHOKCLUOzEJiQ9R QwOjO6HZ050y6N8TB0l9DcfbkvUeaFMQp84xi+qSBqHHIjY0bAyktA/uK6ldm4GL+pye Z557KbcGcJoPQv+k99BIC+Hj7dZfUQ3S/Vvn8q+2KxWK5Bs9WaSEgSWyu6FxZ6G4w0+9 B0Cw== 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 d15si19526340plj.91.2019.05.20.11.03.19; Mon, 20 May 2019 11:03:34 -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 S2388497AbfETNfk (ORCPT + 99 others); Mon, 20 May 2019 09:35:40 -0400 Received: from mx1.mailbox.org ([80.241.60.212]:63538 "EHLO mx1.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725951AbfETNfk (ORCPT ); Mon, 20 May 2019 09:35:40 -0400 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2: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 3B42E50122; Mon, 20 May 2019 15:35:37 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter04.heinlein-hosting.de (spamfilter04.heinlein-hosting.de [80.241.56.122]) (amavisd-new, port 10030) with ESMTP id SNqFqrdz-AGP; Mon, 20 May 2019 15:35:34 +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-kselftest@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org Subject: [PATCH RFC v8 09/10] kselftest: save-and-restore errno to allow for %m formatting Date: Mon, 20 May 2019 23:33:04 +1000 Message-Id: <20190520133305.11925-10-cyphar@cyphar.com> In-Reply-To: <20190520133305.11925-1-cyphar@cyphar.com> References: <20190520133305.11925-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 47e1d995c182..ce049af7415b 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 @@ -72,58 +73,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("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); } @@ -143,10 +154,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); @@ -169,10 +182,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("1..%d # Skipped: ", ksft_test_num()); + errno = saved_errno; vprintf(msg, args); va_end(args); } else { -- 2.21.0