1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

daemon: virtlogd: Drop the server shortcut ref pointer

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@redhat.com>
This commit is contained in:
Erik Skultety 2017-11-14 14:32:16 +01:00
parent 2721577495
commit 700b0d2a2d

View File

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