NetBSD Problem Report #55551
From www@netbsd.org Sat Aug 8 14:39:39 2020
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 5AFEB1A9239
for <gnats-bugs@gnats.NetBSD.org>; Sat, 8 Aug 2020 14:39:39 +0000 (UTC)
Message-Id: <20200808143938.058AB1A923A@mollari.NetBSD.org>
Date: Sat, 8 Aug 2020 14:39:37 +0000 (UTC)
From: soumendra@tamu.edu
Reply-To: soumendra@tamu.edu
To: gnats-bugs@NetBSD.org
Subject: [PATCH] script(1): Minor modification to tcgetattr error handling.
X-Send-Pr-Version: www-1.0
>Number: 55551
>Category: bin
>Synopsis: [PATCH] script(1): Minor modification to tcgetattr error handling.
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sat Aug 08 14:40:00 +0000 2020
>Last-Modified: Sat Aug 08 16:05:01 +0000 2020
>Originator: Soumendra Ganguly
>Release: 9.0
>Organization:
Texas A&M University
>Environment:
NetBSD localhost 9.0 NetBSD 9.0 (GENERIC) #0: Fri Feb 14 00:06:28 UTC 2020 mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/amd64/compile/GENERIC amd64
>Description:
Upon more testing, it was found that the way tcgetattr is called in script(1), it cannot fail with errno == EBADF under normal circumstances (*): script(1) of course does not close its own stdin/stdout voluntarily mid execution.
(*) The only way I was able to force an EBADF was by using
[ p close(1) ] in gdb. Therefore, the EBADF error handling is not removed by this patch, it is only changed to errno != ENOTTY.
>How-To-Repeat:
There is no problem. Only minor restructuring is being done.
>Fix:
--- src/usr.bin/script/script.c 2020-08-08 04:42:52.154774132 -0500
+++ script.c 2020-08-08 04:58:28.624464431 -0500
@@ -158,16 +158,10 @@
if (tcgetattr(STDIN_FILENO, &tt) == -1 ||
ioctl(STDIN_FILENO, TIOCGWINSZ, &win) == -1) {
- switch (errno) {
- case ENOTTY:
- if (openpty(&master, &slave, NULL, NULL, NULL) == -1)
- err(EXIT_FAILURE, "openpty");
- break;
- case EBADF:
- err(EXIT_FAILURE, "%d not valid fd", STDIN_FILENO);
- default: /* errno == EFAULT or EINVAL for ioctl. Not reached in practice. */
- err(EXIT_FAILURE, "ioctl");
- }
+ if (errno != ENOTTY) /* For debugger. */
+ err(EXIT_FAILURE, "tcgetattr/ioctl");
+ if (openpty(&master, &slave, NULL, NULL, NULL) == -1)
+ err(EXIT_FAILURE, "openpty");
} else {
if (openpty(&master, &slave, NULL, &tt, &win) == -1)
err(EXIT_FAILURE, "openpty");
@@ -383,9 +377,8 @@
struct termios traw;
if (tcgetattr(STDOUT_FILENO, &tt) == -1) {
- if (errno == EBADF)
- err(EXIT_FAILURE, "%d not valid fd", STDOUT_FILENO);
- /* errno == ENOTTY */
+ if (errno != ENOTTY) /* For debugger. */
+ err(EXIT_FAILURE, "tcgetattr");
return;
}
isterm = 1;
>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/55551 CVS commit: src/usr.bin/script
Date: Sat, 8 Aug 2020 12:01:35 -0400
Module Name: src
Committed By: christos
Date: Sat Aug 8 16:01:35 UTC 2020
Modified Files:
src/usr.bin/script: script.c
Log Message:
PR/55551 Soumendra Ganguly: Simplify tcgetattr error handling.
To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/script/script.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
(Contact us)
$NetBSD: gnats-precook-prs,v 1.4 2018/12/21 14:20:20 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.