From 72dc6d60abebf84ccad4c96fc266c2b7cdb3dbe0 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Tue, 12 May 2009 15:43:07 +0000 Subject: [PATCH] Remove use of qemudSetNonBlock/SetCloseExec in favour of shared impl --- ChangeLog | 6 ++++++ qemud/event.c | 11 ++++++----- qemud/qemud.c | 46 ++++++++++------------------------------------ qemud/qemud.h | 3 --- 4 files changed, 22 insertions(+), 44 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5be64adbf8..077a9487a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Tue May 12 16:38:22 BST 2009 Daniel P. Berrange + + * qemud/qemud.c, qemud/qemud.h, qemud/event.c: Remove use + of qemudSetNonBock/SetCloseExec in favour of virSetNonBlock + and virSetCloseExec. + Tue May 12 16:38:22 BST 2009 Daniel P. Berrange Allow for quieter build with 'make -s' diff --git a/qemud/event.c b/qemud/event.c index 0887008b4d..65f548e44e 100644 --- a/qemud/event.c +++ b/qemud/event.c @@ -30,7 +30,8 @@ #include #include -#include "qemud.h" +#include "threads.h" +#include "logging.h" #include "event.h" #include "memory.h" #include "util.h" @@ -597,10 +598,10 @@ int virEventInit(void) return -1; if (pipe(eventLoop.wakeupfd) < 0 || - qemudSetNonBlock(eventLoop.wakeupfd[0]) < 0 || - qemudSetNonBlock(eventLoop.wakeupfd[1]) < 0 || - qemudSetCloseExec(eventLoop.wakeupfd[0]) < 0 || - qemudSetCloseExec(eventLoop.wakeupfd[1]) < 0) + virSetNonBlock(eventLoop.wakeupfd[0]) < 0 || + virSetNonBlock(eventLoop.wakeupfd[1]) < 0 || + virSetCloseExec(eventLoop.wakeupfd[0]) < 0 || + virSetCloseExec(eventLoop.wakeupfd[1]) < 0) return -1; if (virEventAddHandleImpl(eventLoop.wakeupfd[0], diff --git a/qemud/qemud.c b/qemud/qemud.c index 829a4bc5f2..1847407911 100644 --- a/qemud/qemud.c +++ b/qemud/qemud.c @@ -371,32 +371,6 @@ qemudDispatchSignalEvent(int watch ATTRIBUTE_UNUSED, virMutexUnlock(&server->lock); } -int qemudSetCloseExec(int fd) { - int flags; - if ((flags = fcntl(fd, F_GETFD)) < 0) - goto error; - flags |= FD_CLOEXEC; - if ((fcntl(fd, F_SETFD, flags)) < 0) - goto error; - return 0; - error: - VIR_ERROR0(_("Failed to set close-on-exec file descriptor flag")); - return -1; -} - - -int qemudSetNonBlock(int fd) { - int flags; - if ((flags = fcntl(fd, F_GETFL)) < 0) - goto error; - flags |= O_NONBLOCK; - if ((fcntl(fd, F_SETFL, flags)) < 0) - goto error; - return 0; - error: - VIR_ERROR0(_("Failed to set non-blocking file descriptor flag")); - return -1; -} static int qemudGoDaemon(void) { int pid = fork(); @@ -525,8 +499,8 @@ static int qemudListenUnix(struct qemud_server *server, goto cleanup; } - if (qemudSetCloseExec(sock->fd) < 0 || - qemudSetNonBlock(sock->fd) < 0) + if (virSetCloseExec(sock->fd) < 0 || + virSetNonBlock(sock->fd) < 0) goto cleanup; memset(&addr, 0, sizeof(addr)); @@ -687,8 +661,8 @@ remoteListenTCP (struct qemud_server *server, else sock->port = -1; - if (qemudSetCloseExec(sock->fd) < 0 || - qemudSetNonBlock(sock->fd) < 0) + if (virSetCloseExec(sock->fd) < 0 || + virSetNonBlock(sock->fd) < 0) goto cleanup; if (listen (sock->fd, 30) < 0) { @@ -1273,8 +1247,8 @@ static int qemudDispatchServer(struct qemud_server *server, struct qemud_socket setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, (void *)&no_slow_start, sizeof no_slow_start); - if (qemudSetCloseExec(fd) < 0 || - qemudSetNonBlock(fd) < 0) { + if (virSetCloseExec(fd) < 0 || + virSetNonBlock(fd) < 0) { close(fd); return -1; } @@ -2872,10 +2846,10 @@ int main(int argc, char **argv) { goto error1; if (pipe(sigpipe) < 0 || - qemudSetNonBlock(sigpipe[0]) < 0 || - qemudSetNonBlock(sigpipe[1]) < 0 || - qemudSetCloseExec(sigpipe[0]) < 0 || - qemudSetCloseExec(sigpipe[1]) < 0) { + virSetNonBlock(sigpipe[0]) < 0 || + virSetNonBlock(sigpipe[1]) < 0 || + virSetCloseExec(sigpipe[0]) < 0 || + virSetCloseExec(sigpipe[1]) < 0) { char ebuf[1024]; VIR_ERROR(_("Failed to create pipe: %s"), virStrerror(errno, ebuf, sizeof ebuf)); diff --git a/qemud/qemud.h b/qemud/qemud.h index 4ddbc41576..e3bae46248 100644 --- a/qemud/qemud.h +++ b/qemud/qemud.h @@ -198,9 +198,6 @@ void qemudLog(int priority, const char *fmt, ...) ATTRIBUTE_FORMAT(printf,2,3); -int qemudSetCloseExec(int fd); -int qemudSetNonBlock(int fd); - int remoteDispatchClientRequest (struct qemud_server *server, struct qemud_client *client,