[PATCH 0/4] Random almost trivial improvements

These all stem out from me playing with coccinelle. Michal Prívozník (4): virnetserver: Check for virNetServerClientInitKeepAlive() retval rpc: Make some functions void lib: Drop needless ret variables src: Fix boolean assignment src/conf/nwfilter_conf.c | 6 +++--- src/conf/virstorageobj.c | 2 +- src/locking/lock_daemon.c | 3 +-- src/logging/log_daemon.c | 3 +-- src/lxc/lxc_driver.c | 2 +- src/nwfilter/nwfilter_dhcpsnoop.c | 2 +- src/qemu/qemu_agent.c | 10 +++++----- src/qemu/qemu_monitor.c | 4 ++-- src/remote/remote_daemon.c | 2 +- src/remote/remote_daemon_config.c | 8 ++++---- src/remote/remote_driver.c | 2 +- src/rpc/virnetlibsshsession.c | 4 +--- src/rpc/virnetlibsshsession.h | 4 ++-- src/rpc/virnetserver.c | 7 ++++--- src/rpc/virnetserverclient.c | 2 +- src/rpc/virnetsocket.c | 6 ++---- src/rpc/virnetsshsession.c | 4 +--- src/rpc/virnetsshsession.h | 4 ++-- src/storage/storage_backend_mpath.c | 3 +-- src/util/virnetlink.c | 2 +- src/util/virtime.c | 4 ++-- src/util/viruri.c | 2 +- src/vmx/vmx.c | 4 ++-- tools/virt-host-validate-bhyve.c | 3 +-- 24 files changed, 42 insertions(+), 51 deletions(-) -- 2.26.2

Since it's introduction in v0.9.7-147-gf4324e3292 the virNetServerClientInitKeepAlive() function returned nothing than a negative one. Fortunately, this did not pose any problem because we ignored the retval happily. Well, it's time to check for the retval because the function might fail regularly. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/rpc/virnetserver.c | 5 +++-- src/rpc/virnetserverclient.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index 242052754f..07c8b85b76 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -306,8 +306,9 @@ int virNetServerAddClient(virNetServerPtr srv, virNetServerDispatchNewMessage, srv); - virNetServerClientInitKeepAlive(client, srv->keepaliveInterval, - srv->keepaliveCount); + if (virNetServerClientInitKeepAlive(client, srv->keepaliveInterval, + srv->keepaliveCount) < 0) + goto error; virObjectUnlock(srv); return 0; diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c index 657108239f..756adcbb4f 100644 --- a/src/rpc/virnetserverclient.c +++ b/src/rpc/virnetserverclient.c @@ -1599,7 +1599,7 @@ virNetServerClientInitKeepAlive(virNetServerClientPtr client, virObjectRef(client); client->keepalive = ka; - + ret = 0; cleanup: virObjectUnlock(client); -- 2.26.2

There are few functions that currently return an integer but in fact they always return the same integer (zero). Make them void. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/rpc/virnetlibsshsession.c | 4 +--- src/rpc/virnetlibsshsession.h | 4 ++-- src/rpc/virnetsocket.c | 6 ++---- src/rpc/virnetsshsession.c | 4 +--- src/rpc/virnetsshsession.h | 4 ++-- 5 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c index 9c20a80b88..0a566eaa54 100644 --- a/src/rpc/virnetlibsshsession.c +++ b/src/rpc/virnetlibsshsession.c @@ -1082,11 +1082,10 @@ virNetLibsshSessionAuthAddKeyboardAuth(virNetLibsshSessionPtr sess, } -int +void virNetLibsshSessionSetChannelCommand(virNetLibsshSessionPtr sess, const char *command) { - int ret = 0; virObjectLock(sess); VIR_FREE(sess->channelCommand); @@ -1094,7 +1093,6 @@ virNetLibsshSessionSetChannelCommand(virNetLibsshSessionPtr sess, sess->channelCommand = g_strdup(command); virObjectUnlock(sess); - return ret; } int diff --git a/src/rpc/virnetlibsshsession.h b/src/rpc/virnetlibsshsession.h index 231c2591b2..e982bcd2ef 100644 --- a/src/rpc/virnetlibsshsession.h +++ b/src/rpc/virnetlibsshsession.h @@ -35,8 +35,8 @@ typedef enum { VIR_NET_LIBSSH_HOSTKEY_VERIFY_IGNORE } virNetLibsshHostkeyVerify; -int virNetLibsshSessionSetChannelCommand(virNetLibsshSessionPtr sess, - const char *command); +void virNetLibsshSessionSetChannelCommand(virNetLibsshSessionPtr sess, + const char *command); int virNetLibsshSessionAuthSetCallback(virNetLibsshSessionPtr sess, virConnectAuthPtr auth); diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index 6c790cb577..3ea863f625 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -969,8 +969,7 @@ virNetSocketNewConnectLibSSH2(const char *host, VIR_NET_SSH_HOSTKEY_FILE_CREATE) != 0) goto error; - if (virNetSSHSessionSetChannelCommand(sess, command) != 0) - goto error; + virNetSSHSessionSetChannelCommand(sess, command); if (!(authMethodList = virStringSplit(authMethods, ",", 0))) goto error; @@ -1101,8 +1100,7 @@ virNetSocketNewConnectLibssh(const char *host, verify) != 0) goto error; - if (virNetLibsshSessionSetChannelCommand(sess, command) != 0) - goto error; + virNetLibsshSessionSetChannelCommand(sess, command); if (!(authMethodList = virStringSplit(authMethods, ",", 0))) goto error; diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c index fabdc3ef22..b4dea15452 100644 --- a/src/rpc/virnetsshsession.c +++ b/src/rpc/virnetsshsession.c @@ -1132,11 +1132,10 @@ virNetSSHSessionAuthAddKeyboardAuth(virNetSSHSessionPtr sess, } -int +void virNetSSHSessionSetChannelCommand(virNetSSHSessionPtr sess, const char *command) { - int ret = 0; virObjectLock(sess); VIR_FREE(sess->channelCommand); @@ -1144,7 +1143,6 @@ virNetSSHSessionSetChannelCommand(virNetSSHSessionPtr sess, sess->channelCommand = g_strdup(command); virObjectUnlock(sess); - return ret; } int diff --git a/src/rpc/virnetsshsession.h b/src/rpc/virnetsshsession.h index 0101489302..4d639da453 100644 --- a/src/rpc/virnetsshsession.h +++ b/src/rpc/virnetsshsession.h @@ -40,8 +40,8 @@ typedef enum { VIR_NET_SSH_HOSTKEY_FILE_CREATE = 1 << 1, } virNetSSHHostKeyFileFlags; -int virNetSSHSessionSetChannelCommand(virNetSSHSessionPtr sess, - const char *command); +void virNetSSHSessionSetChannelCommand(virNetSSHSessionPtr sess, + const char *command); void virNetSSHSessionAuthReset(virNetSSHSessionPtr sess); -- 2.26.2

There are few places where a return variable is introduced (ret or retval), but then is never changed and is then passed to return. Well, we can return the value that the variable is initialized to directly. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/locking/lock_daemon.c | 3 +-- src/logging/log_daemon.c | 3 +-- src/storage/storage_backend_mpath.c | 3 +-- tools/virt-host-validate-bhyve.c | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 4eff63014a..b0cd89375b 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -720,7 +720,6 @@ virLockDaemonPreExecRestart(const char *state_file, { virJSONValuePtr child; char *state = NULL; - int ret = -1; virJSONValuePtr object = virJSONValueNewObject(); char *magic; virHashKeyValuePairPtr pairs = NULL, tmp; @@ -800,7 +799,7 @@ virLockDaemonPreExecRestart(const char *state_file, VIR_FREE(pairs); VIR_FREE(state); virJSONValueFree(object); - return ret; + return -1; } diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c index f37054706e..7017db2dcc 100644 --- a/src/logging/log_daemon.c +++ b/src/logging/log_daemon.c @@ -524,7 +524,6 @@ virLogDaemonPreExecRestart(const char *state_file, { virJSONValuePtr child; char *state = NULL; - int ret = -1; virJSONValuePtr object = virJSONValueNewObject(); char *magic; virHashKeyValuePairPtr pairs = NULL; @@ -581,7 +580,7 @@ virLogDaemonPreExecRestart(const char *state_file, VIR_FREE(pairs); VIR_FREE(state); virJSONValueFree(object); - return ret; + return -1; } diff --git a/src/storage/storage_backend_mpath.c b/src/storage/storage_backend_mpath.c index 7cb084b2d6..fffc0f86b7 100644 --- a/src/storage/storage_backend_mpath.c +++ b/src/storage/storage_backend_mpath.c @@ -243,7 +243,6 @@ virStorageBackendMpathCheckPool(virStoragePoolObjPtr pool G_GNUC_UNUSED, static int virStorageBackendMpathRefreshPool(virStoragePoolObjPtr pool) { - int retval = 0; virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool); VIR_DEBUG("pool=%p", pool); @@ -254,7 +253,7 @@ virStorageBackendMpathRefreshPool(virStoragePoolObjPtr pool) virStorageBackendGetMaps(pool); - return retval; + return 0; } diff --git a/tools/virt-host-validate-bhyve.c b/tools/virt-host-validate-bhyve.c index 2f0ec1e36c..3e8cc59a38 100644 --- a/tools/virt-host-validate-bhyve.c +++ b/tools/virt-host-validate-bhyve.c @@ -47,7 +47,6 @@ int virHostValidateBhyve(void) { - int ret = 0; int fileid = 0; struct kld_file_stat stat; bool vmm_loaded = false, if_tap_loaded = false; @@ -73,5 +72,5 @@ int virHostValidateBhyve(void) MODULE_STATUS_WARN(if_bridge, "bridged networking will not work"); MODULE_STATUS_WARN(nmdm, "nmdm console will not work"); - return ret; + return 0; } -- 2.26.2

On Tue, May 05, 2020 at 12:10:07PM +0200, Michal Privoznik wrote:
diff --git a/tools/virt-host-validate-bhyve.c b/tools/virt-host-validate-bhyve.c index 2f0ec1e36c..3e8cc59a38 100644 --- a/tools/virt-host-validate-bhyve.c +++ b/tools/virt-host-validate-bhyve.c @@ -47,7 +47,6 @@
int virHostValidateBhyve(void) { - int ret = 0; int fileid = 0; struct kld_file_stat stat; bool vmm_loaded = false, if_tap_loaded = false; @@ -73,5 +72,5 @@ int virHostValidateBhyve(void) MODULE_STATUS_WARN(if_bridge, "bridged networking will not work"); MODULE_STATUS_WARN(nmdm, "nmdm console will not work");
- return ret; + return 0; }
This change broke the build because MODULE_STATUS_WARN is a macro that does indeed use 'ret'. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

In a few places we use 0 and false, or 1 and true interchangeably even though the variable or return type in question is boolean. Fix those places. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/nwfilter_conf.c | 6 +++--- src/conf/virstorageobj.c | 2 +- src/lxc/lxc_driver.c | 2 +- src/nwfilter/nwfilter_dhcpsnoop.c | 2 +- src/qemu/qemu_agent.c | 10 +++++----- src/qemu/qemu_monitor.c | 4 ++-- src/remote/remote_daemon.c | 2 +- src/remote/remote_daemon_config.c | 8 ++++---- src/remote/remote_driver.c | 2 +- src/rpc/virnetserver.c | 2 +- src/util/virnetlink.c | 2 +- src/util/virtime.c | 4 ++-- src/util/viruri.c | 2 +- src/vmx/vmx.c | 4 ++-- 14 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index 680f4184c3..732c05ac89 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -1848,7 +1848,7 @@ virNWFilterRuleDetailsParse(xmlNodePtr node, att_datatypes = att[idx].datatype; - while (datatype <= DATATYPE_LAST && found == 0 && rc == 0) { + while (datatype <= DATATYPE_LAST && !found && rc == 0) { if ((att_datatypes & datatype)) { att_datatypes ^= datatype; @@ -2881,14 +2881,14 @@ virNWFilterRuleDefDetailsFormat(virBufferPtr buf, matchShown = MATCH_NO; } else if (matchShown == MATCH_YES) { virBufferAddLit(buf, "/>\n"); - typeShown = 0; + typeShown = false; matchShown = MATCH_NONE; continue; } } else { if (matchShown == MATCH_NO) { virBufferAddLit(buf, "/>\n"); - typeShown = 0; + typeShown = false; matchShown = MATCH_NONE; continue; } diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 5cbd30f93c..13b75b648d 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -332,7 +332,7 @@ bool virStoragePoolObjIsAutostart(virStoragePoolObjPtr obj) { if (!obj->configFile) - return 0; + return false; return obj->autostart; } diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 61dd35360a..3111562568 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1512,7 +1512,7 @@ static int lxcStateInitialize(bool privileged, if (!(lxc_driver->config = cfg = virLXCDriverConfigNew())) goto cleanup; - cfg->log_libvirtd = 0; /* by default log to container logfile */ + cfg->log_libvirtd = false; /* by default log to container logfile */ cfg->have_netns = lxcCheckNetNsSupport(); /* Call function to load lxc driver configuration information */ diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c index 953d8936a4..f530341872 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -326,7 +326,7 @@ virNWFilterSnoopIsActive(char *threadKey) void *entry; if (threadKey == NULL) - return 0; + return false; virNWFilterSnoopActiveLock(); diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index d7fcc869c6..6fa48c06e3 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -267,7 +267,7 @@ qemuAgentIOProcessLine(qemuAgentPtr agent, /* receiving garbage on first sync is regular situation */ if (msg && msg->sync && msg->first) { VIR_DEBUG("Received garbage on sync"); - msg->finished = 1; + msg->finished = true; return 0; } @@ -306,7 +306,7 @@ qemuAgentIOProcessLine(qemuAgentPtr agent, } } msg->rxObject = obj; - msg->finished = 1; + msg->finished = true; obj = NULL; } else { /* we are out of sync */ @@ -627,7 +627,7 @@ qemuAgentIO(GSocket *socket G_GNUC_UNUSED, /* If IO process resulted in an error & we have a message, * then wakeup that waiter */ if (agent->msg && !agent->msg->finished) { - agent->msg->finished = 1; + agent->msg->finished = true; virCondSignal(&agent->notify); } } @@ -751,7 +751,7 @@ qemuAgentNotifyCloseLocked(qemuAgentPtr agent) /* If there is somebody waiting for a message * wake him up. No message will arrive anyway. */ if (agent->msg && !agent->msg->finished) { - agent->msg->finished = 1; + agent->msg->finished = true; virCondSignal(&agent->notify); } } @@ -1209,7 +1209,7 @@ void qemuAgentNotifyEvent(qemuAgentPtr agent, agent->await_event = QEMU_AGENT_EVENT_NONE; /* somebody waiting for this event, wake him up. */ if (agent->msg && !agent->msg->finished) { - agent->msg->finished = 1; + agent->msg->finished = true; virCondSignal(&agent->notify); } } diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index a62fed845e..339facfad3 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -617,7 +617,7 @@ qemuMonitorIO(GSocket *socket G_GNUC_UNUSED, /* If IO process resulted in an error & we have a message, * then wakeup that waiter */ if (mon->msg && !mon->msg->finished) { - mon->msg->finished = 1; + mon->msg->finished = true; virCondSignal(&mon->notify); } } @@ -880,7 +880,7 @@ qemuMonitorClose(qemuMonitorPtr mon) else virResetLastError(); } - mon->msg->finished = 1; + mon->msg->finished = true; virCondSignal(&mon->notify); } diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index 7eec599177..1aa9bfc0d2 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -781,7 +781,7 @@ int main(int argc, char **argv) { # endif /* ! LIBVIRTD */ #endif /* ! WITH_IP */ struct daemonConfig *config; - bool privileged = geteuid() == 0 ? true : false; + bool privileged = geteuid() == 0; bool implicit_conf = false; char *run_dir = NULL; mode_t old_umask; diff --git a/src/remote/remote_daemon_config.c b/src/remote/remote_daemon_config.c index 0ecc49f179..a09f287656 100644 --- a/src/remote/remote_daemon_config.c +++ b/src/remote/remote_daemon_config.c @@ -99,11 +99,11 @@ daemonConfigNew(bool privileged G_GNUC_UNUSED) #ifdef WITH_IP # ifdef LIBVIRTD - data->listen_tls = 1; /* Only honoured if --listen is set */ + data->listen_tls = true; /* Only honoured if --listen is set */ # else /* ! LIBVIRTD */ - data->listen_tls = 0; /* Always honoured, --listen doesn't exist. */ + data->listen_tls = false; /* Always honoured, --listen doesn't exist. */ # endif /* ! LIBVIRTD */ - data->listen_tcp = 0; + data->listen_tcp = false; data->tls_port = g_strdup(LIBVIRTD_TLS_PORT); data->tcp_port = g_strdup(LIBVIRTD_TCP_PORT); @@ -146,7 +146,7 @@ daemonConfigNew(bool privileged G_GNUC_UNUSED) data->max_client_requests = 5; data->audit_level = 1; - data->audit_logging = 0; + data->audit_logging = false; data->keepalive_interval = 5; data->keepalive_count = 5; diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 7bae0c2514..0aeab9db27 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -1133,7 +1133,7 @@ doRemoteOpen(virConnectPtr conn, goto failed; priv->tls = virNetTLSContextNewClientPath(pkipath, - geteuid() != 0 ? true : false, + geteuid() != 0, tls_priority, sanity, verify); if (!priv->tls) diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index 07c8b85b76..e0a23867f6 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -1231,7 +1231,7 @@ virNetServerUpdateTlsFiles(virNetServerPtr srv) { int ret = -1; virNetTLSContextPtr ctxt = NULL; - bool privileged = geteuid() == 0 ? true : false; + bool privileged = geteuid() == 0; ctxt = virNetServerGetTLSContext(srv); if (!ctxt) { diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index 3117dcbe65..d23ed95b78 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -1340,7 +1340,7 @@ int virNetlinkEventServiceStart(unsigned int protocol G_GNUC_UNUSED, bool virNetlinkEventServiceIsRunning(unsigned int protocol G_GNUC_UNUSED) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported)); - return 0; + return false; } int virNetlinkEventServiceLocalPid(unsigned int protocol G_GNUC_UNUSED) diff --git a/src/util/virtime.c b/src/util/virtime.c index bc8f06cd48..88f6f0a551 100644 --- a/src/util/virtime.c +++ b/src/util/virtime.c @@ -386,7 +386,7 @@ virTimeBackOffWait(virTimeBackOffVar *var) VIR_DEBUG("t=%llu, limit=%llu", t, var->limit_t); if (t > var->limit_t) - return 0; /* ends the while loop */ + return false; /* ends the while loop */ /* Compute next wait time. Cap at VIR_TIME_BACKOFF_CAP * to avoid long useless sleeps. */ @@ -406,5 +406,5 @@ virTimeBackOffWait(virTimeBackOffVar *var) VIR_DEBUG("sleeping for %llu ms", next); g_usleep(next * 1000); - return 1; + return true; } diff --git a/src/util/viruri.c b/src/util/viruri.c index 58d9016a61..5fa0a6f0c8 100644 --- a/src/util/viruri.c +++ b/src/util/viruri.c @@ -48,7 +48,7 @@ virURIParamAppend(virURIPtr uri, uri->params[uri->paramsCount].name = pname; uri->params[uri->paramsCount].value = pvalue; - uri->params[uri->paramsCount].ignore = 0; + uri->params[uri->paramsCount].ignore = false; uri->paramsCount++; return 0; diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index b1fd1181eb..f2248cef53 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -840,9 +840,9 @@ virVMXGetConfigBoolean(virConfPtr conf, const char *name, bool *boolean_, return rc; if (STRCASEEQ(string, "true")) { - *boolean_ = 1; + *boolean_ = true; } else if (STRCASEEQ(string, "false")) { - *boolean_ = 0; + *boolean_ = false; } else { virReportError(VIR_ERR_INTERNAL_ERROR, _("Config entry '%s' must represent a boolean value " -- 2.26.2

On Tue, May 05, 2020 at 12:10:04PM +0200, Michal Privoznik wrote:
These all stem out from me playing with coccinelle.
Michal Prívozník (4): virnetserver: Check for virNetServerClientInitKeepAlive() retval rpc: Make some functions void lib: Drop needless ret variables src: Fix boolean assignment
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
participants (2)
-
Daniel P. Berrangé
-
Michal Privoznik