Re: [PATCH] Drop dependency on pm-is-supported

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

 



On Mar 28, 2014, at 11:32 AM, Cédric Bosdonnat <cbosdonnat@xxxxxxxx> wrote:
> 
> From: Cédric Bosdonnat <cedric.bosdonnat@xxxxxxx>
> 
> pm-is-supported is the only thing needed in pm-utils, better get rid of
> it since systemd is heavily used for libvirt.
> ---
> src/util/virnodesuspend.c | 34 ++++++++++++++++++++--------------
> 1 file changed, 20 insertions(+), 14 deletions(-)
> 
> diff --git a/src/util/virnodesuspend.c b/src/util/virnodesuspend.c
> index 8088931..9839de2 100644
> --- a/src/util/virnodesuspend.c
> +++ b/src/util/virnodesuspend.c
> @@ -29,6 +29,8 @@
> #include "viralloc.h"
> #include "virlog.h"
> #include "virerror.h"
> +#include "virfile.h"
> +#include "virstring.h"
> 
> #define VIR_FROM_THIS VIR_FROM_NONE
> 
> @@ -263,41 +265,45 @@ int nodeSuspendForDuration(unsigned int target,
> static int
> virNodeSuspendSupportsTarget(unsigned int target, bool *supported)
> {
> -    virCommandPtr cmd;
> -    int status;
>     int ret = -1;
> +    char *buf = NULL;
> +    char **states = NULL;
> +    bool canSuspend = false;
> +    bool canHibernate = false;
> 
>     if (virNodeSuspendInitialize() < 0)
>         return -1;
> 
>     *supported = false;
> 
> +    if (virFileReadAll("/sys/power/state", 1024, &buf) < 0)
> +        goto cleanup;
> +
> +    states = virStringSplit(buf, " ", 0);
> +
> +    canSuspend = (virStringArrayHasString(states, "mem") ||
> +                  virStringArrayHasString(states, "standby"));
> +    canHibernate = virStringArrayHasString(states, "disk");
> +
>     switch (target) {
>     case VIR_NODE_SUSPEND_TARGET_MEM:
> -        cmd = virCommandNewArgList("pm-is-supported", "--suspend", NULL);
> +        *supported = canSuspend;
>         break;
>     case VIR_NODE_SUSPEND_TARGET_DISK:
> -        cmd = virCommandNewArgList("pm-is-supported", "--hibernate", NULL);
> +        *supported = canHibernate;
>         break;
>     case VIR_NODE_SUSPEND_TARGET_HYBRID:
> -        cmd = virCommandNewArgList("pm-is-supported", "--suspend-hybrid", NULL);
> +        *supported = canSuspend && canHibernate;
>         break;
>     default:
>         return ret;
>     }
> 
> -    if (virCommandRun(cmd, &status) < 0)
> -        goto cleanup;
> -
> -   /*
> -    * Check return code of command == 0 for success
> -    * (i.e., the PM capability is supported)
> -    */
> -    *supported = (status == 0);
>     ret = 0;
> 
>  cleanup:
> -    virCommandFree(cmd);
> +    VIR_FREE(buf);
> +    virStringFreeList(states);
>     return ret;
> }
> 
> -- 
> 1.8.4.5
> 
> --
> libvir-list mailing list
> libvir-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libvir-list

While systemd is used for a number of things there are other platforms than Linux and there are Linux platforms that don't use systemd. Can't we just wrap this in if not systemd?

--
Doug

--
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]