-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
Description
I saw os.homedir()
is directly using uv_os_homedir
and it has an strange feature.
See here for the feature.
It will check the environment variable first and then check for the real home directory.
And someone discussed here for the reason.
I wonder if this should check $HOME first? It's something of a UNIX tradition to be able to change your home directory on the fly. A problem with that is that getenv("HOME") is not MT-safe.
-- @bnoordhuis
But I think there's still a problem.
Consider one situation:
If I wrote a CLI program and it will write some log file on user's home directory.
Now I run the CLI like this:
$ sudo -u foo node mycli.jsIt should write log file on
/home/foo
. But the problem is -os.homedir()
still gotprocess.env.HOME
.
One solution is to edit /etc/sudoers
:
# env_keep+="HOME MAIL"
# comment env_keep += "HOME"
And another method is using -i
argument.
_For further reading you can go to this article. (It was written in Chinese by @Amunu)_
But I think why don't we wrote a os.realHomedir()
or removing checking HOME
in realhomedir()
? Not all of us (normal developers) have the permission to access configuration files on our online servers.