From patchwork Mon Apr 18 19:53:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Serge E. Hallyn" X-Patchwork-Id: 611879 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qpf424FY6z9sdb for ; Tue, 19 Apr 2016 05:54:26 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=UBF0846b; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:references :mime-version:content-type:in-reply-to; q=dns; s=default; b=p5l8 3tY/ZVpLp5PU0C8QvDijEzwoSS1jtusZEHf7Qff0Hwm2Jud251QWqsiZRBMjLeux S1hbWVUf2R9n2xwM4/qry8eqPwzuBpTEtRU0cuCUXlwVMJg9HkiIVqkoNoDwZCyP Tp2mbn1hOJ8PG3giaaNEuG/36PqG5ouuBv0QY8k= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:references :mime-version:content-type:in-reply-to; s=default; bh=JWBAYPTPt9 bBbJFyNc0C3eTBrWE=; b=UBF0846blVBm2P7BN00CqwjZUJx9j9w50XThtg1u4B TucbLNDMClr2Eq1ssk+OpQ6AQGFaTQMH7UGRPdwBSZO9FQB8XAAk2QAPmMU+hZts cKwkwJRkEjTqWOUZELPFqYm/NzRE1rGCkFRm6ZMlzQWp2K++LtzfLn7IPC2V8UBg 0= Received: (qmail 70173 invoked by alias); 18 Apr 2016 19:54:04 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 70089 invoked by uid 89); 18 Apr 2016 19:54:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.7 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2 spammy=strcpy, H*Ad:D*ubuntu.com, our X-HELO: youngberry.canonical.com Date: Mon, 18 Apr 2016 19:53:49 +0000 From: Serge Hallyn To: libc-alpha@sourceware.org, Serge Hallyn Subject: [PATCH 2/2] linux ttyname_r: return link if appropriate Message-ID: <20160418195349.GC30476@ubuntumail> References: <20160415152929.GA7932@ubuntumail> <5711165D.5040902@redhat.com> <20160415164652.GE8450@ubuntumail> <57111F9C.8030902@redhat.com> <20160415174245.GA9610@ubuntumail> <20160415184746.GA10830@ubuntumail> <20160415195938.GP6588@vapier.lan> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20160415195938.GP6588@vapier.lan> User-Agent: Mutt/1.5.21 (2010-09-15) Same as previous commit for ttyname --- sysdeps/unix/sysv/linux/ttyname_r.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/sysdeps/unix/sysv/linux/ttyname_r.c b/sysdeps/unix/sysv/linux/ttyname_r.c index d15bc74..e3d0c8b 100644 --- a/sysdeps/unix/sysv/linux/ttyname_r.c +++ b/sysdeps/unix/sysv/linux/ttyname_r.c @@ -32,6 +32,19 @@ static int getttyname_r (char *buf, size_t buflen, dev_t mydev, ino64_t myino, int save, int *dostat) internal_function; +/* Return true if this is a UNIX98 pty device, as defined in + linux/Documentation/devices.txt */ +static int +is_pty (struct stat64 *sb) +{ +#ifdef _STATBUF_ST_RDEV + int m = major (sb->st_rdev); + return (136 <= m && m <= 143); +#else + return false; +#endif +} + static int internal_function attribute_compat_text_section getttyname_r (char *buf, size_t buflen, dev_t mydev, ino64_t myino, @@ -158,6 +171,15 @@ __ttyname_r (int fd, char *buf, size_t buflen) #endif ) return 0; + + /* If the link doesn't exist, then it points to a device in another + namespace. If it is a UNIX98 pty, then return the /proc/self + fd, as it points to a name unreachable in our namespace */ + if (is_pty (&st) && strlen (procname) < buflen - 1) + { + strcpy (buf, procname); + return 0; + } } /* Prepare the result buffer. */