From patchwork Sun Sep 11 10:50:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marius Bakke X-Patchwork-Id: 42473 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 12B2A27BBEA; Sun, 11 Sep 2022 11:52:51 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 7DABB27BBE9 for ; Sun, 11 Sep 2022 11:52:50 +0100 (BST) Received: from localhost ([::1]:39614 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oXKa1-0006jo-LC for patchwork@mira.cbaines.net; Sun, 11 Sep 2022 06:52:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52036) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oXKZJ-0006jc-1S for guix-patches@gnu.org; Sun, 11 Sep 2022 06:52:05 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:52151) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oXKZG-0004Nb-NU for guix-patches@gnu.org; Sun, 11 Sep 2022 06:52:04 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oXKZG-0002PK-JG for guix-patches@gnu.org; Sun, 11 Sep 2022 06:52:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#57730] [PATCH] syscalls: Adjust for glibc 2.34 and later. Resent-From: Marius Bakke Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 11 Sep 2022 10:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 57730 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 57730@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16628934799194 (code B ref -1); Sun, 11 Sep 2022 10:52:02 +0000 Received: (at submit) by debbugs.gnu.org; 11 Sep 2022 10:51:19 +0000 Received: from localhost ([127.0.0.1]:40850 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oXKYZ-0002OD-A2 for submit@debbugs.gnu.org; Sun, 11 Sep 2022 06:51:19 -0400 Received: from lists.gnu.org ([209.51.188.17]:43206) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oXKYW-0002O5-89 for submit@debbugs.gnu.org; Sun, 11 Sep 2022 06:51:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59972) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oXKYP-0006dT-M3 for guix-patches@gnu.org; Sun, 11 Sep 2022 06:51:15 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:49700) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oXKYL-0004G2-VJ for guix-patches@gnu.org; Sun, 11 Sep 2022 06:51:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=/Qxredzk5ozggEJNQUcuSOqrF4rgmgtqakyrukl7ZRQ=; b=V4Jr8YSUtzvpVc n8fg4OCrtY3ZPUFR9YXAiwwQhRIwq5kQunMQ6QUsb8eiF4MABvT7PcE+jbrtgqgTMZsT6F+FR+A8Q oG4zuRGCanVWDAZCz9IPFR5Sr1JSp61u9Q9AUK6Ku0s6Xte1cKWaazxqA1EPmAtvlm7JD7T2ul6ix DuvUr5LgD0tdBnieXj8LqELxF+0h6hcKgAn2j9RowpNlm08HMFM9vnbi8TKUpr96UWSnaYz4AurzI IQ9LnvYdgJt8tLg0+JubNISSjxLXwF/AtKG2eLwMQdSWxf98EWFkvU4HC/LxOcZj3XznD5rAV1/go CVWU//M4WIHF9qyH067Q==; Received: from [84.214.173.6] (port=57546 helo=localhost) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oXKYE-0005kP-Gs for guix-patches@gnu.org; Sun, 11 Sep 2022 06:51:05 -0400 From: Marius Bakke Date: Sun, 11 Sep 2022 12:50:51 +0200 Message-Id: <20220911105051.16901-1-marius@gnu.org> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches This is a re-implementation of 3c8b6fd94ceb1e898216929e8768fb518dbf1de9 that works with new and old libc's. * guix/build/syscalls.scm (openpty, login-tty): Wrap in exception handlers and retry with libutil if the first call is unsuccessful. --- guix/build/syscalls.scm | 71 ++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm index b00615d9b7..eee90216eb 100644 --- a/guix/build/syscalls.scm +++ b/guix/build/syscalls.scm @@ -9,6 +9,7 @@ ;;; Copyright © 2021 Chris Marusich ;;; Copyright © 2021 Tobias Geerinckx-Rice ;;; Copyright © 2022 Oleg Pykhalov +;;; Copyright © 2022 Marius Bakke ;;; ;;; This file is part of GNU Guix. ;;; @@ -2339,39 +2340,57 @@ (define* (terminal-rows #:optional (port (current-output-port))) (terminal-dimension window-size-rows port (const 25))) (define openpty - (let ((proc (syscall->procedure int "openpty" '(* * * * *) - #:library "libutil"))) - (lambda () - "Return two file descriptors: one for the pseudo-terminal control side, + (lambda* (#:optional library) + "Return two file descriptors: one for the pseudo-terminal control side, and one for the controlled side." + (let ((proc (syscall->procedure int "openpty" '(* * * * *) + #:library library))) (let ((head (make-bytevector (sizeof int))) (inferior (make-bytevector (sizeof int)))) - (let-values (((ret err) - (proc (bytevector->pointer head) - (bytevector->pointer inferior) - %null-pointer %null-pointer %null-pointer))) - (unless (zero? ret) - (throw 'system-error "openpty" "~A" - (list (strerror err)) - (list err)))) - - (let ((* (lambda (bv) - (bytevector-sint-ref bv 0 (native-endianness) - (sizeof int))))) - (values (* head) (* inferior))))))) + (catch 'system-error + (lambda () + (let-values (((ret err) + (proc (bytevector->pointer head) + (bytevector->pointer inferior) + %null-pointer %null-pointer %null-pointer))) + (unless (zero? ret) + (throw 'system-error "openpty" "~A" + (list (strerror err)) + (list err))) + + (let ((* (lambda (bv) + (bytevector-sint-ref bv 0 (native-endianness) + (sizeof int))))) + (values (* head) (* inferior))))) + (lambda args + (if (and (= (system-error-errno args) 38) + (not library)) + ;; Prior to glibc 2.34, openpty resided in libutil. + ;; Try again, fingers crossed! + (openpty "libutil") + (apply throw args)))))))) (define login-tty - (let* ((proc (syscall->procedure int "login_tty" (list int) - #:library "libutil"))) - (lambda (fd) - "Make FD the controlling terminal of the current process (with the + (lambda* (fd #:optional library) + "Make FD the controlling terminal of the current process (with the TIOCSCTTY ioctl), redirect standard input, standard output and standard error output to this terminal, and close FD." - (let-values (((ret err) (proc fd))) - (unless (zero? ret) - (throw 'system-error "login-pty" "~A" - (list (strerror err)) - (list err))))))) + (let ((proc (syscall->procedure int "login_tty" (list int) + #:library library))) + (catch 'system-error + (lambda () + (let-values (((ret err) (proc fd))) + (unless (zero? ret) + (throw 'system-error "login-pty" "~A" + (list (strerror err)) + (list err))))) + (lambda args + (if (and (= (system-error-errno args) 38) + (not library)) + ;; Prior to glibc 2.34, login-pty resided in libutil. + ;; Try again, fingers crossed! + (login-tty fd "libutil") + (apply throw args))))))) ;;;