提交 10ec0725 编写于 作者: D Daniel P. Berrange

Add helper APIs to track if libvirtd or loadable modules have changed

The future QEMU capabilities cache needs to be able to invalidate
itself if the libvirtd binary or any loadable modules are changed
on disk. Record the 'ctime' value for these binaries and provide
helper APIs to query it. This approach assumes that if libvirt.so
is changed, then libvirtd will also change, which should usually
be the case with libtool's wrapper scripts that cause libvirtd to
get re-linked
Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
上级 f5796b61
......@@ -1152,6 +1152,8 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE);
}
virUpdateSelfLastChanged(argv[0]);
if (strstr(argv[0], "lt-libvirtd") ||
strstr(argv[0], "/daemon/.libs/libvirtd")) {
char *tmp = strrchr(argv[0], '/');
......
......@@ -74,6 +74,8 @@ virDriverLoadModule(const char *name)
goto cleanup;
}
virUpdateSelfLastChanged(modfile);
handle = dlopen(modfile, RTLD_NOW | RTLD_GLOBAL);
if (!handle) {
VIR_ERROR(_("failed to load module %s %s"), modfile, dlerror());
......
......@@ -1954,6 +1954,7 @@ virGetGroupID;
virGetGroupList;
virGetGroupName;
virGetHostname;
virGetSelfLastChanged;
virGetUnprivSGIOSysfsPath;
virGetUserCacheDirectory;
virGetUserConfigDirectory;
......@@ -1983,6 +1984,7 @@ virSetNonBlock;
virSetUIDGID;
virSetUIDGIDWithCaps;
virStrIsPrint;
virUpdateSelfLastChanged;
virValidateWWN;
......
......@@ -2173,3 +2173,26 @@ bool virIsSUID(void)
{
return getuid() != geteuid();
}
static time_t selfLastChanged;
time_t virGetSelfLastChanged(void)
{
return selfLastChanged;
}
void virUpdateSelfLastChanged(const char *path)
{
struct stat sb;
if (stat(path, &sb) < 0)
return;
if (sb.st_ctime > selfLastChanged) {
VIR_DEBUG("Setting self last changed to %lld for '%s'",
(long long)sb.st_ctime, path);
selfLastChanged = sb.st_ctime;
}
}
......@@ -194,4 +194,8 @@ const char *virGetEnvBlockSUID(const char *name);
const char *virGetEnvAllowSUID(const char *name);
bool virIsSUID(void);
time_t virGetSelfLastChanged(void);
void virUpdateSelfLastChanged(const char *path);
#endif /* __VIR_UTIL_H__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册