Re: [PATCH] Use a shell command as a socket for gdbserver

Mike Frysinger
2015-05-04T07:44:40Z

[-- Attachment #1: Type: text/plain, Size: 963 bytes --]

On 03 May 2015 00:39, Gabriel Corona wrote:
> +static int open_shell_command(char* command)

const, and the * should be next to "command", not "char"

> + res = socketpair(AF_LOCAL, SOCK_STREAM, 0, sockets);

space before the "(" -- this comes up a lot in your patch

> + else if (child == 0)
> + {
> + if (close (sockets[0]) < 0)
> + exit (1);
> + if (dup2 (sockets[1], 0) < 0 || dup2 (sockets[1], 1) < 0)
> + exit (1);

why not use error() instead of exit(1) ?

shouldn't you close sockets[1] after the dup2 ?

> + res = fork ();
> + if (res < 0)
> + exit (1);
> + if (res != 0)
> + exit (0);

the double fork could use a comment

> + {
> + signal (SIGPIPE, SIG_IGN);
> + while ((pid = waitpid (child, NULL, 0)) < 0 && errno == EINTR);
> + if (pid < 0)
> + error ("Could not wait for child.");
> + close (sockets[1]);
> + return sockets[0];

shouldn't this close sockets[1] before anything else ?
-mike

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]