}
static int virSystemdHasMachinedCachedValue = -1;
+static int virSystemdHasLogindCachedValue = -1;
/* Reset the cache from tests for testing the underlying dbus calls
* as well */
virSystemdHasMachinedCachedValue = -1;
}
+void virSystemdHasLogindResetCachedValue(void)
+{
+ virSystemdHasLogindCachedValue = -1;
+}
+
+
/* -2 = machine1 is not supported on this machine
* -1 = error
* 0 = machine1 is available
virSystemdHasLogind(void)
{
int ret;
+ int val;
+
+ val = virAtomicIntGet(&virSystemdHasLogindCachedValue);
+ if (val != -1)
+ return val;
ret = virDBusIsServiceEnabled("org.freedesktop.login1");
- if (ret < 0)
+ if (ret < 0) {
+ if (ret == -2)
+ virAtomicIntSet(&virSystemdHasLogindCachedValue, -2);
return ret;
+ }
- if ((ret = virDBusIsServiceRegistered("org.freedesktop.login1")) < 0)
+ if ((ret = virDBusIsServiceRegistered("org.freedesktop.login1")) == -1)
return ret;
+ virAtomicIntSet(&virSystemdHasLogindCachedValue, ret);
return ret;
}
}; \
if (virTestRun("Test " name " ", testPMSupportHelper, &data) < 0) \
ret = -1; \
+ virSystemdHasLogindResetCachedValue(); \
if (virTestRun("Test " name " no systemd ", \
testPMSupportHelperNoSystemd, &data) < 0) \
ret = -1; \
+ virSystemdHasLogindResetCachedValue(); \
if (virTestRun("Test systemd " name " not running ", \
testPMSupportSystemdNotRunning, &data) < 0) \
ret = -1; \
+ virSystemdHasLogindResetCachedValue(); \
} while (0)
TESTS_PM_SUPPORT_HELPER("canSuspend", &virSystemdCanSuspend);