[PATCH 1/2] daemon: virtlogd: Drop the server shortcut ref pointer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We put the server into a hash table as we do with the other daemons,
there is no compelling reason why it should have another pointer
dedicated just to the server. Besides, the locking daemon doesn't have
it and virtlogd is essentially a copy paste of virtlockd.

Signed-off-by: Erik Skultety <eskultet@xxxxxxxxxx>
---
 src/logging/log_daemon.c | 54 ++++++++++++++++++++++++++++--------------------
 1 file changed, 32 insertions(+), 22 deletions(-)

diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c
index 5a136c59d..7e8c9cfc2 100644
--- a/src/logging/log_daemon.c
+++ b/src/logging/log_daemon.c
@@ -59,7 +59,6 @@ VIR_LOG_INIT("logging.log_daemon");
 struct _virLogDaemon {
     virMutex lock;
     virNetDaemonPtr dmn;
-    virNetServerPtr srv;
     virLogHandlerPtr handler;
 };
 
@@ -117,7 +116,6 @@ virLogDaemonFree(virLogDaemonPtr logd)
 
     virObjectUnref(logd->handler);
     virMutexDestroy(&logd->lock);
-    virObjectUnref(logd->srv);
     virObjectUnref(logd->dmn);
 
     VIR_FREE(logd);
@@ -139,6 +137,7 @@ static virLogDaemonPtr
 virLogDaemonNew(virLogDaemonConfigPtr config, bool privileged)
 {
     virLogDaemonPtr logd;
+    virNetServerPtr srv;
 
     if (VIR_ALLOC(logd) < 0)
         return NULL;
@@ -150,19 +149,21 @@ virLogDaemonNew(virLogDaemonConfigPtr config, bool privileged)
         return NULL;
     }
 
-    if (!(logd->srv = virNetServerNew("virtlogd", 1,
-                                      1, 1, 0, config->max_clients,
-                                      config->max_clients, -1, 0,
-                                      NULL,
-                                      virLogDaemonClientNew,
-                                      virLogDaemonClientPreExecRestart,
-                                      virLogDaemonClientFree,
-                                      (void*)(intptr_t)(privileged ? 0x1 : 0x0))))
+    if (!(srv = virNetServerNew("virtlogd", 1,
+                                1, 1, 0, config->max_clients,
+                                config->max_clients, -1, 0,
+                                NULL,
+                                virLogDaemonClientNew,
+                                virLogDaemonClientPreExecRestart,
+                                virLogDaemonClientFree,
+                                (void*)(intptr_t)(privileged ? 0x1 : 0x0))))
         goto error;
 
     if (!(logd->dmn = virNetDaemonNew()) ||
-        virNetDaemonAddServer(logd->dmn, logd->srv) < 0)
+        virNetDaemonAddServer(logd->dmn, srv) < 0)
         goto error;
+    virObjectUnref(srv);
+    srv = NULL;
 
     if (!(logd->handler = virLogHandlerNew(privileged,
                                            config->max_size,
@@ -174,6 +175,7 @@ virLogDaemonNew(virLogDaemonConfigPtr config, bool privileged)
     return logd;
 
  error:
+    virObjectUnref(srv);
     virLogDaemonFree(logd);
     return NULL;
 }
@@ -191,6 +193,7 @@ virLogDaemonNewPostExecRestart(virJSONValuePtr object, bool privileged,
                                virLogDaemonConfigPtr config)
 {
     virLogDaemonPtr logd;
+    virNetServerPtr srv;
     virJSONValuePtr child;
 
     if (VIR_ALLOC(logd) < 0)
@@ -212,14 +215,15 @@ virLogDaemonNewPostExecRestart(virJSONValuePtr object, bool privileged,
     if (!(logd->dmn = virNetDaemonNewPostExecRestart(child)))
         goto error;
 
-    if (!(logd->srv = virNetDaemonAddServerPostExec(logd->dmn,
-                                                    "virtlogd",
-                                                    virLogDaemonClientNew,
-                                                    virLogDaemonClientNewPostExecRestart,
-                                                    virLogDaemonClientPreExecRestart,
-                                                    virLogDaemonClientFree,
-                                                    (void*)(intptr_t)(privileged ? 0x1 : 0x0))))
+    if (!(srv = virNetDaemonAddServerPostExec(logd->dmn,
+                                              "virtlogd",
+                                              virLogDaemonClientNew,
+                                              virLogDaemonClientNewPostExecRestart,
+                                              virLogDaemonClientPreExecRestart,
+                                              virLogDaemonClientFree,
+                                              (void*)(intptr_t)(privileged ? 0x1 : 0x0))))
         goto error;
+    virObjectUnref(srv);
 
     if (!(child = virJSONValueObjectGet(object, "handler"))) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -857,6 +861,7 @@ virLogDaemonUsage(const char *argv0, bool privileged)
 }
 
 int main(int argc, char **argv) {
+    virNetServerPtr srv = NULL;
     virNetServerProgramPtr logProgram = NULL;
     char *remote_config_file = NULL;
     int statuswrite = -1;
@@ -1076,19 +1081,23 @@ int main(int argc, char **argv) {
             goto cleanup;
         }
 
-        if ((rv = virLogDaemonSetupNetworkingSystemD(logDaemon->srv)) < 0) {
+        srv = virNetDaemonGetServer(logDaemon->dmn, "virtlogd");
+        if ((rv = virLogDaemonSetupNetworkingSystemD(srv)) < 0) {
             ret = VIR_LOG_DAEMON_ERR_NETWORK;
             goto cleanup;
         }
 
         /* Only do this, if systemd did not pass a FD */
         if (rv == 0 &&
-            virLogDaemonSetupNetworkingNative(logDaemon->srv, sock_file) < 0) {
+            virLogDaemonSetupNetworkingNative(srv, sock_file) < 0) {
             ret = VIR_LOG_DAEMON_ERR_NETWORK;
             goto cleanup;
         }
+        virObjectUnref(srv);
     }
 
+    srv = virNetDaemonGetServer(logDaemon->dmn, "virtlogd");
+
     if (timeout != -1) {
         VIR_DEBUG("Registering shutdown timeout %d", timeout);
         virNetDaemonAutoShutdown(logDaemon->dmn,
@@ -1107,7 +1116,7 @@ int main(int argc, char **argv) {
         ret = VIR_LOG_DAEMON_ERR_INIT;
         goto cleanup;
     }
-    if (virNetServerAddProgram(logDaemon->srv, logProgram) < 0) {
+    if (virNetServerAddProgram(srv, logProgram) < 0) {
         ret = VIR_LOG_DAEMON_ERR_INIT;
         goto cleanup;
     }
@@ -1129,7 +1138,7 @@ int main(int argc, char **argv) {
 
     /* Start accepting new clients from network */
 
-    virNetServerUpdateServices(logDaemon->srv, true);
+    virNetServerUpdateServices(srv, true);
     virNetDaemonRun(logDaemon->dmn);
 
     if (execRestart &&
@@ -1142,6 +1151,7 @@ int main(int argc, char **argv) {
 
  cleanup:
     virObjectUnref(logProgram);
+    virObjectUnref(srv);
     virLogDaemonFree(logDaemon);
     if (statuswrite != -1) {
         if (ret != 0) {
-- 
2.13.6

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux