From: Corey Bryant <coreyb@linux.vnet.ibm.com>
To: Stefan Hajnoczi <stefanha@gmail.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, 01 Nov 2011 09:52:57 -0400 [thread overview]
Message-ID: <4EAFF9B9.90401@linux.vnet.ibm.com> (raw)
In-Reply-To: <20111101081514.GA27890@stefanha-thinkpad.localdomain>
On 11/01/2011 04:15 AM, Stefan Hajnoczi wrote:
> 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.
>
Ah, good catch, this was a bug. And I agree that bool would work
better. I'll fix this.
>> + /* 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().
>
I agree. I'll fix this.
>> +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.
Ok, I'll do this. But I think I'll re-introduce the cleanup goto in
patch 2/4 to free the simple queue memory.
--
Regards,
Corey
>
> Stefan
>
next prev parent reply other threads:[~2011-11-01 14:00 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
2011-11-01 13:52 ` Corey Bryant [this message]
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=4EAFF9B9.90401@linux.vnet.ibm.com \
--to=coreyb@linux.vnet.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=rmarwah@linux.vnet.ibm.com \
--cc=stefanha@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.