From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on atuin.qyliss.net X-Spam-Level: X-Spam-Status: No, score=-2.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_SPF_HELO,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS autolearn=no autolearn_force=no version=3.4.4 Received: by atuin.qyliss.net (Postfix, from userid 496) id 29AA18893; Fri, 19 Mar 2021 03:48:11 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by atuin.qyliss.net (Postfix) with ESMTP id B191D87FC; Fri, 19 Mar 2021 03:47:56 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 496) id D8A708812; Fri, 19 Mar 2021 03:47:53 +0000 (UTC) Received: from NAM04-CO1-obe.outbound.protection.outlook.com (mail-oln040092010085.outbound.protection.outlook.com [40.92.10.85]) by atuin.qyliss.net (Postfix) with ESMTPS id 97763880E for ; Fri, 19 Mar 2021 03:47:49 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G/V7pX1LH2/WcxfoihB+Ksplvu1Fuc7fd1zi7FTidNagVs5Dr7a3cLFErVqPXxo8cmIkgxUPMmOwBJwqHll8J4oR96bZjYwz2ekWGvxAzNHGWC62QZcALSjtXjdoAxovDhjsrWu1KE0ZZrr6q6UWh0n1J5pTCn6TYC9mEb8QnPbjyZ/3CiPpo4pk+bkxqSTvdrHjSCbHyomN2z1DM6XWXMfEFFTwPjwi7eJiPsgOy4lL6eIqcsLtV0FY+Cwzctev84gKDdFAN87TITcKzNnUIlmA1rlGqZeFPE/juZulbPxkNdBv1K/dPJJavTTF6Byaz8/SF9cmOZkur2x4xkDOCA== 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-SenderADCheck; bh=HBlwhiMpkTlWAp2I+NTNVtERxQgoiNax/bAyNaEeB98=; b=mGYYdSzFTs9AuC1BnpYnKxjsJ9sS68f4Q23NCUEwZSLygj/WZGEjR8hSZFPvRT0eIVQIE8B8OD+UaXTqyohGOZm881+XGY6fDi4RkPDDgUQ0U/AbWpVCKcoekgobgvjQuS+fiJF7CI808YRFA7x/Rrv2yFyKL0VCddCx902B+IljKwkrChAx1x1sPNE8hHMBfRG5jgfX8XpZ1xj+zr/4T19HEAGbJcRJ8kUccHMp3OQht9LjnPDiRwkw6ohgbn/06+dxceNBSX5DS4LyCw4OOp6AEbRIGpDKYQitCd8dvaZfehlbpGBg7hmGOKdykj6WAYj/QVeKb4hZ6NYUg3SaHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HBlwhiMpkTlWAp2I+NTNVtERxQgoiNax/bAyNaEeB98=; b=PC7u17ne8YJnfdq5LDXYjhJV7iLJYPYml7FEe35rosURlc7NqbC+cOWzWtFOYzRY1C4LTE9D15a2wmC4oEk++xFdIP8JlBIA47J3FZINHhoMNaq+RrI2k7dkonj1RP1cWpa9ISjYef+jABHE8iYhBrGC2MRBbQjGdLMRNdJUtIIRPrnLLspNVi4hfjGRP2qvZtx+bSNJAjkdcgwvoNHDpREcvDPtTER7MY69MAFYTrGhHWMi7NiyxyndSGwWR7RTKSXdXBVRSVWkQxlIzMALuHwDsB02Wxc3morH8ktH0IqBjax6w5yQjFIqLrFj8VOnmDVo84KHeW7D9rsBznzA4Q== Received: from SN1NAM04FT023.eop-NAM04.prod.protection.outlook.com (10.152.88.52) by SN1NAM04HT169.eop-NAM04.prod.protection.outlook.com (10.152.88.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.32; Fri, 19 Mar 2021 03:47:46 +0000 Received: from SJ0PR03MB5581.namprd03.prod.outlook.com (2a01:111:e400:7e4c::40) by SN1NAM04FT023.mail.protection.outlook.com (2a01:111:e400:7e4c::108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18 via Frontend Transport; Fri, 19 Mar 2021 03:47:46 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:8DED2B5B275727FB81CE381963882BB998759E27CBE11153FD273AA3AF4CAE67;UpperCasedChecksum:CD320A0BB3169EC8477D9B2CE7CB2E3E54A7A83AFAF45A7C77AE86726192656D;SizeAsReceived:8473;Count:44 Received: from SJ0PR03MB5581.namprd03.prod.outlook.com ([fe80::ed0b:679f:905f:4c94]) by SJ0PR03MB5581.namprd03.prod.outlook.com ([fe80::ed0b:679f:905f:4c94%5]) with mapi id 15.20.3933.032; Fri, 19 Mar 2021 03:47:46 +0000 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Subject: Re: [PATCH ucspi-vsock 7/7] Extract vsockserver-socketbinder and vsockserverd From: "Cole Helbling" To: "Alyssa Ross" , Date: Thu, 18 Mar 2021 20:39:31 -0700 Message-ID: In-Reply-To: <20210319031713.23600-1-hi@alyssa.is> X-TMN: [rBH8wY/HMInwHt9iOUGHfWp1YkUlQ1Y2] X-ClientProxiedBy: SJ0PR13CA0045.namprd13.prod.outlook.com (2603:10b6:a03:2c2::20) To SJ0PR03MB5581.namprd03.prod.outlook.com (2603:10b6:a03:27b::20) X-Microsoft-Original-Message-ID: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost (73.48.197.220) by SJ0PR13CA0045.namprd13.prod.outlook.com (2603:10b6:a03:2c2::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3977.10 via Frontend Transport; Fri, 19 Mar 2021 03:47:45 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 44 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 02c9aa54-740b-456e-83b5-08d8ea89c1f4 X-MS-TrafficTypeDiagnostic: SN1NAM04HT169: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: r9aCDmrlz8w0YpMFtHe6odDPKOeUrAgSX5dpTPWMDrWUlonFlw5Nztais+1Hsh3Dk6oegK7KwISu7Zb3ML8tzug+bBjnFMgHIipTARaTOHNj4dDuCCbrsgYB6FUzHJqR6xGgegcL5ZtahnRbhx4CZK5geJf/OUMGzrzaKTHNwo2ChpnCiB/+fvUCJ+tWHRSf8oKrBx6KiTtTMwMBCBQiHKYUeS8Zc/c9TNgrry1otvoLfdyGjQ3Iu1rHzcs53iXqzBrxWGjJ03oRGucRjXZL01C0PYWm8d5jAquG8g4u5d6a3R662wO3icKO8f9S0Qm2NzVp7efv5SBUZuh7VfcjbErDYf7zQkgIBWfJN2Px2aXYJO8maRgQZIa4UbYMI+r9IIXYsNiJazZCa6eCdNqVH8/UzHKu7ayykQeDV0wjNYg= X-MS-Exchange-AntiSpam-MessageData: J04967E2EcKzyywKcKvKAFgbo5EG9/Efexu9Id+lMtcF2qw+qV2Lui1GmuKtxCP13uIJw4pCJmpjKShwgu0dLBEuiepYj4UAXhlp6HvVpw1SrNkaV+4CCrjQJzJOAnO0LaRMrQAk3ygc1FaD9y47/g== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 02c9aa54-740b-456e-83b5-08d8ea89c1f4 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Mar 2021 03:47:46.0800 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: SN1NAM04FT023.eop-NAM04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1NAM04HT169 Message-ID-Hash: QOOAR3LO56E6UHXXLECT4RR7QERYU5DQ X-Message-ID-Hash: QOOAR3LO56E6UHXXLECT4RR7QERYU5DQ X-MailFrom: cole.e.helbling@outlook.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.3.1 Precedence: list List-Id: Patches and low-level development discussion Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: On Thu Mar 18, 2021 at 8:17 PM PDT, Alyssa Ross wrote: > vsockserver-socketbinder creates and listens on a socket, and > vsockserverd accepts connections and sets up file descriptors. > > vsockserver previously did both of these things in one big program, > but now it just sets up a command line to run vsockserver-socketbinder > followed by vsockserverd. Having two seperate programs allows one > program to be used in situations where the other is not > suitable (e.g. using vsockserver-socketbinder to create a socket in > situations where accept behaviour more complex than vsockserverd can > provide is required). > > This design is taken from s6[1], which uses the same design for its > s6-ipcserver, s6-ipcserver-socketbinder, and s6-ipcserverd programs. > > [1]: https://skarnet.org/software/s6/ > --- > > Because vsockserver.c is completely rewritten in this patch, the diff > generated by git was a bit confusing, so the diff here has been > lovingly hand-edited to group the hunks together more and make it easy > to see the new code all at once. Being able to do this is one of the > nice things about email patches. ;) > > The new implementations are much more thoroughly commented. Think > that's my new style. :) > > .gitignore | 2 + > Makefile.in | 14 ++- > vsockserver-socketbinder.c | 86 ++++++++++++++++++ > vsockserver.c | 149 ++++++++++++++------------------ > vsockserver.c =3D> vsockserverd.c | 65 ++++++-------- > 5 files changed, 186 insertions(+), 130 deletions(-) > create mode 100644 vsockserver-socketbinder.c > copy vsockserver.c =3D> vsockserverd.c (64%) [snip] > diff --git a/vsockserver-socketbinder.c b/vsockserver-socketbinder.c > new file mode 100644 > index 0000000..598c01c > --- /dev/null > +++ b/vsockserver-socketbinder.c > @@ -0,0 +1,86 @@ [snip] > +int main(int argc, char *argv[]) > +{ > + int opt, fd; > + uint32_t cid, port; > + > + // A skeleton of an option parser to reject any options that > + // are given, so we can add options in the future without > + // worrying about breaking backwards compatibility because > + // they were previously interpreted as a first argument. > + while ((opt =3D getopt(argc, argv, "+")) !=3D -1) { > + switch (opt) { > + default: > + ex_usage(); > + } > + } > + > + // Check there are enough positional arguments (two for the > + // address and at least one to exec into). > + if (optind > argc - 3) > + ex_usage(); > + > + // Parse the `cid' argument. > + if (!strcmp(argv[optind], "-1")) > + cid =3D VMADDR_CID_ANY; > + else if (getu32(argv[optind], 0, UINT32_MAX, &cid)) > + ex_usage(); > + optind++; > + > + // Parse the `port' argument. > + if (!strcmp(argv[optind], "-1")) > + port =3D VMADDR_PORT_ANY; > + else if (getu32(argv[optind], 0, UINT32_MAX, &port)) > + ex_usage(); > + optind++; > + > + // Set up the socket. > + fd =3D socket(AF_VSOCK, SOCK_STREAM, 0); > + if (fd =3D=3D -1) > + diee(EX_OSERR, "socket"); > + if (fcntl(fd, F_SETFL, O_NONBLOCK) =3D=3D -1) > + diee(EX_OSERR, "fcntl"); > + if (vsock_bind(fd, cid, port) =3D=3D -1) > + diee(EX_OSERR, "bind"); > + if (listen(fd ,40) =3D=3D -1) Minor formatting nit (comma, then space); but also, what is `40` representative of? Should this be `#define`d, or otherwise assigned to some descriptive name? > + diee(EX_OSERR, "listen"); > + > + // Place the socket at stdout. > + if (dup2(fd, STDIN_FILENO) =3D=3D -1) > + diee(EX_OSERR, "dup2"); > + if (fd !=3D STDIN_FILENO) > + close(fd); > + > + // Finally, exec into `prog'. > + execvp(argv[optind], &argv[optind]); > + diee(EX_OSERR, "execvp"); > +} Cole