const char *last_space;
last_space = strrchr(p, ' ');
- if (last_space != NULL && timezone_is_valid(last_space + 1)) {
+ if (last_space != NULL && timezone_is_valid(last_space + 1, LOG_DEBUG)) {
c->timezone = strdup(last_space + 1);
if (!c->timezone)
return -ENOMEM;
int r;
last_space = strrchr(t, ' ');
- if (last_space != NULL && timezone_is_valid(last_space + 1))
+ if (last_space != NULL && timezone_is_valid(last_space + 1, LOG_DEBUG))
tz = last_space + 1;
if (!tz || endswith_no_case(t, " UTC"))
return 0;
}
-bool timezone_is_valid(const char *name) {
+bool timezone_is_valid(const char *name, int log_level) {
bool slash = false;
const char *p, *t;
_cleanup_close_ int fd = -1;
fd = open(t, O_RDONLY|O_CLOEXEC);
if (fd < 0) {
- log_debug_errno(errno, "Failed to open timezone file '%s': %m", t);
+ log_full_errno(log_level, errno, "Failed to open timezone file '%s': %m", t);
return false;
}
r = fd_verify_regular(fd);
if (r < 0) {
- log_debug_errno(r, "Timezone file '%s' is not a regular file: %m", t);
+ log_full_errno(log_level, r, "Timezone file '%s' is not a regular file: %m", t);
return false;
}
r = loop_read_exact(fd, buf, 4, false);
if (r < 0) {
- log_debug_errno(r, "Failed to read from timezone file '%s': %m", t);
+ log_full_errno(log_level, r, "Failed to read from timezone file '%s': %m", t);
return false;
}
/* Magic from tzfile(5) */
if (memcmp(buf, "TZif", 4) != 0) {
- log_debug("Timezone file '%s' has wrong magic bytes", t);
+ log_full(log_level, "Timezone file '%s' has wrong magic bytes", t);
return false;
}
if (!e)
return -EINVAL;
- if (!timezone_is_valid(e))
+ if (!timezone_is_valid(e, LOG_DEBUG))
return -EINVAL;
z = strdup(e);
bool ntp_synced(void);
int get_timezones(char ***l);
-bool timezone_is_valid(const char *name);
+bool timezone_is_valid(const char *name, int log_level);
bool clock_boottime_supported(void);
bool clock_supported(clockid_t clock);
return 0;
}
+static bool timezone_is_valid_log_error(const char *name) {
+ return timezone_is_valid(name, LOG_ERR);
+}
+
static int prompt_timezone(void) {
_cleanup_strv_free_ char **zones = NULL;
int r;
putchar('\n');
- r = prompt_loop("Please enter timezone name or number", zones, timezone_is_valid, &arg_timezone);
+ r = prompt_loop("Please enter timezone name or number", zones, timezone_is_valid_log_error, &arg_timezone);
if (r < 0)
return r;
break;
case ARG_TIMEZONE:
- if (!timezone_is_valid(optarg)) {
+ if (!timezone_is_valid(optarg, LOG_ERR)) {
log_error("Timezone %s is not valid.", optarg);
return -EINVAL;
}
return 0;
}
- if (!timezone_is_valid(tz)) {
+ if (!timezone_is_valid(tz, LOG_DEBUG)) {
log_debug_errno(r, "Timezone is not valid, ignoring: %m");
return 0;
}
int r;
assert_return(server, -EINVAL);
- assert_return(timezone_is_valid(tz), -EINVAL);
+ assert_return(timezone_is_valid(tz, LOG_DEBUG), -EINVAL);
if (streq_ptr(tz, server->timezone))
return 0;
if (r < 0)
return r;
- if (!timezone_is_valid(tz)) {
+ if (!timezone_is_valid(tz, LOG_ERR)) {
log_syntax(unit, LOG_ERR, filename, line, 0, "Timezone is not valid, ignoring assignment: %s", rvalue);
free(tz);
return 0;
}
static void test_timezone_is_valid(void) {
- assert_se(timezone_is_valid("Europe/Berlin"));
- assert_se(timezone_is_valid("Australia/Sydney"));
- assert_se(!timezone_is_valid("Europe/Do not exist"));
+ assert_se(timezone_is_valid("Europe/Berlin", LOG_ERR));
+ assert_se(timezone_is_valid("Australia/Sydney", LOG_ERR));
+ assert_se(!timezone_is_valid("Europe/Do not exist", LOG_ERR));
}
static void test_get_timezones(void) {
assert_se(r == 0);
STRV_FOREACH(zone, zones)
- assert_se(timezone_is_valid(*zone));
+ assert_se(timezone_is_valid(*zone, LOG_ERR));
}
static void test_usec_add(void) {
if (r < 0)
return r;
- if (!timezone_is_valid(z))
+ if (!timezone_is_valid(z, LOG_DEBUG))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid time zone '%s'", z);
r = free_and_strdup(&c->zone, z);