From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27219 invoked by alias); 5 May 2015 02:58:44 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 27175 invoked by uid 89); 5 May 2015 02:58:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: smtp.gentoo.org Received: from smtp.gentoo.org (HELO smtp.gentoo.org) (140.211.166.183) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 05 May 2015 02:58:37 +0000 Received: from vapier (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with SMTP id 50AC1340BF5; Tue, 5 May 2015 02:58:35 +0000 (UTC) Date: Tue, 05 May 2015 02:58:00 -0000 From: Mike Frysinger To: Gabriel Corona Cc: gdb-patches@sourceware.org Subject: Re: [PATCH v2 1/2] Use a shell command as a socket for gdbserver Message-ID: <20150505025834.GM30924@vapier> Mail-Followup-To: Gabriel Corona , gdb-patches@sourceware.org References: <1430776463-23214-1-git-send-email-gabriel.corona@enst-bretagne.fr> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="pFpMklMRdxwSC3Yi" Content-Disposition: inline In-Reply-To: <1430776463-23214-1-git-send-email-gabriel.corona@enst-bretagne.fr> X-IsSubscribed: yes X-SW-Source: 2015-05/txt/msg00067.txt.bz2 --pFpMklMRdxwSC3Yi Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 1666 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 =3D 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 wo= n't=20 create a new one. i think before you close, you need to compare it to=20 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 st= yle=20 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 =3D waitpid (child, &status, 0)) < 0 && errno =3D=3D E= INTR); > + 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 --pFpMklMRdxwSC3Yi Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-length: 819 -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJVSDHaAAoJEEFjO5/oN/WBkh0QAK2VaLXUhbYZFBK2u2wZH/tQ blOZjvG/uFJzhQLZMnOGcMTxJzA5yhFozZcze69vy0LmtbZPeSh8FZ4rzCkfDoC6 wXmdcfMfXYFYADLPJuxoXCzBCjy/4J2+m8N59LV9KBpJJSAWOY8hdy0FmvlmVLTN 8GBdX44t7suo14LmmJ7BMKpFUYeiL8EJEZlIzjPur0d8xxhzXuN19mJ1AsbSxiRW orCeE07JN5PPVTg/lpswcAni0fNInRhh001Q1MvzODUzssn3ihST+5npWvvqoD94 +jDcsq6pfKCYEB5KXjubaMP8bTPDsSd5M4P9vjAZAT/k0F6+FvHerbSJsHO8oKje mLup5sPZUwItXvdLIzOGUn/t3vJFTXTenlnYyuznk9Np7x4YmVrOjvVuNk0AeSXd hBQvWYY7Pzk5FKnz9RuQ90zmiO9lf75cvBfnzZ19tpptMMHS1nV/VmVrA1R3WuSf tdflYPJ1mttftLuErF74ewMtfoHaIh/4Uj1wteDjXm8vlvOJ2sex681RQ5LZTssE XKK4FczABHCfaKKQ9Xk1RPzGlWvVTYbQLDcwdNrCi8dKdU9o4y466YdfFLWtju4T EhhmR24r2eZK/SMGfzbsEkqFY3hOYItNaB7Q2r99Rje4g2He4tLloVOap0L4i+9w Y13kN6aGDIxJFkjLnPa5 =yRZV -----END PGP SIGNATURE----- --pFpMklMRdxwSC3Yi--