From: Stefan Hajnoczi <stefanha@gmail.com>
To: Corey Bryant <coreyb@linux.vnet.ibm.com>
Cc: rmarwah@linux.vnet.ibm.com, aliguori@us.ibm.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v3 1/4] Add basic version of bridge helper
Date: Tue, 1 Nov 2011 08:15:14 +0000 [thread overview]
Message-ID: <20111101081514.GA27890@stefanha-thinkpad.localdomain> (raw)
In-Reply-To: <1320086191-23641-2-git-send-email-coreyb@linux.vnet.ibm.com>
On Mon, Oct 31, 2011 at 02:36:28PM -0400, Corey Bryant wrote:
A couple of nitpicks regarding error handling:
> +static int has_vnet_hdr(int fd)
> +{
> + unsigned int features = 0;
> + struct ifreq ifreq;
> +
> + if (ioctl(fd, TUNGETFEATURES, &features) == -1) {
> + return -errno;
> + }
> +
> + if (!(features & IFF_VNET_HDR)) {
> + return -ENOTSUP;
> + }
> +
> + if (ioctl(fd, TUNGETIFF, &ifreq) != -1 || errno != EBADFD) {
> + return -ENOTSUP;
> + }
> +
> + return 1;
> +}
This function is strange, it looks like a boolean function but actually
only returns 1 or -errno. It is used incorrectly in main(). I suggest
changing the return value to bool and returning false on error.
> + /* open a socket to use to control the network interfaces */
> + ctlfd = socket(AF_INET, SOCK_STREAM, 0);
> + if (ctlfd == -1) {
> + fprintf(stderr, "failed to open control socket\n");
> + ret = -errno;
It's better to stash away errno before invoking other library functions.
man errno(3) says:
"a function that succeeds is allowed to change errno"
This means fprintf(3) could clobber errno.
I suggest simply printing out errno with the error message and returning
exit code 1 (EXIT_FAILURE). The same applies for the other error exit
cases in main().
> +cleanup:
> +
> + close(fd);
> +
> + close(ctlfd);
ctlfd is an uninitialized variable if opening fd fails. We also never
close unixfd.
I'd remove this cleanup code and just return without closing any file
descriptors - let the kernel do it.
Stefan
next prev parent reply other threads:[~2011-11-01 9:05 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-31 18:36 [Qemu-devel] [PATCH v3 0/4] -net bridge: rootless bridge support for qemu Corey Bryant
2011-10-31 18:36 ` [Qemu-devel] [PATCH v3 1/4] Add basic version of bridge helper Corey Bryant
2011-11-01 8:15 ` Stefan Hajnoczi [this message]
2011-11-01 13:52 ` Corey Bryant
2011-10-31 18:36 ` [Qemu-devel] [PATCH v3 2/4] Add access control support to qemu " Corey Bryant
2011-10-31 18:36 ` [Qemu-devel] [PATCH v3 3/4] Add cap reduction support to enable use as SUID Corey Bryant
2011-10-31 18:36 ` [Qemu-devel] [PATCH v3 4/4] Add support for net bridge Corey Bryant
2011-11-03 3:10 ` Mark Wu
2011-11-03 20:04 ` Corey Bryant
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=20111101081514.GA27890@stefanha-thinkpad.localdomain \
--to=stefanha@gmail.com \
--cc=aliguori@us.ibm.com \
--cc=coreyb@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=rmarwah@linux.vnet.ibm.com \
/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;
as well as URLs for NNTP newsgroup(s).