From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51512) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VEUIP-0008OI-DQ for qemu-devel@nongnu.org; Tue, 27 Aug 2013 21:11:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VEUIK-0006Yf-GB for qemu-devel@nongnu.org; Tue, 27 Aug 2013 21:11:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:17540) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VEUIK-0006Yb-8s for qemu-devel@nongnu.org; Tue, 27 Aug 2013 21:11:36 -0400 Message-ID: <521D4E44.9090705@redhat.com> Date: Tue, 27 Aug 2013 19:11:32 -0600 From: Eric Blake MIME-Version: 1.0 References: <1377571931-9144-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1377571931-9144-2-git-send-email-xiawenc@linux.vnet.ibm.com> In-Reply-To: <1377571931-9144-2-git-send-email-xiawenc@linux.vnet.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="C5tLmOwU9dnTAGwW3jcX1mLLQBwHkWC7R" Subject: Re: [Qemu-devel] [PATCH V2 1/3] qemu-iotests: add unix socket help program List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Wenchao Xia Cc: pbonzini@redhat.com, lcapitulino@redhat.com, qemu-devel@nongnu.org, anthony@codemonkey.ws, armbru@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --C5tLmOwU9dnTAGwW3jcX1mLLQBwHkWC7R Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 08/26/2013 08:52 PM, Wenchao Xia wrote: > This program can do a sendmsg call to transfer fd with unix > socket, which is not supported in python2. >=20 > The built binary will not be deleted in clean, but it is a > existing issue in ./tests, which should be solved in another > patch. >=20 > Signed-off-by: Wenchao Xia > --- > +++ b/tests/qemu-iotests/socket_scm_helper.c > @@ -0,0 +1,119 @@ > +/* > + * SCM_RIGHT with unix socket help program for test s/SCM_RIGHT/&S/ > + > +static int send_fd(int fd, int fd_to_send, const char *data, size_t le= n) > +{ > + struct msghdr msg; > + struct iovec iov[1]; > + int ret; > + char control[CMSG_SPACE(sizeof(int))]; > + struct cmsghdr *cmsg; > + > + if (fd < 0) { > + fprintf(stderr, "Socket fd is invalid.\n"); > + return -1; > + } > + if (fd_to_send < 0) { > + fprintf(stderr, "Fd to send is invalid.\n"); > + return -1; > + } > + if (data =3D=3D NULL || len <=3D 0) { len cannot be < 0, since it is size_t (or did you mean for it to be ssize_t?) > + if (ret < 0) { > + fprintf(stderr, "Failed to send msg, reason: %s.\n", strerror(= errno)); Messages typically shouldn't end with '.'; especially when ending the message with strerror. > + } > + > + return ret; > +} > + > +/* > + * To make things simple, the caller need to specify: s/need/needs/ > + * 1. socket fd. > + * 2. fd to send. > + * 3. msg to send. > + */ > +int main(int argc, char **argv, char **envp) > +{ > + int sock, fd, ret, buflen; > + const char *buf; > +#ifdef SOCKET_SCM_DEBUG > + int i; > + for (i =3D 0; i < argc; i++) { > + fprintf(stderr, "Parameter %d: %s.\n", i, argv[i]); Another useless ending '.' (and elsewhere throughout the patch) > + } > +#endif > + > + if (argc < 4) { > + fprintf(stderr, > + "Invalid parameter, use it as:\n" > + "%s SOCKET_FD FD_TO_SEND MSG.\n", > + argv[0]); This rejects too few, but not too many, arguments. Should the condition be: if (argc !=3D 4) > + return 1; I prefer EXIT_FAILURE over the magic number 1 (multiple instances). > + } > + > + errno =3D 0; > + sock =3D strtol(argv[1], NULL, 10); Failure to pass in a second argument means you cannot distinguish "" from "0" from "0a" - all three input strings for argv[1] result in sock=3D=3D0 without you knowing any better. If you're going to use strtol(), use it correctly; if you don't care about garbage, then atoi() is just as (in)correct and with less typing. > + if (errno) { > + fprintf(stderr, "Failed in strtol for socket fd, reason: %s.\n= ", > + strerror(errno)); > + return 1; > + } > + fd =3D strtol(argv[2], NULL, 10); > + if (errno) { > + fprintf(stderr, "Failed in strtol for fd to send, reason: %s.\= n", > + strerror(errno)); > + return 1; > + } > + > + buf =3D argv[3]; > + buflen =3D strlen(buf); > + > + ret =3D send_fd(sock, fd, buf, buflen); > + if (ret < 0) { > + return 1; > + } > + return 0; I prefer EXIT_SUCCESS over the magic number 0. > +} >=20 --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --C5tLmOwU9dnTAGwW3jcX1mLLQBwHkWC7R Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.14 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJSHU5EAAoJEKeha0olJ0NqK44H/Ao8Z3fRb4cMxRCtj3oFeuFp TP83w6LTKqBMDnJtubB3RsstXM5Tws85LMjbXO61WlzQq2sQVu3DflbsjR+yVF1y 1QLxr9Wa7WcajEP0F68Cj7OofQOaRA3XhDnkrOj5c1BnYsSfKs9FUsk56xCTnj9a DquN7zn8yPfPfrpqKZ2OSZpICSLwO8IoJAhNtxK3GeX8ZcMiKjHh3EN8x6WjfI9c uqHcWtW1gJsBaOuQUus6osAnUj0u7tW7FgSgXVxR3CF5hfiCK8ciLs1UqQk+12yl Dh5s7/ogjXoI5w+EEGLl5L9VKRLxXY5OBuw7w9PL5czDIVT6QcJBDh5Wg6aJvzs= =nBVp -----END PGP SIGNATURE----- --C5tLmOwU9dnTAGwW3jcX1mLLQBwHkWC7R--