From: "Cole Helbling" <cole.e.helbling@outlook.com>
To: "Alyssa Ross" <hi@alyssa.is>, <devel@spectrum-os.org>
Subject: Re: [PATCH ucspi-vsock 7/7] Extract vsockserver-socketbinder and vsockserverd
Date: Thu, 18 Mar 2021 20:39:31 -0700 [thread overview]
Message-ID: <SJ0PR03MB55810B41A83419F337E04FB5B3689@SJ0PR03MB5581.namprd03.prod.outlook.com> (raw)
In-Reply-To: <20210319031713.23600-1-hi@alyssa.is>
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 => vsockserverd.c | 65 ++++++--------
> 5 files changed, 186 insertions(+), 130 deletions(-)
> create mode 100644 vsockserver-socketbinder.c
> copy vsockserver.c => 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 = getopt(argc, argv, "+")) != -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 = 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 = VMADDR_PORT_ANY;
> + else if (getu32(argv[optind], 0, UINT32_MAX, &port))
> + ex_usage();
> + optind++;
> +
> + // Set up the socket.
> + fd = socket(AF_VSOCK, SOCK_STREAM, 0);
> + if (fd == -1)
> + diee(EX_OSERR, "socket");
> + if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1)
> + diee(EX_OSERR, "fcntl");
> + if (vsock_bind(fd, cid, port) == -1)
> + diee(EX_OSERR, "bind");
> + if (listen(fd ,40) == -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) == -1)
> + diee(EX_OSERR, "dup2");
> + if (fd != STDIN_FILENO)
> + close(fd);
> +
> + // Finally, exec into `prog'.
> + execvp(argv[optind], &argv[optind]);
> + diee(EX_OSERR, "execvp");
> +}
Cole
next prev parent reply other threads:[~2021-03-19 3:48 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-19 3:23 Broken threading fix Alyssa Ross
2021-03-19 2:56 ` [PATCH ucspi-vsock 1/7] vsock: get cid and port instead of just cid Alyssa Ross
2021-03-19 2:53 ` [PATCH ucspi-vsock 0/7] Extract vsockserver-socketbinder and vsockserverd Alyssa Ross
2021-03-19 3:19 ` Alyssa Ross
2021-03-19 2:56 ` [PATCH ucspi-vsock 2/7] vsock: check socket family before reading sockaddr Alyssa Ross
2021-03-19 2:56 ` [PATCH ucspi-vsock 3/7] vsockserver: switch to a non-blocking socket Alyssa Ross
2021-03-19 2:56 ` [PATCH ucspi-vsock 4/7] configure: create, to generate config.h Alyssa Ross
2021-03-19 2:56 ` [PATCH ucspi-vsock 5/7] log: add die function Alyssa Ross
2021-03-19 2:56 ` [PATCH ucspi-vsock 6/7] exec: add execzp() Alyssa Ross
2021-03-19 3:17 ` [PATCH ucspi-vsock 7/7] Extract vsockserver-socketbinder and vsockserverd Alyssa Ross
2021-03-19 3:39 ` Cole Helbling [this message]
2021-03-20 20:24 ` Alyssa Ross
2021-03-21 2:52 ` Cole Helbling
2021-03-21 14:33 ` Alyssa Ross
2021-03-21 14:38 ` Alyssa Ross
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=SJ0PR03MB55810B41A83419F337E04FB5B3689@SJ0PR03MB5581.namprd03.prod.outlook.com \
--to=cole.e.helbling@outlook.com \
--cc=devel@spectrum-os.org \
--cc=hi@alyssa.is \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://spectrum-os.org/git/crosvm
https://spectrum-os.org/git/doc
https://spectrum-os.org/git/mktuntap
https://spectrum-os.org/git/nixpkgs
https://spectrum-os.org/git/spectrum
https://spectrum-os.org/git/ucspi-vsock
https://spectrum-os.org/git/www
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).