On Fri, Oct 23, 2009 at 02:05:35PM +0100, Daniel P. Berrange wrote: > * daemon/libvirtd.c: Change qemudNetworkInit() so that it doesn't try > to free its argument, leaving the caller todo cleanup as is normal > practice. Add missing policykit cleanup to qemudCleanup, and remove > server watch if set. Remove duplicated call to listen() on TCP sockets > --- > daemon/libvirtd.c | 39 ++++++++++++++------------------------- > 1 files changed, 14 insertions(+), 25 deletions(-) > > diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c > index fa473ce..db151cd 100644 > --- a/daemon/libvirtd.c > +++ b/daemon/libvirtd.c > @@ -593,13 +593,7 @@ remoteMakeSockets (int *fds, int max_fds, int *nfds_r, const char *node, const c > return -1; > } > close (fds[*nfds_r]); > - } > - else { > - if (listen (fds[*nfds_r], SOMAXCONN) == -1) { > - VIR_ERROR(_("listen: %s"), > - virStrerror (errno, ebuf, sizeof ebuf)); > - return -1; > - } > + } else { > ++*nfds_r; > } > runp = runp->ai_next; > @@ -867,8 +861,7 @@ static struct qemud_server *qemudInitialize(int sigread) { > return server; > } > > -static struct qemud_server *qemudNetworkInit(struct qemud_server *server) { > - struct qemud_socket *sock; > +static int qemudNetworkInit(struct qemud_server *server) { > char sockname[PATH_MAX]; > char roSockname[PATH_MAX]; > #if HAVE_SASL > @@ -935,6 +928,7 @@ static struct qemud_server *qemudNetworkInit(struct qemud_server *server) { > #ifdef HAVE_AVAHI > if (server->privileged && mdns_adv) { > struct libvirtd_mdns_group *group; > + struct qemud_socket *sock; > int port = 0; > > server->mdns = libvirtd_mdns_new(); > @@ -976,25 +970,13 @@ static struct qemud_server *qemudNetworkInit(struct qemud_server *server) { > } > #endif > > - return server; > + return 0; > > cleanup: > - if (server) { > - sock = server->sockets; > - while (sock) { > - close(sock->fd); > - sock = sock->next; > - } > - > -#if HAVE_POLKIT0 > - if (server->sysbus) > - dbus_connection_unref(server->sysbus); > -#endif > - free(server); > - } > - return NULL; > + return -1; > } > > + > static gnutls_session_t > remoteInitializeTLSSession (void) > { > @@ -2305,6 +2287,8 @@ static void qemudCleanup(struct qemud_server *server) { > sock = server->sockets; > while (sock) { > struct qemud_socket *next = sock->next; > + if (sock->watch) > + virEventRemoveHandleImpl(sock->watch); > close(sock->fd); > free(sock); > sock = next; > @@ -2322,6 +2306,11 @@ static void qemudCleanup(struct qemud_server *server) { > } > #endif > > +#if HAVE_POLKIT0 > + if (server->sysbus) > + dbus_connection_unref(server->sysbus); > +#endif > + > virStateCleanup(); > > if (virCondDestroy(&server->job) < 0) { > @@ -3015,7 +3004,7 @@ int main(int argc, char **argv) { > goto error2; > } > > - if (!(server = qemudNetworkInit(server))) { > + if (qemudNetworkInit(server) < 0) { > ret = 2; > goto error2; > } It's rather hard to follow without seeing the source next to it, but that's a nice cleanup, ACK ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@xxxxxxxxxxxx | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list