Subject: bug#47298: Emacs creates HOME if it does not exist

From: Jean Louis <[email-masked]>
Date: Fri, 26 Mar 2021 12:18:20 +0300

* Glenn Morris <[email-masked]> [2021-03-25 21:29]:
> Eli Zaretskii wrote:
> 
> >> From: Glenn Morris <[email-masked]>
> >> Date: Sun, 21 Mar 2021 13:40:53 -0400
> >> 
> >> IMO the Emacs 26.3 behaviour is correct, and Emacs should not be
> >> creating HOME if it does not exist.
> >
> > I'm not sure I agree with you.  What do other programs do in this
> > situation?
> 
> Dunno.
> IMO applications should not be creating HOME, that is a system-level
> responsibility.

Emacs also does not create home directly, it creates its own
configuration directory appended to environment variable $HOME --
which in most cases is home directory of a user, but may not be. Home
directory of a user is located in /etc/passwd and $HOME is
customization that users still can do for other purpose.

If Emacs does not touch /etc/passwd or look for user's home there,
then is not creating user's home, it is creating its configuration
directory as appended to environment variable $HOME -- and other
applications do exactly the same!

Plethora of applications are creating their configurations in
~/.config -- so please look there, you will find all created
directories. 

Applications are then probably finding where is the config directory
by deriving it from $HOME environment variable or $XDG_CONFIG_HOME and
when $XDG_CONFIG_HOME is not there it is derived maybe from
XDG_CONFIG_HOME="$HOME/.config"

> Missing HOME indicates either a deliberate choice, or a system-level
> problem that the application should not try to fix (in most cases, it
> won't even have permission to do so) but should just report.

When application like Emacs runs, it does not "create home" as above
explained, but it wants to create its directory for future
functionality. Using $HOME environment variable is not same as user's
home directory, which is defined in /etc/passwd and need not be
defined in $HOME automatically -- though that is what systems do for
convenience.

I can enter in the system at /root point, it does not matter, $HOME is
where I have permission and my files. 

> > And if we don't create ~/.emacs.d, how can we save user's
> > customizations?
> 
> You don't, you give a warning.

Your assumption that Emacs changes or fiddles with user's home is
incorrect. It works (probably, me insecure) with $HOME variable which
is not equal to user's home, which is irrelevant to user's home
directory! 

I don't agree with this quite, as I use Emacs on Lineage OS, Android
OS, there are setups you do not know, and where this statement does
not apply. In fact there is no specific user's directory on such
systems and it depends of the access:

On the same system:

$ adb shell (but I am not root)
condor:/ $ echo $HOME
/

and I have no permissions to write in that directory, obviously it is
not real home, but I have $HOME.

Then different SSH application would give me different $HOME.

$ ssh motorolausb
$ echo $HOME
/data/data/com.termux/files/home

which is inconvenient, so I like changing $HOME variable to
/storage/emulated/0 as that is where Pictures, and Videos are located
as well, makes more sense to me.

> > That might mean we need to find other ways of isolating tests from
> > user customizations.
> 
> Your only alternative is to have the test machinery make a temporary but
> existing HOME and ensure it is deleted afterwards.
> But IMO that is a separate issue.
> Even if that change is made, I still don't believe Emacs should create HOME.

I think it should as all other applications follow that. Creating
$HOME is not same as creating user's home directory as specified in
/etc/passwd -- while similar, those things are not same, I have given
you example from Lineage OS system.

If the configuration directory cannot be created, no warning should be
issued as user is invoking Emacs most probably to edit text and there
is no need to confuse editing with configuration.

When configuration cannot be saved because the directory could not be
created, at the time point of not being able to save configuration,
that is where warning should be issued.

Jean