From patchwork Tue Jul 7 21:54:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 39951 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ECA6C3851C1F; Tue, 7 Jul 2020 21:54:42 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from hera.aquilenet.fr (hera.aquilenet.fr [185.233.100.1]) by sourceware.org (Postfix) with ESMTPS id 97557385ED4B for ; Tue, 7 Jul 2020 21:54:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 97557385ED4B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=samuel.thibault@ens-lyon.org Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 90AC6272C; Tue, 7 Jul 2020 23:54:39 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Gin9EVIzDjR5; Tue, 7 Jul 2020 23:54:38 +0200 (CEST) Received: from function.home (lfbn-bor-1-797-11.w86-234.abo.wanadoo.fr [86.234.239.11]) by hera.aquilenet.fr (Postfix) with ESMTPSA id BFB93271C; Tue, 7 Jul 2020 23:54:38 +0200 (CEST) Received: from samy by function.home with local (Exim 4.94) (envelope-from ) id 1jsvXx-003z1r-PN; Tue, 07 Jul 2020 23:54:37 +0200 From: Samuel Thibault To: libc-alpha@sourceware.org Subject: [hurd,commited] hurd: Fix strerror not setting errno Date: Tue, 7 Jul 2020 23:54:37 +0200 Message-Id: <20200707215437.949537-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: commit-hurd@gnu.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" * sysdeps/mach/strerror_l.c: Include . (__strerror_l): Save errno on entry and restore it on exit. --- sysdeps/mach/strerror_l.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/sysdeps/mach/strerror_l.c b/sysdeps/mach/strerror_l.c index 72b857f4a0..dacb7e4d95 100644 --- a/sysdeps/mach/strerror_l.c +++ b/sysdeps/mach/strerror_l.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +41,8 @@ translate (const char *str, locale_t loc) char * __strerror_l (int errnum, locale_t loc) { + int saved_errno = errno; + char *err; int system; int sub; int code; @@ -61,15 +64,15 @@ __strerror_l (int errnum, locale_t loc) errnum) == -1) tls_internal->strerror_l_buf = NULL; + __set_errno (saved_errno); return tls_internal->strerror_l_buf; } es = &__mach_error_systems[system]; if (sub >= es->max_sub) - return (char *) translate (es->bad_sub, loc); - - if (code >= es->subsystem[sub].max_code) + err = (char *) translate (es->bad_sub, loc); + else if (code >= es->subsystem[sub].max_code) { struct tls_internal_t *tls_internal = __glibc_tls_internal (); free (tls_internal->strerror_l_buf); @@ -79,10 +82,13 @@ __strerror_l (int errnum, locale_t loc) errnum) == -1) tls_internal->strerror_l_buf = NULL; - return tls_internal->strerror_l_buf; + err = tls_internal->strerror_l_buf; } + else + err = (char *) translate (es->subsystem[sub].codes[code], loc); - return (char *) translate (es->subsystem[sub].codes[code], loc); + __set_errno (saved_errno); + return err; } weak_alias (__strerror_l, strerror_l) libc_hidden_def (__strerror_l)