Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on linux if TZ env var set and starts with ':', use as timezone #144

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/tz_linux.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
use std::fs::{read_link, read_to_string};

pub(crate) fn get_timezone_inner() -> Result<String, crate::GetTimezoneError> {
if let Some(tz) = std::env::var_os("TZ") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that env::var_os is due to be made unsafe in Rust 2024, I'm not comfortable with this. If we do support reading from the TX env var, I'd rather it be gated by a feature and exposed via a new entry point.

At least in Artichoke, I'd not use this as is since my application must run its own hooks on env accesses and e.g. allow disabling all env accesses via a feature for sandboxing.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd make the same argument. Interacting with environment variables is IMHO out-of-scope of this library.

match tz.into_string() {
Ok(mut tz) => {
if tz.starts_with(":") {
return Ok(tz.split_off(1));
}
}
Err(_) => { /* not UTF-8, ignore TZ env var */ }
}
}

etc_localtime()
.or_else(|_| etc_timezone())
.or_else(|_| openwrt::etc_config_system())
Expand Down
Loading