Currently, the @flags usage is a bit unclear at first sight to say the
least. There's no need for such unclear code especially when we can
borrow the working code from qemuDomainShutdownFlags().
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
diff to v1:
-lxcDomainReboot adjusted too
-drop @useInitctl
-shorten the commit message a bit
src/lxc/lxc_driver.c | 46 ++++++++++++++++++++--------------------------
1 file changed, 20 insertions(+), 26 deletions(-)
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 7e56a59..06263b9 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -2701,7 +2701,8 @@ lxcDomainShutdownFlags(virDomainPtr dom,
virDomainObjPtr vm;
char *vroot = NULL;
int ret = -1;
- int rc;
+ int rc = 0;
+ bool initctlRequested, signalRequested;
virCheckFlags(VIR_DOMAIN_SHUTDOWN_INITCTL |
VIR_DOMAIN_SHUTDOWN_SIGNAL, -1);
@@ -2730,25 +2731,21 @@ lxcDomainShutdownFlags(virDomainPtr dom,
(unsigned long long)priv->initpid) < 0)
goto cleanup;
- if (flags == 0 ||
- (flags & VIR_DOMAIN_SHUTDOWN_INITCTL)) {
- if ((rc = virInitctlSetRunLevel(VIR_INITCTL_RUNLEVEL_POWEROFF,
- vroot)) < 0) {
+ initctlRequested = !flags || flags & VIR_DOMAIN_SHUTDOWN_INITCTL;
+ signalRequested = !flags || flags & VIR_DOMAIN_SHUTDOWN_SIGNAL;
+
+ if (initctlRequested) {
+ rc = virInitctlSetRunLevel(VIR_INITCTL_RUNLEVEL_POWEROFF, vroot);
+ if (rc < 0 && !signalRequested)
goto cleanup;
- }
- if (rc == 0 && flags != 0 &&
- ((flags & ~VIR_DOMAIN_SHUTDOWN_INITCTL) == 0)) {
+ if (rc == 0 && !signalRequested) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("Container does not provide an initctl pipe"));
goto cleanup;
}
- } else {
- rc = 0;
}
- if (rc == 0 &&
- (flags == 0 ||
- (flags & VIR_DOMAIN_SHUTDOWN_SIGNAL))) {
+ if (signalRequested || rc == 0) {
if (kill(priv->initpid, SIGTERM) < 0 &&
errno != ESRCH) {
virReportSystemError(errno,
@@ -2781,7 +2778,8 @@ lxcDomainReboot(virDomainPtr dom,
virDomainObjPtr vm;
char *vroot = NULL;
int ret = -1;
- int rc;
+ int rc = 0;
+ bool initctlRequested, signalRequested;
virCheckFlags(VIR_DOMAIN_REBOOT_INITCTL |
VIR_DOMAIN_REBOOT_SIGNAL, -1);
@@ -2810,25 +2808,21 @@ lxcDomainReboot(virDomainPtr dom,
(unsigned long long)priv->initpid) < 0)
goto cleanup;
- if (flags == 0 ||
- (flags & VIR_DOMAIN_REBOOT_INITCTL)) {
- if ((rc = virInitctlSetRunLevel(VIR_INITCTL_RUNLEVEL_REBOOT,
- vroot)) < 0) {
+ initctlRequested = !flags || flags & VIR_DOMAIN_REBOOT_INITCTL;
+ signalRequested = !flags || flags & VIR_DOMAIN_REBOOT_SIGNAL;
+
+ if (initctlRequested) {
+ rc = virInitctlSetRunLevel(VIR_INITCTL_RUNLEVEL_REBOOT, vroot);
+ if (rc < 0)
goto cleanup;
- }
- if (rc == 0 && flags != 0 &&
- ((flags & ~VIR_DOMAIN_SHUTDOWN_INITCTL) == 0)) {
+ if (rc == 0 && !signalRequested) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("Container does not provide an initctl pipe"));
goto cleanup;
}
- } else {
- rc = 0;
}
- if (rc == 0 &&
- (flags == 0 ||
- (flags & VIR_DOMAIN_REBOOT_SIGNAL))) {
+ if (signalRequested || rc == 0) {
if (kill(priv->initpid, SIGHUP) < 0 &&
errno != ESRCH) {
virReportSystemError(errno,
--
1.8.5.1