[libvirt] [PATCH 04/12] virsh: domid: Error out if domain is not active

Lin Ma posted 12 patches 5 years, 5 months ago
There is a newer version of this series
[libvirt] [PATCH 04/12] virsh: domid: Error out if domain is not active
Posted by Lin Ma 5 years, 5 months ago
Signed-off-by: Lin Ma <lma@suse.de>
---
 tools/virsh-domain.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index d1d3f8e566..86152a53b1 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -10458,18 +10458,21 @@ cmdDomid(vshControl *ctl, const vshCmd *cmd)
 {
     virDomainPtr dom;
     unsigned int id;
+    bool ret = false;
 
     if (!(dom = virshCommandOptDomainBy(ctl, cmd, NULL,
                                         VIRSH_BYNAME|VIRSH_BYUUID)))
-        return false;
+        return ret;
 
     id = virDomainGetID(dom);
-    if (id == ((unsigned int)-1))
-        vshPrint(ctl, "%s\n", "-");
-    else
+    if (id == ((unsigned int)-1)) {
+        vshError(ctl, "%s", _("Domain is not active"));
+    } else {
         vshPrint(ctl, "%d\n", id);
+        ret = true;
+    }
     virshDomainFree(dom);
-    return true;
+    return ret;
 }
 
 /*
-- 
2.26.0

Re: [libvirt] [PATCH 04/12] virsh: domid: Error out if domain is not active
Posted by Ján Tomko 5 years, 4 months ago
On a Friday in 2020, Lin Ma wrote:
>Signed-off-by: Lin Ma <lma@suse.de>
>---
> tools/virsh-domain.c | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)
>
>diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
>index d1d3f8e566..86152a53b1 100644
>--- a/tools/virsh-domain.c
>+++ b/tools/virsh-domain.c
>@@ -10458,18 +10458,21 @@ cmdDomid(vshControl *ctl, const vshCmd *cmd)
> {
>     virDomainPtr dom;
>     unsigned int id;
>+    bool ret = false;
>
>     if (!(dom = virshCommandOptDomainBy(ctl, cmd, NULL,
>                                         VIRSH_BYNAME|VIRSH_BYUUID)))
>-        return false;
>+        return ret;
>
>     id = virDomainGetID(dom);
>-    if (id == ((unsigned int)-1))
>-        vshPrint(ctl, "%s\n", "-");
>-    else
>+    if (id == ((unsigned int)-1)) {
>+        vshError(ctl, "%s", _("Domain is not active"));

I'm not convinced we should change the existing behavior here.

Jano

>+    } else {
>         vshPrint(ctl, "%d\n", id);
>+        ret = true;
>+    }
>     virshDomainFree(dom);
>-    return true;
>+    return ret;
> }
>
> /*
>-- 
>2.26.0
>
Re: [libvirt] [PATCH 04/12] virsh: domid: Error out if domain is not active
Posted by Lin Ma 5 years, 4 months ago
On 2020-09-12 10:31, Ján Tomko wrote:
> On a Friday in 2020, Lin Ma wrote:
>> Signed-off-by: Lin Ma <lma@suse.de>
>> ---
>> tools/virsh-domain.c | 13 ++++++++-----
>> 1 file changed, 8 insertions(+), 5 deletions(-)
>> 
>> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
>> index d1d3f8e566..86152a53b1 100644
>> --- a/tools/virsh-domain.c
>> +++ b/tools/virsh-domain.c
>> @@ -10458,18 +10458,21 @@ cmdDomid(vshControl *ctl, const vshCmd *cmd)
>> {
>>     virDomainPtr dom;
>>     unsigned int id;
>> +    bool ret = false;
>> 
>>     if (!(dom = virshCommandOptDomainBy(ctl, cmd, NULL,
>>                                         VIRSH_BYNAME|VIRSH_BYUUID)))
>> -        return false;
>> +        return ret;
>> 
>>     id = virDomainGetID(dom);
>> -    if (id == ((unsigned int)-1))
>> -        vshPrint(ctl, "%s\n", "-");
>> -    else
>> +    if (id == ((unsigned int)-1)) {
>> +        vshError(ctl, "%s", _("Domain is not active"));
> 
> I'm not convinced we should change the existing behavior here.
> 
> Jano
> 

ok, let's leave it as it is.

Thanks,
Lin


>> +    } else {
>>         vshPrint(ctl, "%d\n", id);
>> +        ret = true;
>> +    }
>>     virshDomainFree(dom);
>> -    return true;
>> +    return ret;
>> }
>> 
>> /*
>> -- 2.26.0
>>