From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:42788) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLAHb-0001si-MF for qemu-devel@nongnu.org; Tue, 01 Nov 2011 05:05:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RLAHS-0001yk-CK for qemu-devel@nongnu.org; Tue, 01 Nov 2011 05:05:23 -0400 Received: from mail-ey0-f173.google.com ([209.85.215.173]:58383) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLAHR-0001ya-IT for qemu-devel@nongnu.org; Tue, 01 Nov 2011 05:05:14 -0400 Received: by eyh6 with SMTP id 6so6759990eyh.4 for ; Tue, 01 Nov 2011 02:05:12 -0700 (PDT) Date: Tue, 1 Nov 2011 08:15:14 +0000 From: Stefan Hajnoczi Message-ID: <20111101081514.GA27890@stefanha-thinkpad.localdomain> References: <1320086191-23641-1-git-send-email-coreyb@linux.vnet.ibm.com> <1320086191-23641-2-git-send-email-coreyb@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1320086191-23641-2-git-send-email-coreyb@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [PATCH v3 1/4] Add basic version of bridge helper List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Corey Bryant Cc: rmarwah@linux.vnet.ibm.com, aliguori@us.ibm.com, qemu-devel@nongnu.org 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