From owner-freebsd-hackers@freebsd.org Mon Jan 8 18:05:31 2018 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 588B4E7B90C for ; Mon, 8 Jan 2018 18:05:31 +0000 (UTC) (envelope-from aduane@juniper.net) Received: from mx0a-00273201.pphosted.com (mx0a-00273201.pphosted.com [208.84.65.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.pphosted.com", Issuer "thawte SHA256 SSL CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 16EED6A17F; Mon, 8 Jan 2018 18:05:30 +0000 (UTC) (envelope-from aduane@juniper.net) Received: from pps.filterd (m0108159.ppops.net [127.0.0.1]) by mx0a-00273201.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w08HxBIQ020044; Mon, 8 Jan 2018 10:05:28 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=juniper.net; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=PPS1017; bh=4Ua6JlYOwEcwPzmMp2HKu68snB/7d2MlePhspaupCmU=; b=Pgdm1Suw5bE0hEGgbWkrgOv2o9hoeYbwU+0t48MKciH7RYkHiSz62HxwiNMbqQ4lXXv6 63Km9vPGqCX7N5WO+O0zfuEr88Qngqr0tvPdRtxQH6aThU4cJflHB0r7o7XsMRHwSrY3 k6BGpaF9kkDg3kGZZXKvclLCm2g4ad86zRDIJOqgN8skM0EkRSAF14r0Yfags0OHc38o SK1Lii203qZH5i4RUmvP55PwdbAwYUkD9QB0y94xBQOz9kwttD2H5Le7MaD+UfMNFuF2 /IO9GgSRJRH/g74xjzmqmSVbtvefUHqT1qJfB28Jcs32RI7z2d6tdcs5e3EEQZqqUExD jQ== Received: from nam02-bl2-obe.outbound.protection.outlook.com (mail-bl2nam02lp0082.outbound.protection.outlook.com [207.46.163.82]) by mx0a-00273201.pphosted.com with ESMTP id 2fc49715y0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 08 Jan 2018 10:05:28 -0800 Received: from SN1PR0501MB2125.namprd05.prod.outlook.com (10.163.228.152) by SN1PR0501MB2160.namprd05.prod.outlook.com (10.163.229.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.407.1; Mon, 8 Jan 2018 18:05:25 +0000 Received: from SN1PR0501MB2125.namprd05.prod.outlook.com ([10.163.228.152]) by SN1PR0501MB2125.namprd05.prod.outlook.com ([10.163.228.152]) with mapi id 15.20.0407.005; Mon, 8 Jan 2018 18:05:25 +0000 From: Andrew Duane To: Eric van Gyzen , "Rodney W. Grimes" , Eugene Grosbein CC: Yuri , Brooks Davis , Ian Lepore , Alan Somers , Freebsd hackers list Subject: RE: Is it considered to be ok to not check the return code of close(2) in base? Thread-Topic: Is it considered to be ok to not check the return code of close(2) in base? Thread-Index: AQHTiKloOfClzGJYSEGJa8gDMYWghaNqRGmQ Date: Mon, 8 Jan 2018 18:05:25 +0000 Message-ID: References: <201801081655.w08GtO3D022568@pdx.rh.CN85.dnsmgr.net> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [66.129.241.10] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; SN1PR0501MB2160; 7:lL1xNIZNlWknDTzVO04SApzOHZItSMu1viSTMHpFAb0wuSFvbn4roJ7/1zJjewB0RF105nMANwNJ0OSJ/oKgJ2GUEf+gBSq21QvA8EDaUzbjvhIUW5ukfxJmEXCCN52d2pldFSFKwFODmaHFJwk2z7wNQa9i9OcVBjwvxpJ2/3EOqivAOM5DZsYHuNIMxdZzcI9r23O47LT/aBp0ePiS51567XsHGXpc7O7u8/RYLA7dMSUXcYa5qWPnjkTjA+zc x-ms-exchange-antispam-srfa-diagnostics: SSOS; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: d78c0d50-0552-406a-9634-08d556c264d0 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020040)(48565401081)(5600026)(4604075)(3008032)(2017052603307)(7153060)(7193020); SRVR:SN1PR0501MB2160; x-ms-traffictypediagnostic: SN1PR0501MB2160: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(138986009662008); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(5005006)(8121501046)(3002001)(3231023)(944501098)(10201501046)(93006095)(93001095)(6055026)(6041268)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(20161123564045)(6072148)(201708071742011); SRVR:SN1PR0501MB2160; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:SN1PR0501MB2160; x-forefront-prvs: 054642504A x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(366004)(376002)(396003)(346002)(39860400002)(39380400002)(13464003)(199004)(189003)(24454002)(2950100002)(305945005)(81166006)(77096006)(68736007)(9686003)(5660300001)(55016002)(2906002)(97736004)(229853002)(4326008)(6436002)(66066001)(7736002)(6246003)(3280700002)(81156014)(8676002)(3660700001)(86362001)(7696005)(106356001)(76176011)(110136005)(105586002)(59450400001)(53546011)(6506007)(3846002)(6116002)(2900100001)(478600001)(74316002)(53936002)(33656002)(14454004)(316002)(25786009)(8936002)(102836004)(99286004)(54906003); DIR:OUT; SFP:1102; SCL:1; SRVR:SN1PR0501MB2160; H:SN1PR0501MB2125.namprd05.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; received-spf: None (protection.outlook.com: juniper.net does not designate permitted sender hosts) x-microsoft-antispam-message-info: FNxXjny9KMfxkBr6nGCUujY8loG/+JfBVYTdO6f7GQLX2SFrsvvFTpsIHK/Dc8kabeyVpLRZqH15lIO9y0SM4g== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: juniper.net X-MS-Exchange-CrossTenant-Network-Message-Id: d78c0d50-0552-406a-9634-08d556c264d0 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Jan 2018 18:05:25.7047 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: bea78b3c-4cdb-4130-854a-1d193232e5f4 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR0501MB2160 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-01-08_11:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_spam_notspam policy=outbound_spam score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1801080257 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Jan 2018 18:05:31 -0000 > -----Original Message----- > From: owner-freebsd-hackers@freebsd.org [mailto:owner-freebsd- > hackers@freebsd.org] On Behalf Of Eric van Gyzen > Sent: Monday, January 8, 2018 12:52 PM > To: Rodney W. Grimes ; Eugene > Grosbein > Cc: Yuri ; Brooks Davis ; Ian > Lepore ; Alan Somers ; Freebsd > hackers list > Subject: Re: Is it considered to be ok to not check the return code of cl= ose(2) > in base? >=20 > On 01/08/2018 10:55, Rodney W. Grimes wrote: > >> 08.01.2018 23:13, Eric van Gyzen wrote: > >> > >>> Right, which is the reason such bugs are hard to diagnose. > >>> Optionally killing the process on close->EBADF would help find buggy > >>> code when another thread did NOT re-open the file descriptor between > >>> the two close calls. > >> > >> Wouldn't "close(f); assert(errno !=3D EBADF);" be better? >=20 > Putting the code in one place is far better than putting it in N places..= .after > /finding/ those N places. Indeed, the purpose of this code is to help pe= ople > find those places, even in their own code, outside of base. >=20 > > Or even > > #ifdef DEBUG_CLOSE > > #define close(f) close(f); assert(errno !=3D EBADF); > > #endif >=20 > errno could have been EBADF before the close(). A successful close() doe= s > not modify errno. So, this would have be larger, making it even more > unpalatable. >=20 > > Then the people that want to go chasing these errors can, and the rest > > of us are untouched. >=20 > Every mention in this thread of killing the process has called it optiona= l. > Tools, not policy. >=20 > Eric Of course, my OCD will kick in and say this would need to be something like= : #ifdef DEBUG_CLOSE #define close(f) do {if (close(f) < 0) assert(errno !=3D EBADF); } while (0= ) #endif Have to watch those macro replacements like "if (need_to_close) close(f);".= And the close succeeding :-) .................................... Andrew L. Duane - Principal Resident Engineer AT&T Advanced Services Technical Lead Juniper Quality Ambassador m +1 603.770.7088 o +1 408.933.6944 (2-6944) skype: andrewlduane aduane@juniper.net