Merge pull request #6879 from marcelhollerbach/testsuite-fix

time-util: testsuite fix
This commit is contained in:
Lennart Poettering
2017-09-22 18:47:59 +02:00
committed by GitHub
+18 -10
View File
@@ -849,11 +849,11 @@ parse_usec:
}
from_tm:
x = mktime_or_timegm(&tm, utc);
if (x < 0)
if (weekday >= 0 && tm.tm_wday != weekday)
return -EINVAL;
if (weekday >= 0 && tm.tm_wday != weekday)
x = mktime_or_timegm(&tm, utc);
if (x < 0)
return -EINVAL;
ret = (usec_t) x * USEC_PER_SEC + x_usec;
@@ -883,20 +883,18 @@ typedef struct ParseTimestampResult {
} ParseTimestampResult;
int parse_timestamp(const char *t, usec_t *usec) {
char *last_space, *timezone = NULL;
char *last_space, *tz = NULL;
ParseTimestampResult *shared, tmp;
int r;
pid_t pid;
last_space = strrchr(t, ' ');
if (last_space != NULL && timezone_is_valid(last_space + 1))
timezone = last_space + 1;
tz = last_space + 1;
if (timezone == NULL || endswith_no_case(t, " UTC"))
if (tz == NULL || endswith_no_case(t, " UTC"))
return parse_timestamp_impl(t, usec, false);
t = strndupa(t, last_space - t);
shared = mmap(NULL, sizeof *shared, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
if (shared == MAP_FAILED)
return negative_errno();
@@ -910,14 +908,24 @@ int parse_timestamp(const char *t, usec_t *usec) {
}
if (pid == 0) {
if (setenv("TZ", timezone, 1) != 0) {
bool with_tz = true;
if (setenv("TZ", tz, 1) != 0) {
shared->return_value = negative_errno();
_exit(EXIT_FAILURE);
}
tzset();
shared->return_value = parse_timestamp_impl(t, &shared->usec, true);
/* If there is a timezone that matches the tzname fields, leave the parsing to the implementation.
* Otherwise just cut it off */
with_tz = !STR_IN_SET(tz, tzname[0], tzname[1]);
/*cut off the timezone if we dont need it*/
if (with_tz)
t = strndupa(t, last_space - t);
shared->return_value = parse_timestamp_impl(t, &shared->usec, with_tz);
_exit(EXIT_SUCCESS);
}