mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-01 20:05:46 +00:00
util: cache the result of whether logind is available
Similar to how we cache the availability of machined. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
81177ff4de
commit
dd16434a2a
@ -3135,6 +3135,7 @@ virSystemdCanSuspend;
|
|||||||
virSystemdCreateMachine;
|
virSystemdCreateMachine;
|
||||||
virSystemdGetActivation;
|
virSystemdGetActivation;
|
||||||
virSystemdGetMachineNameByPID;
|
virSystemdGetMachineNameByPID;
|
||||||
|
virSystemdHasLogindResetCachedValue;
|
||||||
virSystemdHasMachinedResetCachedValue;
|
virSystemdHasMachinedResetCachedValue;
|
||||||
virSystemdMakeScopeName;
|
virSystemdMakeScopeName;
|
||||||
virSystemdMakeSliceName;
|
virSystemdMakeSliceName;
|
||||||
|
@ -140,6 +140,7 @@ char *virSystemdMakeSliceName(const char *partition)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int virSystemdHasMachinedCachedValue = -1;
|
static int virSystemdHasMachinedCachedValue = -1;
|
||||||
|
static int virSystemdHasLogindCachedValue = -1;
|
||||||
|
|
||||||
/* Reset the cache from tests for testing the underlying dbus calls
|
/* Reset the cache from tests for testing the underlying dbus calls
|
||||||
* as well */
|
* as well */
|
||||||
@ -148,6 +149,12 @@ void virSystemdHasMachinedResetCachedValue(void)
|
|||||||
virSystemdHasMachinedCachedValue = -1;
|
virSystemdHasMachinedCachedValue = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void virSystemdHasLogindResetCachedValue(void)
|
||||||
|
{
|
||||||
|
virSystemdHasLogindCachedValue = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -2 = machine1 is not supported on this machine
|
/* -2 = machine1 is not supported on this machine
|
||||||
* -1 = error
|
* -1 = error
|
||||||
* 0 = machine1 is available
|
* 0 = machine1 is available
|
||||||
@ -178,14 +185,23 @@ static int
|
|||||||
virSystemdHasLogind(void)
|
virSystemdHasLogind(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
int val;
|
||||||
|
|
||||||
|
val = virAtomicIntGet(&virSystemdHasLogindCachedValue);
|
||||||
|
if (val != -1)
|
||||||
|
return val;
|
||||||
|
|
||||||
ret = virDBusIsServiceEnabled("org.freedesktop.login1");
|
ret = virDBusIsServiceEnabled("org.freedesktop.login1");
|
||||||
if (ret < 0)
|
if (ret < 0) {
|
||||||
return ret;
|
if (ret == -2)
|
||||||
|
virAtomicIntSet(&virSystemdHasLogindCachedValue, -2);
|
||||||
if ((ret = virDBusIsServiceRegistered("org.freedesktop.login1")) < 0)
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((ret = virDBusIsServiceRegistered("org.freedesktop.login1")) == -1)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
virAtomicIntSet(&virSystemdHasLogindCachedValue, ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,3 +28,4 @@
|
|||||||
#include "virsystemd.h"
|
#include "virsystemd.h"
|
||||||
|
|
||||||
void virSystemdHasMachinedResetCachedValue(void);
|
void virSystemdHasMachinedResetCachedValue(void);
|
||||||
|
void virSystemdHasLogindResetCachedValue(void);
|
||||||
|
@ -751,12 +751,15 @@ mymain(void)
|
|||||||
}; \
|
}; \
|
||||||
if (virTestRun("Test " name " ", testPMSupportHelper, &data) < 0) \
|
if (virTestRun("Test " name " ", testPMSupportHelper, &data) < 0) \
|
||||||
ret = -1; \
|
ret = -1; \
|
||||||
|
virSystemdHasLogindResetCachedValue(); \
|
||||||
if (virTestRun("Test " name " no systemd ", \
|
if (virTestRun("Test " name " no systemd ", \
|
||||||
testPMSupportHelperNoSystemd, &data) < 0) \
|
testPMSupportHelperNoSystemd, &data) < 0) \
|
||||||
ret = -1; \
|
ret = -1; \
|
||||||
|
virSystemdHasLogindResetCachedValue(); \
|
||||||
if (virTestRun("Test systemd " name " not running ", \
|
if (virTestRun("Test systemd " name " not running ", \
|
||||||
testPMSupportSystemdNotRunning, &data) < 0) \
|
testPMSupportSystemdNotRunning, &data) < 0) \
|
||||||
ret = -1; \
|
ret = -1; \
|
||||||
|
virSystemdHasLogindResetCachedValue(); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
TESTS_PM_SUPPORT_HELPER("canSuspend", &virSystemdCanSuspend);
|
TESTS_PM_SUPPORT_HELPER("canSuspend", &virSystemdCanSuspend);
|
||||||
|
Loading…
Reference in New Issue
Block a user