From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 2B4361F5AE for ; Tue, 27 Apr 2021 07:16:03 +0000 (UTC) Received: from localhost ([::1]:60160 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lbHww-0005IN-9i for normalperson@yhbt.net; Tue, 27 Apr 2021 03:16:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52684) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbHvx-0004dX-P9 for bug-gnulib@gnu.org; Tue, 27 Apr 2021 03:15:01 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]:53894) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lbHvw-0006jC-5T for bug-gnulib@gnu.org; Tue, 27 Apr 2021 03:15:01 -0400 Received: by mail-wm1-x332.google.com with SMTP id i129so4208305wma.3 for ; Tue, 27 Apr 2021 00:14:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=awNQRYtytU4wVtiFa/MQOcTJH4wDJXo9myM5QoOUK5E=; b=CiUx1EM69Sgohfuc1EIyLKid5TfV/AVycaUjTcXnzOmbWSxC7USr+0ioCoTi/WsEZF d3pbFtN1Qa0qn1VsAWPMdDEKS8ep4n1giuWmB3Lj4IaH7yfAoQR8y8AECoN4Pe3eLA2Q N06pJHVYnq2rUuwvn2qx639jHxja5xKI3nkKyGl+zns7L4PQVzmTHi+gxDJUoMeEq2dn fqI85zmEyhxSGZ8TaJRRi99KslkKM7/vH6JH1sdo7pqKWO7B9LBmDl8kwvs9crJggENO 4bGifGw2icyy1u6kg6UeWt0N3857Wktd8dXNmBQAGdp5JWYMAM/sJg7epM5/6stRC61J fZBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=awNQRYtytU4wVtiFa/MQOcTJH4wDJXo9myM5QoOUK5E=; b=Q9rMnkx9rc5g2r+O8SBMZEuRK+znQnrvBYfAziRs85YFEzFro/wET5nNe4SWsSOMC0 x0Fnk6l5aLeL77PoV20McoWHHelfj+JO9OJFseRXVqIWBp+rJSibrllWSc8SZls+OEGH nqjEY6vcPS6ZzL7yY1C/MX7DkF+n6L5DTCwBIcm+3nhqCxVhS419Fk/pbeam0vUHgxcJ Bq8O+k5Kqiqh0XLDAYGDVO4HrNo2rvmmxU8QScXrIL88+mQ+EfG3MHfy2Bn7wyxIMVBj ggRqqC8FRdQrVoUpwwwwMJ0xGjaasKOqCqZ66/zfgWbjSzrfEWBZlqtvHik90Md3pjSx m8cw== X-Gm-Message-State: AOAM533wddQa/ZMDwM/kuXkUDDB5/hV3223w4hhfgPdPyrCpLSvMWMoZ 9RSELf2agJn8Y2yMF/CZ8M3gh6INZgI= X-Google-Smtp-Source: ABdhPJwzqK1gt61dIWd36MFW7oofEHfAdZOe59vNOjDMLugNFVR1pi1yCbKtcAUnfbpACR+31u6j4Q== X-Received: by 2002:a1c:c910:: with SMTP id f16mr2784397wmb.136.1619507697138; Tue, 27 Apr 2021 00:14:57 -0700 (PDT) Received: from portable-bastien.localnet ([2a01:e0a:3d3:9cc1:cd42:7140:6b8f:d751]) by smtp.gmail.com with ESMTPSA id q5sm1603129wmj.20.2021.04.27.00.14.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Apr 2021 00:14:55 -0700 (PDT) From: Bastien =?ISO-8859-1?Q?Roucari=E8s?= To: "bug-gnulib@gnu.org" , Erik Blake , mtk.manpages@gmail.com Subject: Portabilty of poll trick Date: Tue, 27 Apr 2021 07:14:53 +0000 Message-ID: <2051587.bS8k0qy9eM@portable-bastien> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart2021359.0NZ9DvIWb3"; micalg="pgp-sha512"; protocol="application/pgp-signature" Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=roucaries.bastien@gmail.com; helo=mail-wm1-x332.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, FREEMAIL_REPLY=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" --nextPart2021359.0NZ9DvIWb3 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii"; protected-headers="v1" From: Bastien =?ISO-8859-1?Q?Roucari=E8s?= To: "bug-gnulib@gnu.org" , Erik Blake , mtk.manpages@gmail.com Subject: Portabilty of poll trick Date: Tue, 27 Apr 2021 07:14:53 +0000 Message-ID: <2051587.bS8k0qy9eM@portable-bastien> Hi, I want to assess the safety and portability of the following trick, for getting outside poll. Replacing by using dup2 a read poll object by a writtable one. I think to use this for stopping polling in multithread program It work really well, and could for instance allow me to tear down eventfd of other event like file that does not support shutdown CC also Michael Kerrisk (mtk.manpages@gmail.com) for comments on this trick #include #include #include #include #include #include #include static void *run_poll (void *arg) { struct pollfd fds[1]; int rc; fds[0].fd = ((int *)arg)[0]; fds[0].events = POLLERR | POLLHUP | POLLNVAL | POLLIN; // // Poll indefinitely // printf("starting poll\n"); fflush(stdout); rc = poll((struct pollfd *) &fds, 1, -1); if ( rc == -1 ) { printf("POLL returned error %d: %s\n", errno, strerror(errno)); } else { printf("POLL returned %d (revents = 0x%08x): %s %s %s %s %s\n", rc, fds[0].revents, ( ( fds[0].revents & POLLIN ) ? "pollin" : "noin" ), ( ( fds[0].revents & POLLOUT ) ? "pollout" : "noout" ), ( ( fds[0].revents & POLLERR ) ? "pollerr" : "noerr" ), ( ( fds[0].revents & POLLHUP ) ? "pollhup" : "nohup" ), ( ( fds[0].revents & POLLNVAL ) ? "pollnval" : "nonval" )); } return NULL; } int main (int argc, char **argv) { pthread_t thread; int rc; int fdst[2]; pipe(fdst); rc = pthread_create(&thread, NULL, run_poll, &fdst); sleep(3); printf("removing access\n"); dup2(fdst[0],fdst[1]); sleep(3); return 0; } --nextPart2021359.0NZ9DvIWb3 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEXQGHuUCiRbrXsPVqADoaLapBCF8FAmCHue0ACgkQADoaLapB CF+cZw//ZLkBbQZczrwGuwCLBtGbYdF04qcH6pVkpfefDNhfXUEYqn9p0+YA01Ec 1l+HWAHZfB7ssQ1CgoM3xR2bA71IB6234atTk/5dGqHY4SmTvA/fEYKXDZmVg3Zh f1d+fx0u/MWambQOF0Q2mP8T/XIt7cy9mKZT8EUeKkkEJP/iX7beYsK3h0ODu0Gh vHelmNy6n6Qukvgp1qEqka66dRPq0fmVEQwxo4KSMc5R7XRJamtn+7rzHfQdJHuR WWYZ+/2MX//vlT3xLSdrQxOif9RMXPNxAUdKFVyt22kwqRBaxuq2bw52AzBj4usb 4jlj/kn7+DGJehdENRzSJA9Tf/qDlCaBCPmkIhElkaU5xUhlYM+JSWqfq03IE5SA TNvCn6b660sbQ8TwBJ3bZ1ijk6oHw1TdHkch2CNctAZGFnisbjQKBt7ZxIuhKKhW GVu9AvBY3RCaEu2/HTSqXNXHynakWJJbmCEvrAovfcBOc05LROuqbHGhh1F0OZ2F nkbhqhqwbxCIsk5YQA3/5umQc+SFjEZA0z4M/EiIE7aU7zb0xfWR3vaWrGzo7uWq pJHa+MGE/l4Hs5xXixfBL7YLijiGWyqx35HZEXi8GFAv8cKRUCWNW8Rlq+vx9ZW2 nfSavuhLwPIh028LV4dP6uyx5uZkbM7Zobe2yJWOSr0D9HraDHQ= =Wn5V -----END PGP SIGNATURE----- --nextPart2021359.0NZ9DvIWb3--