This patch introduces a internal RPC API "virNetServerClose", which
is standalone with "virNetServerFree". it closes all the socket fds,
and unlinks the unix socket paths, regardless of whether the socket
is still referenced or not.
This is to address regression bug:
https://bugzilla.redhat.com/show_bug.cgi?id=725702
---
daemon/libvirtd.c | 1 +
src/rpc/virnetserver.c | 16 ++++++++++++++++
src/rpc/virnetserver.h | 1 +
src/rpc/virnetserverservice.c | 12 ++++++++++++
src/rpc/virnetserverservice.h | 2 ++
src/rpc/virnetsocket.c | 22 ++++++++++++++++++++++
src/rpc/virnetsocket.h | 1 +
7 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index 9e044e2..53f1002 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -1558,6 +1558,7 @@ int main(int argc, char **argv) {
cleanup:
virNetServerProgramFree(remoteProgram);
virNetServerProgramFree(qemuProgram);
+ virNetServerClose(srv);
virNetServerFree(srv);
if (statuswrite != -1) {
if (ret != 0) {
diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c
index 5e4826b..1a49dbb 100644
--- a/src/rpc/virnetserver.c
+++ b/src/rpc/virnetserver.c
@@ -798,3 +798,19 @@ void virNetServerFree(virNetServerPtr srv)
virMutexDestroy(&srv->lock);
VIR_FREE(srv);
}
+
+void virNetServerClose(virNetServerPtr srv)
+{
+ int i;
+
+ if (!srv)
+ return;
+
+ virNetServerLock(srv);
+
+ for (i = 0; i < srv->nservices; i++) {
+ virNetServerServiceClose(srv->services[i]);
+ }
+
+ virNetServerUnlock(srv);
+}
diff --git a/src/rpc/virnetserver.h b/src/rpc/virnetserver.h
index 810d8a3..324cfb7 100644
--- a/src/rpc/virnetserver.h
+++ b/src/rpc/virnetserver.h
@@ -85,5 +85,6 @@ void virNetServerQuit(virNetServerPtr srv);
void virNetServerFree(virNetServerPtr srv);
+void virNetServerClose(virNetServerPtr srv);
#endif
diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c
index d5648dc..8c9ed1e 100644
--- a/src/rpc/virnetserverservice.c
+++ b/src/rpc/virnetserverservice.c
@@ -280,3 +280,15 @@ void virNetServerServiceToggle(virNetServerServicePtr svc,
VIR_EVENT_HANDLE_READABLE :
0);
}
+
+void virNetServerServiceClose(virNetServerServicePtr svc)
+{
+ int i;
+
+ if (!svc)
+ return;
+
+ for (i = 0; i < svc->nsocks; i++) {
+ virNetSocketClose(svc->socks[i]);
+ }
+}
diff --git a/src/rpc/virnetserverservice.h b/src/rpc/virnetserverservice.h
index 9357598..8540bd9 100644
--- a/src/rpc/virnetserverservice.h
+++ b/src/rpc/virnetserverservice.h
@@ -66,4 +66,6 @@ void virNetServerServiceFree(virNetServerServicePtr svc);
void virNetServerServiceToggle(virNetServerServicePtr svc,
bool enabled);
+void virNetServerServiceClose(virNetServerServicePtr svc);
+
#endif
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index 41b691a..992e33a 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -1222,3 +1222,25 @@ void virNetSocketRemoveIOCallback(virNetSocketPtr sock)
virMutexUnlock(&sock->lock);
}
+
+void virNetSocketClose(virNetSocketPtr sock)
+{
+ if (!sock)
+ return;
+
+ virMutexLock(&sock->lock);
+
+ VIR_FORCE_CLOSE(sock->fd);
+
+#ifdef HAVE_SYS_UN_H
+ /* If a server socket, then unlink UNIX path */
+ if (!sock->client &&
+ sock->localAddr.data.sa.sa_family == AF_UNIX &&
+ sock->localAddr.data.un.sun_path[0] != '\0') {
+ if (unlink(sock->localAddr.data.un.sun_path) == 0)
+ sock->localAddr.data.un.sun_path[0] = '\0';
+ }
+#endif
+
+ virMutexUnlock(&sock->lock);
+}
diff --git a/src/rpc/virnetsocket.h b/src/rpc/virnetsocket.h
index dfb3c5d..1e1c63c 100644
--- a/src/rpc/virnetsocket.h
+++ b/src/rpc/virnetsocket.h
@@ -118,6 +118,7 @@ void virNetSocketUpdateIOCallback(virNetSocketPtr sock,
void virNetSocketRemoveIOCallback(virNetSocketPtr sock);
+void virNetSocketClose(virNetSocketPtr sock);
#endif /* __VIR_NET_SOCKET_H__ */
--
1.7.6