From: Mike Frysinger <vapier@gentoo.org>
To: Gabriel Corona <gabriel.corona@enst-bretagne.fr>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH v2 1/2] Use a shell command as a socket for gdbserver
Date: Tue, 05 May 2015 02:58:00 -0000 [thread overview]
Message-ID: <20150505025834.GM30924@vapier> (raw)
In-Reply-To: <1430776463-23214-1-git-send-email-gabriel.corona@enst-bretagne.fr>
[-- Attachment #1: Type: text/plain, Size: 1704 bytes --]
On 04 May 2015 23:54, Gabriel Corona wrote:
> +static int
> +open_shell_command (char *command)
const ?
> +{
> + int sockets[2];
> + pid_t child, grandchild, res;
> + int status;
> +
> + if (socketpair (AF_LOCAL, SOCK_STREAM, 0, sockets) < 0)
> + perror_with_name ("Can't get socketpair");
> + child = fork ();
prefer a blank line above the fork assignment
> + if (dup2 (sockets[1], 0) < 0 || dup2 (sockets[1], 1) < 0)
> + perror_with_name ("Can't dup socket to stdio");
use STDIN_FILENO & STDOUT_FILENO instead of 0 & 1
> + if (close (sockets[1]) < 0)
> + perror_with_name ("Can't close original socket");
dup2 has an edge case where if the fd is the same as an existing one, it won't
create a new one. i think before you close, you need to compare it to
STDIN_FILENO & STDOUT_FILENO and only close it if it doesn't match.
> + /* Double fork in order to inherit the grandchild. The process
> + is expected to exit when the other end of the socketpair is
> + closed.
> + */
prefer a blank line above this comment to space the code out. also, GNU style
says:
- use two spaces after periods
- cuddle the trailing */ rather than putting it on a new line by itself
> + else
> + {
> + close (sockets[1]);
check return value ?
> + signal (SIGPIPE, SIG_IGN);
> + while ((res = waitpid (child, &status, 0)) < 0 && errno == EINTR);
> + if (res < 0)
> + perror_with_name ("Can't wait child process");
phrasing is awkward ... maybe insert "on" or "for the" in there ?
> + }
> + return -1;
> +}
i think GNU style says you should have a blank line above this last return
-mike
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
prev parent reply other threads:[~2015-05-05 2:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-04 21:54 Gabriel Corona
2015-05-04 21:54 ` [PATCH v2 2/2] Make gdbserver connect to SOCK_STREAM sockets Gabriel Corona
2015-05-05 3:01 ` Mike Frysinger
2015-05-05 2:58 ` Mike Frysinger [this message]
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=20150505025834.GM30924@vapier \
--to=vapier@gentoo.org \
--cc=gabriel.corona@enst-bretagne.fr \
--cc=gdb-patches@sourceware.org \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox