From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:49798) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TL7NB-0001UZ-01 for qemu-devel@nongnu.org; Mon, 08 Oct 2012 03:03:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TL7N9-0007Zf-9H for qemu-devel@nongnu.org; Mon, 08 Oct 2012 03:03:28 -0400 Received: from mail-bk0-f45.google.com ([209.85.214.45]:48880) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TL7N9-0007ZS-2M for qemu-devel@nongnu.org; Mon, 08 Oct 2012 03:03:27 -0400 Received: by mail-bk0-f45.google.com with SMTP id jf3so1542571bkc.4 for ; Mon, 08 Oct 2012 00:03:24 -0700 (PDT) Date: Mon, 8 Oct 2012 09:03:21 +0200 From: Stefan Hajnoczi Message-ID: <20121008070321.GA16332@stefanha-thinkpad.redhat.com> References: <1348577763-12920-1-git-send-email-pbonzini@redhat.com> <1348577763-12920-3-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1348577763-12920-3-git-send-email-pbonzini@redhat.com> Subject: Re: [Qemu-devel] [PATCH 02/17] event_notifier: enable it to use pipes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org On Tue, Sep 25, 2012 at 02:55:48PM +0200, Paolo Bonzini wrote: > int event_notifier_init(EventNotifier *e, int active) > { > + int fds[2]; > + int ret; > + > #ifdef CONFIG_EVENTFD > - int fd = eventfd(!!active, EFD_NONBLOCK | EFD_CLOEXEC); > - if (fd < 0) > - return -errno; > - e->fd = fd; > - return 0; > + ret = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); > #else > - return -ENOSYS; > + ret = -1; > + errno = ENOSYS; > #endif > + if (ret >= 0) { > + e->rfd = e->wfd = ret; > + } else { > + if (errno != ENOSYS) { > + return -errno; > + } > + if (qemu_pipe(fds) < 0) { > + return -errno; > + } > + ret = fcntl_setfl(fds[0], O_NONBLOCK); > + if (ret < 0) { ret = -errno; > + goto fail; > + } > + ret = fcntl_setfl(fds[1], O_NONBLOCK); > + if (ret < 0) { ret = -errno; > + goto fail; > + } > + e->rfd = fds[0]; > + e->wfd = fds[1]; > + } > + if (active) { > + event_notifier_set(e); > + } > + return 0; > + > +fail: > + close(fds[0]); > + close(fds[1]); > + return ret; > } > > void event_notifier_cleanup(EventNotifier *e) > { > - close(e->fd); > + if (e->rfd != e->wfd) { > + close(e->rfd); > + } > + close(e->wfd); > } > > int event_notifier_get_fd(EventNotifier *e) > { > - return e->fd; > + return e->rfd; > } > > int event_notifier_set_handler(EventNotifier *e, > EventNotifierHandler *handler) > { > - return qemu_set_fd_handler(e->fd, (IOHandler *)handler, NULL, e); > + return qemu_set_fd_handler(e->rfd, (IOHandler *)handler, NULL, e); > } > > int event_notifier_set(EventNotifier *e) > { > - uint64_t value = 1; > - int r = write(e->fd, &value, sizeof(value)); > - return r == sizeof(value); > + static const uint64_t value = 1; > + ssize_t ret; > + > + do { > + ret = write(e->wfd, &value, sizeof(value)); > + } while (ret < 0 && errno == EINTR); > + > + /* EAGAIN is fine, a read must be pending. */ > + if (ret < 0 && errno != EAGAIN) { > + return -1; If we're changing the return value representation, then we might as well: return -errno; But no caller actually checks the return value.