Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4682795ybi; Sat, 20 Jul 2019 04:04:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqyIpbYO91iPq0cJ2Qnyx/NPI5Pr9RBEQpy+ZefXx8xa04ogwhcYklgXNVJs3G80TuoAATIh X-Received: by 2002:a17:90a:d791:: with SMTP id z17mr60391622pju.40.1563620678575; Sat, 20 Jul 2019 04:04:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563620678; cv=none; d=google.com; s=arc-20160816; b=XfFe9glrwXTMEbgoYROMUfFihcdHi+ajn3Nbm+k66x+oiQaplUQxh6srbDidZVYLlK N6qEyuHHGp4zai2B540rwuvRORjcvfqUZAm9yQJeCXF7DGM10okTuheh588VVlzotg1+ Zkv85VEyXptRKYjlxvgD0dP8hckSuEqPWgybwZPTye2os3e81Vq8fWXUNyxuQHHHOZKq JCM6ma3txUlvlFwdibLNnmTonM2bZGzhs5lXT4mEKV1sHwCAe88pDpFbDcgbGiUz190f P9ezX4+vnL7VnWnw7O0flTJhKdipML3mFk4yx4nc3+YS7VRD3JLn0PywGqyTFzgwoC9w hdAA== 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=wlBmkeYPJaw/LQzz212hxQbN2YHPWTvW+dGh4ppPw8I3wRVlydYuMn+xRbJMnS2eNe qZ9JtpSzpRbVu0k2Co3J64jZlRsqm9LptRFNT6/zCrcwTJTTxSsmDRB58U/p79QQeRc5 dxI55Qq0/XWNDgmgCSixqeRtiQJJjai7PU8O7ZGlPJ/5Ni4SIBG2aMM2zbtL+AA6liKW aWC9NibrJmaWU9anIkFbjB7B3BjsdCPGl4hwutDvnJLpGNzC9OlKN9PrSvgV31TXAVS0 Q6CF0b2AGmRGV7XiTphRq0+NAFlTR2541T6aP28T60Wv4oW2dRbZH2KwoIDppIdpHkvp EI6g== 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 t129si8210883pfb.16.2019.07.20.04.03.36; Sat, 20 Jul 2019 04:04:38 -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 S1732723AbfGTADz (ORCPT + 99 others); Fri, 19 Jul 2019 20:03:55 -0400 Received: from mx2.mailbox.org ([80.241.60.215]:21686 "EHLO mx2.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728929AbfGTADy (ORCPT ); Fri, 19 Jul 2019 20:03:54 -0400 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id C762AA1050; Sat, 20 Jul 2019 02:03:52 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter01.heinlein-hosting.de (spamfilter01.heinlein-hosting.de [80.241.56.115]) (amavisd-new, port 10030) with ESMTP id GTv2JeZDgEMV; Sat, 20 Jul 2019 02:03:46 +0200 (CEST) From: Aleksa Sarai To: Shuah Khan Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Aleksa Sarai Subject: [PATCH] kselftest: save-and-restore errno to allow for %m formatting Date: Sat, 20 Jul 2019 10:03:32 +1000 Message-Id: <20190720000332.4701-1-cyphar@cyphar.com> In-Reply-To: References: 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