From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nihcesxway5.hub.nih.gov (nihcesxway5.hub.nih.gov [128.231.90.120]) by sourceware.org (Postfix) with ESMTPS id 0E7FD3858C56 for ; Sun, 26 Jun 2022 17:05:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0E7FD3858C56 X-SBRS-Extended: Low X-IronPortListener: ces-out X-IronPort-AV: E=Sophos;i="5.92,224,1650945600"; d="scan'208";a="338979858" Received: from unknown (HELO mail.nih.gov) ([156.40.79.161]) by nihcesxway5.hub.nih.gov with ESMTP/TLS/AES256-GCM-SHA384; 26 Jun 2022 13:05:05 -0400 Received: from nihexb2.nih.gov (156.40.79.162) by nihexb1.nih.gov (156.40.79.161) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.9; Sun, 26 Jun 2022 13:05:05 -0400 Received: from GCC02-BL0-obe.outbound.protection.outlook.com (156.40.79.133) by nihexb2.nih.gov (156.40.79.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.9 via Frontend Transport; Sun, 26 Jun 2022 13:05:05 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OKv3txOK95dCKpvgdlf0qwT9I4hHnqQvFsxtPtF91MfcKug+z/um4Dy6xBs0sUqTCu+7KzZBlUD5WDVdZ6sXYJxqK9zgony4bUsSgkzw8z3hBidlrXMuN5uLsOKs2F3cFDftD922wYC97B62rTlaatzYW17ohcuY26+xtFgPYugRLvvXdc7yolsvcgkNaxZJiKDfXWGjfhdvAMXdQIESKjr7Y6Mqp3/pVt6b/LDnThGsjv2PwZNzOlWbDUvl4js/5YvDWmmrK7GnzV2ceYR598xkJ30SUsnbsT1awXNHEPa3YknEj4mOt+gNeegatK52VTwy6N5MPbBrA7x5Tq8P6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=OmgZ1b6rWhiEXLUXBvrfYecFNJat8nu+ag8dRM66Jr4=; b=da/zK+4LCsYEp55iG5tAT7DnRZ9nANW9JFN/RWBGcJR2QxWkUKggfPCeb+eQn6hbYuzgJU7WVC1lWQAgCbZwI1WOB2LzKJ4FDiWzNJqvWQgamgL1UsajrHIGoIwD/ORSH50zIgpaNEPiyCTvgrJZ8IstlJi91srFB4Dn7/qkji+LxnA9NvBRhhh8Aoerh1OKNIxY3y1G8LdjpPfrUB60qilwxHnXEsEFD2rS1f9Wl8HsUNo4pXKAV1n0rqtx2AmIWigYmrkM6pmsX2Yy6n4+G5cUiGzg8b9B8iCxRcjT2lJcRt/A/l9r3N3RyaA9zN+G+8nGIM/JMKMBbDTjkm3ViA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=ncbi.nlm.nih.gov; dmarc=pass action=none header.from=ncbi.nlm.nih.gov; dkim=pass header.d=ncbi.nlm.nih.gov; arc=none Received: from DM8PR09MB7095.namprd09.prod.outlook.com (2603:10b6:5:2e3::14) by DM6PR09MB4822.namprd09.prod.outlook.com (2603:10b6:5:261::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.15; Sun, 26 Jun 2022 17:04:58 +0000 Received: from DM8PR09MB7095.namprd09.prod.outlook.com ([fe80::282a:38f8:c3b5:8f5b]) by DM8PR09MB7095.namprd09.prod.outlook.com ([fe80::282a:38f8:c3b5:8f5b%7]) with mapi id 15.20.5373.015; Sun, 26 Jun 2022 17:04:58 +0000 From: "Lavrentiev, Anton (NIH/NLM/NCBI) [C]" To: "'cygwin@cygwin.com'" Subject: poll() is buggy for duplicate file descriptors inquired for different events Thread-Topic: poll() is buggy for duplicate file descriptors inquired for different events Thread-Index: AdiJfM3OzZaW3H5sS+uh4gnASgxp6g== Date: Sun, 26 Jun 2022 17:04:58 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: f4012f5d-a9c5-4123-10f6-08da57960029 x-ms-traffictypediagnostic: DM6PR09MB4822:EE_ x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: NCjvOh6/09vO5Nlf0N7oMMW5p/4IHsMTiF69/3aTq73uNiy8BPavjQCsm+U4XLHufC9ynWg9Yr6e3YfP8c36gIjf8ywhah5Y9ayEDJTSr/urHsmQSiWQ8DBt/iM/bET6cUg/Kz1UgHzI0N+DLnaFLKGBit4jDMD37fyasY5uUjJAIUo88v4M5GrMauZZpwVblQW54J1ZXVacdfaBOU2QSqgmslTdehUsHP5al2yl2LdHneHUdM5dOTneGlnED2BifGBinDvPr25SUWgag2g1vNT/Kbnzm5yEQ9ppnoB8Nn7rTQKptvjGFWUp8ipvOwecAoAKeEbnmX3fwlZ8601Y2vinLTHuisTIgGry5rr1lKC/nrz0yZmTKwIekeuAD8ulS9p7tNEkYvy37gtKf8AohdO1Mj6eKMVtcfmsr/MV4QwySUBfCWYR+uZ9Mmp7yd9tNHt8c+kEDtgwIjL/LyZotkbNs9nDB9tr9SBwXs5DP0bmuDVfTmd7RMHK7CBTdCePhM0DxXEXtffEkpj3AWzuLnKH4GIpBpL4/K4+2w5bPW5KfAtr8vF9gmNUHq7qHLGP5PR3Y+6NFXGGXU+4kuqQmyqirO4yGM7yZt3VnfNYjwyxu64NKHtjinsN5OF/0B/HlD7OEnzakdlMv09vPjQDOmBjSBsJ5OV2IJ6gNUFBx/iNrSHYTlKxUN9hE2kJCfpGGxQV5eBvI5O3ouKmbicTKN3cJuxFAlYxZxUz+0sZodfZX2SjnJJ8TZ7saEc2/+pjc7+dD1z2fLme8YDuyuCM5XfQ1+Sv3VBMtXLoTN//LvnEpunRqB4DJznmhg5CXGAr x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM8PR09MB7095.namprd09.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(366004)(8936002)(52536014)(498600001)(6506007)(66946007)(26005)(7696005)(86362001)(2906002)(38100700002)(33656002)(9686003)(83380400001)(38070700005)(8676002)(122000001)(5660300002)(55016003)(64756008)(76116006)(186003)(71200400001)(66556008)(66446008)(66476007)(6916009)(491001); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?wxHfrz2ebR69HvpkaDXzGTjgd93xPcp4wAbQIFax+mFIlH3BD7LzoIMKL1IG?= =?us-ascii?Q?v6LP1zTe8XAiYwxKH/EstwfGF1naEXJkUA221ZYL6OiUvDXri2OqB0wVEEt3?= =?us-ascii?Q?W36Fqg9bbUt4VZw2/bjDAlcdHo3YOUqhJBpLvlEFk4Hjtrtxs/yKxJvlGYSw?= =?us-ascii?Q?QW6DgfVB7AsoM8qsuyYu5AonEH9eTnB9CmUVkaGBHhqUWvbJ0pGlV+bgWO4E?= =?us-ascii?Q?2vXjRQccWxj709mjY0VnuDPleOZCIOFNa/ZBIEI38q3Ex10vGrhGMyI/GnlT?= =?us-ascii?Q?z9SFZ0/Olxj7H67hCdfUnahlA7bDhfrQIGfwv8fkzXwp/HllPgzDpdnC/e7x?= =?us-ascii?Q?yfwszvRpMCX2hYLlVlbkxvGIXTzE2Vdo+G8rDDAU9Tfm7/+L3/uvSo+uaNp+?= =?us-ascii?Q?nlsbbFPDx5ZguBJcK5+09dxiw4Uqz0h4ltwePoQQQHjmlVFL6giW9XNTNW1R?= =?us-ascii?Q?SDN1fU/njMtl8XW5hp3tW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QIX?= =?us-ascii?Q?c26qxeBuhgpuuKt+tZGg/Ww5l/V7X2Y4zm0kOLx4+mQcUN2g6rav4DES3t+P?= =?us-ascii?Q?IU/dvPWxR0MfFN3D9Ia1A8i5sRxDUnfRLoahkFWXcCxLHpuYreLKsWXqLFGM?= =?us-ascii?Q?tRQCB6NYunwUNN3pzsVb4MDcpHQaJDpFK0b4xIqIJaBrBjhlr/dE8+EomW6a?= =?us-ascii?Q?YyEz4Yp+gkJY44tukKU=3D?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM8PR09MB7095.namprd09.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: f4012f5d-a9c5-4123-10f6-08da57960029 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Jun 2022 17:04:58.5123 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 14b77578-9773-42d5-8507-251ca2dc2b06 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR09MB4822 X-OriginatorOrg: ncbi.nlm.nih.gov X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, T_SPF_HELO_PERMERROR autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: cygwin@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Jun 2022 17:05:07 -0000 Hi, It looks like if a file descriptor is inquired a few times in a poll() call= with different events (and for one of those events the file descriptor is = "ready"), only that occurrence gets reported correctly, and all other occurrences get= the returned event just "copied over" (and thus, it may be incompatible wi= th the query for that occurrence). The following simple test case demonstrates this: $ cat poll.c=20 #include #include #include int main() { int n; struct pollfd pfd[2]; memset(pfd, 0, sizeof(pfd)); pfd[0].fd =3D 1; pfd[0].events =3D POLLOUT; pfd[1].fd =3D 1; pfd[1].events =3D POLLIN; =20 n =3D poll(pfd, 2, 1000); printf("n =3D %d\n" "[0].fd =3D %d\n" "[0].event =3D %d\n" "[0].revent =3D %d\n" "[1].fd =3D %d\n" "[1].event =3D %d\n" "[1].revent =3D %d\n", n, pfd[0].fd, pfd[0].events, pfd[0].revents, pfd[1].fd, pfd[1].events, pfd[1].revents); pfd[1].revents =3D 0; n =3D poll(&pfd[1], 1, 1000); printf("n =3D %d\n" "[1].fd =3D %d\n" "[1].event =3D %d\n" "[1].revent =3D %d\n", n, pfd[1].fd, pfd[1].events, pfd[1].revents); return 0; } $ gcc -Wall -o poll poll.c $ ./poll n =3D 2 [0].fd =3D 1 [0].event =3D 4 [0].revent =3D 4 [1].fd =3D 1 [1].event =3D 1 [1].revent =3D 4 n =3D 0 [1].fd =3D 1 [1].event =3D 1 [1].revent =3D 0 Note that "stdout" is inquired about ready-to-write (in [0]) and ready-to-r= ead (in [1]). Because it is ready-to-write, poll() returns immediately, but also having t= he response ready-to-write in [1], where only "read"-compatible status (POLLIN, or POLL= HUP, or POLLERR, or just 0, if nothing of sorts was available) should have been posted -- bu= t *never* POLLOUT! Also note that [1] should have never been flagged as "ready", either, so th= e return code should have been 1, not 2. Finally note that if [0] and [1] were swapped so that [0] was inquired for = POLLIN, and [1] was inquired for POLLOUT, the result would have still been incorrect on Cygwin ([0] returning POLLOUT= for POLLIN inquired). For the second invocation, when inquired just singly, the response is corre= ct. Now compare it with the correct behavior of the same code, all through, on = Linux: $ ./poll n =3D 1 [0].fd =3D 1 [0].event =3D 4 [0].revent =3D 4 [1].fd =3D 1 [1].event =3D 1 [1].revent =3D 0 n =3D 0 [1].fd =3D 1 [1].event =3D 1 [1].revent =3D 0 P.S. The manual page for poll(2) says: The bits returned in revents can include any of those specified in events, = or one of the values POLLERR, POLLHUP, or POLLNVAL. So returning POLLOUT(4) for POLLIN(1) violates the rule: bit 0 is NOT set i= n the binary representation of 4. Anton Lavrentiev Contractor NIH/NLM/NCBI