Hi Ken,

> > What's the intent of an empty HOME?
> > Is it set by accident when it's meant to be unset?
> > Is it empty by accident when it's meant to be non-empty?
> > Do they want HOME=/, HOME=$PWD, or are they expecting it to error.
> > Any choice could be not what the user intended so exit.
>
> I mean ... you could say the exact same things of an unset HOME!

No, one cannot say of an unset HOME that it may be set by accident.
Nor that it is empty by accident since it is neither empty or non-empty.
This being Unix, the user knows what they're doing and POSIX seemingly
allows it so we permit the lack of HOME and use pw_dir.
There is no ambiguity over the right course.
As is often the way with an environment variable, HOME overrides pw_dir
just as an argv option overrides an environment variable which overrides
a configuration-file setting.

But if HOME is empty we do not know their intent so to ignore it and use
pw_dir may not be what they think will occur.  The wrong profile could
be read or the wrong .netrc used, upsetting the user.

> My point is that I cannot see a reason to treat unset HOME and empty
> HOME differently in nmh; if unset HOME uses pw_dir, then I would argue
> that an empty HOME should do the same thing.

I disagree.  In the same way that seeing ${foo:-bar} instead of
${foo:bar} in sh is a smell.

> I was curious and some system call traces suggest that what happens
> under the hood is that when 'cd' is called with an empty HOME sh
> explicitly calls chdir(getcwd()).

Sometimes.  I think it's more complex than that, e.g. perhaps PWD has
an effect, and it will obviously vary widely.

    $ LC_ALL=C env HOME= PWD=/nonexist strace -fe getcwd,stat,chdir dash -c cd
    stat("/nonexist", 0x7ffc101d1bb0)       = -1 ENOENT (No such file or 
directory)
    getcwd("/home/tmp/1628693513.257008819", 4096) = 31
    chdir("/home/tmp/1628693513.257008819") = 0
    +++ exited with 0 +++
    $
    $ LC_ALL=C env HOME= PWD=$PWD strace -fe getcwd,stat,chdir dash -c cd
    stat("/home/tmp/1628693513.257008819", {st_mode=S_IFDIR|0755, st_size=4096, 
...}) = 0
    stat(".", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
    chdir("/home/tmp/1628693513.257008819") = 0
    +++ exited with 0 +++
    $
    $ LC_ALL=C env -u PWD HOME= strace -fe getcwd,stat,chdir dash -c cd
    getcwd("/home/tmp/1628693513.257008819", 4096) = 31
    chdir("/home/tmp/1628693513.257008819") = 0
    +++ exited with 0 +++
    $

-- 
Cheers, Ralph.

Reply via email to