libxl: use thread-safe localtime_r and handle NULL

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
This commit is contained in:
Wei Liu authored and Ian Campbell committed 2015-07-24 11:23:27 +01:00
1 parent 24ee2db689
commit aba1db82f5
1 file changed
+9 -2
+9 -2
View File
@@ -306,10 +306,16 @@ int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config,
rtc_timeoffset = d_config->b_info.rtc_timeoffset;
if (libxl_defbool_val(d_config->b_info.localtime)) {
time_t t;
struct tm *tm;
struct tm *tm, result;
t = time(NULL);
tm = localtime(&t);
tm = localtime_r(&t, &result);
if (!tm) {
LOGE(ERROR, "Failed to call localtime_r");
ret = ERROR_FAIL;
goto out;
}
rtc_timeoffset += tm->tm_gmtoff;
}
@@ -335,6 +341,7 @@ int libxl__arch_domain_create(libxl__gc *gc, libxl_domain_config *d_config,
}
}
out:
return ret;
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.