mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 10:11:27 +01:00
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:
1 parent
24ee2db689
commit
aba1db82f5
1 file changed
+9
-2
@@ -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;
|
||||
}
|
||||
|
||||
|
||||