Sys.timezone() fails on Linux under Microsoft WSL

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Sys.timezone() fails on Linux under Microsoft WSL

Brenton Wiernik
In Microsoft’s Windows Subsystem for Linux (WSL or WSL2), there is not system framework, so utilities that depend on it fail. This includes timedatectl which R uses in Sys.timezone(). The timedatectl utility is present on Linux systems installed under WSL/WSL2, but is non-functional. So, when Sys.timezone() checks for Sys.which("timedatectl"), it receives a false positive. The subsequent methods after this if () do work, however.

This can be fixed if line 42 of Sys.timezone() were changed from:
if (nzchar(Sys.which("timedatectl"))) {

to:
if (nzchar(Sys.which("timedatectl")) && !grepl("microsoft", system("uname -r", intern = TRUE), ignore.case = TRUE)) {

"uname -r" returns for example:
"5.4.72-microsoft-standard-WSL2"

So checking for "microsoft" or "WSL" would probably work.


Brenton Wiernik



        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Sys.timezone() fails on Linux under Microsoft WSL

Martin Maechler
>>>>> Brenton Wiernik
>>>>>     on Tue, 13 Apr 2021 09:15:50 -0400 writes:

    > In Microsoft’s Windows Subsystem for Linux (WSL or WSL2),
    > there is not system framework, so utilities that depend on
    > it fail. This includes timedatectl which R uses in
    > Sys.timezone(). The timedatectl utility is present on
    > Linux systems installed under WSL/WSL2, but is
    > non-functional. So, when Sys.timezone() checks for
    > Sys.which("timedatectl"), it receives a false
    > positive. The subsequent methods after this if () do work,
    > however.

    > This can be fixed if line 42 of Sys.timezone() were changed from:

    > if (nzchar(Sys.which("timedatectl"))) {

    > to:

    > if (nzchar(Sys.which("timedatectl")) && !grepl("microsoft", system("uname -r", intern = TRUE), ignore.case = TRUE)) {

    > "uname -r" returns for example:  "5.4.72-microsoft-standard-WSL2"

    > So checking for "microsoft" or "WSL" would probably work.

    > Brenton Wiernik

Thank you.  This all makes sense.
However,  using system("uname -r")  creates another platform
dependency (it fails, i.e., signals an error, e.g., on our Windows Server).

Could  Sys.info()  be used instead?
What does it give on your platform?



    > [[alternative HTML version deleted]]

    > ______________________________________________
    > [hidden email] mailing list
    > https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Sys.timezone() fails on Linux under Microsoft WSL

Brenton Wiernik
That would work.

Sys.info()['release']
#                          release
# "5.4.72-microsoft-standard-WSL2"

Brenton


From: Martin Maechler
Sent: Wednesday, April 14, 2021 03:28
To: Brenton Wiernik
Cc: [hidden email]
Subject: Re: [Rd] Sys.timezone() fails on Linux under Microsoft WSL

>>>>> Brenton Wiernik
>>>>>     on Tue, 13 Apr 2021 09:15:50 -0400 writes:

    > In Microsoft’s Windows Subsystem for Linux (WSL or WSL2),
    > there is not system framework, so utilities that depend on
    > it fail. This includes timedatectl which R uses in
    > Sys.timezone(). The timedatectl utility is present on
    > Linux systems installed under WSL/WSL2, but is
    > non-functional. So, when Sys.timezone() checks for
    > Sys.which("timedatectl"), it receives a false
    > positive. The subsequent methods after this if () do work,
    > however.

    > This can be fixed if line 42 of Sys.timezone() were changed from:

    > if (nzchar(Sys.which("timedatectl"))) {

    > to:

    > if (nzchar(Sys.which("timedatectl")) && !grepl("microsoft", system("uname -r", intern = TRUE), ignore.case = TRUE)) {

    > "uname -r" returns for example:  "5.4.72-microsoft-standard-WSL2"

    > So checking for "microsoft" or "WSL" would probably work.

    > Brenton Wiernik

Thank you.  This all makes sense.
However,  using system("uname -r")  creates another platform
dependency (it fails, i.e., signals an error, e.g., on our Windows Server).

Could  Sys.info()  be used instead?
What does it give on your platform?



    > [[alternative HTML version deleted]]

    > ______________________________________________
    > [hidden email] mailing list
    > https://stat.ethz.ch/mailman/listinfo/r-devel


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Sys.timezone() fails on Linux under Microsoft WSL

Jim Hester
In reply to this post by Brenton Wiernik
One way to avoid the call to timedatectl is to set the `TZ` environment
variable on your machine to your local timezone, if this is set
`Sys.timezone()` uses this and does not try to query timedatectl for the
timezone.

This is a common issue as well in docker containers, as like on WSL in
docker timedatectl is present, but non-functional.

Jim

On Tue, Apr 13, 2021 at 9:19 AM Brenton Wiernik <[hidden email]> wrote:

> In Microsoft’s Windows Subsystem for Linux (WSL or WSL2), there is not
> system framework, so utilities that depend on it fail. This includes
> timedatectl which R uses in Sys.timezone(). The timedatectl utility is
> present on Linux systems installed under WSL/WSL2, but is non-functional.
> So, when Sys.timezone() checks for Sys.which("timedatectl"), it receives a
> false positive. The subsequent methods after this if () do work, however.
>
> This can be fixed if line 42 of Sys.timezone() were changed from:
> if (nzchar(Sys.which("timedatectl"))) {
>
> to:
> if (nzchar(Sys.which("timedatectl")) && !grepl("microsoft", system("uname
> -r", intern = TRUE), ignore.case = TRUE)) {
>
> "uname -r" returns for example:
> "5.4.72-microsoft-standard-WSL2"
>
> So checking for "microsoft" or "WSL" would probably work.
>
>
> Brenton Wiernik
>
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel