How to make emacs stop trying to load /home/sb/.emacs after su to root?

classic Classic list List threaded Threaded
20 messages Options
Reply | Threaded
Open this post in threaded view
|

How to make emacs stop trying to load /home/sb/.emacs after su to root?

Steinar Bang
 debian 10.0 "buster", amd64
 emacs 26.1

I do /bin/su to change the user to root.
HOME is set to /root

However emacs still tries to load /home/sb/.emacs

How can I make emacs stop loading the original user's .emacs when logged
in as root?

Thanks!


- Steinar

Reply | Threaded
Open this post in threaded view
|

Re: How to make emacs stop trying to load /home/sb/.emacs after su to root?

Stefan Monnier
Hi Steinar,

>  debian 10.0 "buster", amd64
>  emacs 26.1
>
> I do /bin/su to change the user to root.
> HOME is set to /root

Good.

> However Emacs still tries to load /home/sb/.emacs

Weird.
I suggest you file a bug report.


        Stefan


Reply | Threaded
Open this post in threaded view
|

Re: How to make emacs stop trying to load /home/sb/.emacs after su to root?

Perry Smith-2
In reply to this post by Steinar Bang

> On Jul 8, 2019, at 5:16 PM, Steinar Bang <[hidden email]> wrote:
>
> debian 10.0 "buster", amd64
> emacs 26.1
>
> I do /bin/su to change the user to root.
> HOME is set to /root
>
> However emacs still tries to load /home/sb/.emacs
>
> How can I make emacs stop loading the original user's .emacs when logged
> in as root?

Can you do “id” after you do the su?  Usually “su - root” is the suggested method.
The ‘-‘ causes the users environment to get loaded or something.  Never looked
too deep into it.

I suspect one of your uid’s is not root… euid, ruid, etc. and emacs is doing
some type of get user attributes and its returning the real user’s home rather
than the effective user’s home.



Reply | Threaded
Open this post in threaded view
|

Re: How to make emacs stop trying to load /home/sb/.emacs after su to root?

Tomas Nordin-2
Perry Smith <[hidden email]> writes:

>> On Jul 8, 2019, at 5:16 PM, Steinar Bang <[hidden email]> wrote:
>>
>> debian 10.0 "buster", amd64
>> emacs 26.1

Same here but emacs 27.

>>
>> I do /bin/su to change the user to root. HOME is set to /root
>>
>> However emacs still tries to load /home/sb/.emacs

I had the same happen here.

>>
>> How can I make emacs stop loading the original user's .emacs when
>> logged in as root?
>
> Can you do “id” after you do the su?  Usually “su - root” is the suggested method.
> The ‘-‘ causes the users environment to get loaded or something.  Never looked
> too deep into it.

After su;

# id
uid=0(root) gid=0(root) groups=0(root)

After su - root;

# id
uid=0(root) gid=0(root) groups=0(root)

but after this latter way of getting root emacs did not try to load
/home/tomas/.emacs

Just metooing

Best regards
--
Tomas

Reply | Threaded
Open this post in threaded view
|

Re: How to make emacs stop trying to load /home/sb/.emacs after su to root?

Tomas Zerolo
On Tue, Jul 09, 2019 at 09:00:11PM +0200, Tomas Nordin wrote:
> Perry Smith <[hidden email]> writes:

[...]

> >> How can I make emacs stop loading the original user's .emacs when
> >> logged in as root?
> >
> > Can you do “id” after you do the su?  Usually “su - root” is the suggested method.
> > The ‘-‘ causes the users environment to get loaded or something.  Never looked
> > too deep into it.
>
> After su;
>
> # id
> uid=0(root) gid=0(root) groups=0(root)
>
> After su - root;
>
> # id
> uid=0(root) gid=0(root) groups=0(root)
>
> but after this latter way of getting root emacs did not try to load
> /home/tomas/.emacs
>
> Just metooing
Have you checked the environment? What does $HOME say? (although the
"su -" part lets one expect that the HOME var is set anew: checking
won't hurt :-)

Cheers
-- t

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to make emacs stop trying to load /home/sb/.emacs after su to root?

Tomas Nordin-2
[hidden email] writes:

> On Tue, Jul 09, 2019 at 09:00:11PM +0200, Tomas Nordin wrote:
>> Perry Smith <[hidden email]> writes:
>
> [...]
>
>> >> How can I make emacs stop loading the original user's .emacs when
>> >> logged in as root?
>> >
>> > Can you do “id” after you do the su?  Usually “su - root” is the suggested method.
>> > The ‘-‘ causes the users environment to get loaded or something.  Never looked
>> > too deep into it.
>>
>> After su;
>>
>> # id
>> uid=0(root) gid=0(root) groups=0(root)
>>
>> After su - root;
>>
>> # id
>> uid=0(root) gid=0(root) groups=0(root)
>>
>> but after this latter way of getting root emacs did not try to load
>> /home/tomas/.emacs
>>
>> Just metooing
>
> Have you checked the environment? What does $HOME say? (although the
> "su -" part lets one expect that the HOME var is set anew: checking
> won't hurt :-)

echo $HOME gave /root after both su methods

>
> Cheers
> -- t

Reply | Threaded
Open this post in threaded view
|

Re: How to make emacs stop trying to load /home/sb/.emacs after su to root?

Tomas Zerolo
On Tue, Jul 09, 2019 at 10:04:20PM +0200, Tomas Nordin wrote:

> [hidden email] writes:
>
> > On Tue, Jul 09, 2019 at 09:00:11PM +0200, Tomas Nordin wrote:
> >> Perry Smith <[hidden email]> writes:
> >
> > [...]
> >
> >> >> How can I make emacs stop loading the original user's .emacs when
> >> >> logged in as root?
> >> >
> >> > Can you do “id” after you do the su?  Usually “su - root” is the suggested method.
> >> > The ‘-‘ causes the users environment to get loaded or something.  Never looked
> >> > too deep into it.
> >>
> >> After su;
> >>
> >> # id
> >> uid=0(root) gid=0(root) groups=0(root)
> >>
> >> After su - root;
> >>
> >> # id
> >> uid=0(root) gid=0(root) groups=0(root)
> >>
> >> but after this latter way of getting root emacs did not try to load
> >> /home/tomas/.emacs
> >>
> >> Just metooing
> >
> > Have you checked the environment? What does $HOME say? (although the
> > "su -" part lets one expect that the HOME var is set anew: checking
> > won't hurt :-)
>
> echo $HOME gave /root after both su methods
Hm. Was somewhat to be expected. Still... bizarre. You could try to
compare the result of "set" (displays the whole environment) after
both "su" variants: perhaps you find an environment variable which
could explain this behaviour. As a guide you can look up the env
variables relevant to Emacs in the manual; online here [1] [2].

But we don't know (yet) whether an env variable is the culprit
(although it seems compelling...)

Cheers

[1] https://www.gnu.org/software/emacs/manual/html_node/emacs/General-Variables.html#General-Variables
[2] https://www.gnu.org/software/emacs/manual/html_node/emacs/Misc-Variables.html#Misc-Variables

-- t

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to make emacs stop trying to load /home/sb/.emacs after su to root?

Nick Dokos-3
[hidden email] writes:

> ...
> But we don't know (yet) whether an env variable is the culprit
> (although it seems compelling...)
>

man su says:

       For  backward  compatibility,  su  defaults to not change the current directory and to
       only set the environment variables HOME and SHELL (/plus USER and LOGNAME if the target
       user is not root/).  It is recommended to always use the --login option (instead of its
       shortcut -) to avoid side effects caused by mixing environments.

[emphasis added].

That might have something to do with it. What happens with ~ might also
matter. How does emacs find the init file?

--
Nick

"There are only two hard problems in computer science: cache
invalidation, naming things, and off-by-one errors." -Martin Fowler


Reply | Threaded
Open this post in threaded view
|

Re: How to make emacs stop trying to load /home/sb/.emacs after su to root?

Steinar Bang
In reply to this post by Stefan Monnier
>>>>> Stefan Monnier <[hidden email]>:

> I suggest you file a bug report.

Tried to.  But it was appearently resolved as won't-fix:
 https://debbugs.gnu.org/db/36/36583.html

Not a very friendly and helpful response on the resolve, I might note.

(I didn't get any acknowledgement for this bug report and didn't find
anything on the first search, so I reported another today, and didn't
see the response until I found a better way to search for the new bug)


Reply | Threaded
Open this post in threaded view
|

Re: How to make emacs stop trying to load /home/sb/.emacs after su to root?

Steinar Bang
>>>>> Steinar Bang <[hidden email]>:

>>>>> Stefan Monnier <[hidden email]>:
>> I suggest you file a bug report.

> Tried to.  But it was appearently resolved as won't-fix:
>  https://debbugs.gnu.org/db/36/36583.html

> Not a very friendly and helpful response on the resolve, I might note.

Google was more helpful:
 https://www.gnu.org/software/emacs/manual/html_node/emacs/Find-Init.html#Find-Init

"However, if you run Emacs from a shell started by su, Emacs tries to
 find your own .emacs, not that of the user you are currently pretending
 to be. The idea is that you should get your own editor customizations
 even if you are running as the super user."

Hm... this is annoying and new behaviour with emacs 26.

Does anyone know if there is a way to get the emacs 25 behaviour back...?


- Steinar

Reply | Threaded
Open this post in threaded view
|

Re: How to make emacs stop trying to load /home/sb/.emacs after su to root?

Steinar Bang
>>>>> Steinar Bang <[hidden email]>:

>  https://www.gnu.org/software/emacs/manual/html_node/emacs/Find-Init.html#Find-Init

> "However, if you run Emacs from a shell started by su, Emacs tries to
>  find your own .emacs, not that of the user you are currently pretending
>  to be. The idea is that you should get your own editor customizations
>  even if you are running as the super user."

> Hm... this is annoying and new behaviour with emacs 26.

> Does anyone know if there is a way to get the emacs 25 behaviour back...?

I've been looking at the code in startup.el but I haven't been able to
determine where the cause of the new behaviour is.

Is it somewhere in startup--load-user-init-file ?

(I figure that if I can look at the code doing it, I can find a way to
undo it... this is emacs, after all...:-) )

Reply | Threaded
Open this post in threaded view
|

Re: How to make emacs stop trying to load /home/sb/.emacs after su to root?

Steinar Bang
>>>>> Steinar Bang <[hidden email]>:

>> https://www.gnu.org/software/emacs/manual/html_node/emacs/Find-Init.html#Find-Init

>> "However, if you run Emacs from a shell started by su, Emacs tries to
>> find your own .emacs, not that of the user you are currently pretending
>> to be. The idea is that you should get your own editor customizations
>> even if you are running as the super user."

>> Hm... this is annoying and new behaviour with emacs 26.

>> Does anyone know if there is a way to get the emacs 25 behaviour back...?

> I've been looking at the code in startup.el but I haven't been able to
> determine where the cause of the new behaviour is.

> Is it somewhere in startup--load-user-init-file ?

It has to be the function find-init-path, I think...?

So, the culprit is whatever sets init-file-user (that find-init-path
uses)...?

Let me see:
 If I do a plain su, then init-file-user is "sb"

 If I do "/bin/su - root" then init-file-user is ""

But there may not be an easy way to undo this behaviour by setting
init-file-user, because by its nature this variable is used before any
init files are loaded... hm.

Reply | Threaded
Open this post in threaded view
|

Re: How to make emacs stop trying to load /home/sb/.emacs after su to root?

Steinar Bang
>>>>> Steinar Bang <[hidden email]>:

> But there may not be an easy way to undo this behaviour by setting
> init-file-user, because by its nature this variable is used before any
> init files are loaded... hm.

Hm... looks like the only way to fix this is to hack the C code and
start using my own fork of emacs.

A bit on the drastic side to fix what is in the large scheme of things,
a minor annoyance.

I'll think about what to do when I calm down. :-)


Reply | Threaded
Open this post in threaded view
|

Re: How to make emacs stop trying to load /home/sb/.emacs after su to root?

Perry Smith-2
In reply to this post by Steinar Bang


> On Jul 11, 2019, at 1:09 PM, Steinar Bang <[hidden email]> wrote:
>
> Google was more helpful:
> https://www.gnu.org/software/emacs/manual/html_node/emacs/Find-Init.html#Find-Init
From your reference:

More precisely, Emacs first determines which user's init file to use. It gets your user name from the environment variables LOGNAME andUSER; if neither of those exists, it uses effective user-ID. If that user name matches the real user-ID, then Emacs uses HOME; otherwise, it looks up the home directory corresponding to that user name in the system's data base of users.

Is USER or LOGNAME set?  If not, would setting one of those be easier?

You said this is new behavior.  Are you sure of that?  The page your reference seems all perfectly normal way things work.

Last, in another email you said that if you “su - root”, then it is set to “”.  That seems weird too.  Is that before ~root/.emacs.el et. al. doesn’t exist?

pedz



Reply | Threaded
Open this post in threaded view
|

Re: How to make emacs stop trying to load /home/sb/.emacs after su to root?

Steinar Bang
>>>>> Perry Smith <[hidden email]>:

> You said this is new behavior.  Are you sure of that?

Compared to emacs 25 on debian 9.9, this is new behaviour.

I'm sure of this because I have a computer still debian 9.9 and mosh in
and /bin/su and then start emacs is something I do a lot, and I did that
in a different window at the same time as I had the issues on debian 10.

I don't think this is something the debian maintainers have changed.

(and no, it doesn't have anything to do with mosh. It works the same way
with SSH. I can't try on the console, because it's a VPS without a
console )

And the difference is more drastic than it would appear to be, because
emacs loads the .emacs file in my home directory, and then fails
miserably because that confif files expects a lot of emacs packages that
emacs is unable to find (ie. it does not use the packages under the
original user, ie. ~sb/.emacs.d/elpa/ ).

So... the resulting emacs starts up in a broken middle-of-configuration
state.  It does not have my own user's complete configuration.  And it
does not have user root's perfectly valid (but far less extensive)
configuration (it mainly configures stuff that annoys me, such as the
default of splitting windows vertically).

> The page your reference seems all perfectly normal way things work.

Actually it doesn't work (see the above paragraphs).

Of course I can *make* it work by typing "/bin/su - root" instead of
"/bin/su", but the need to do so... annoys me deeply.

> Last, in another email you said that if you “su - root”, then it is
> set to “”.  That seems weird too.  Is that before ~root/.emacs.el
> et. al. doesn’t exist?

I don't understand the question...?

~sb/.emacs exists
~root/.emacs also exists (but is far less extensive than ~sb/.emacs)

(and they both exists both before and after emacs is started... have
existed for years, in fact...)

Reply | Threaded
Open this post in threaded view
|

Re: How to make emacs stop trying to load /home/sb/.emacs after su to root?

Stefan Monnier
>> You said this is new behavior.  Are you sure of that?
> Compared to emacs 25 on debian 9.9, this is new behaviour.

I can't find any relevant change in Emacs in that timeframe.
OTOH it seems that the `su` that comes with Debian may have changed
between Debian 9 and Debian 10 (tho whether you see the change or not
might depend on whether you did an upgrade or a fresh install).

https://wiki.debian.org/NewInBuster says:

    The `su` command in buster is provided by the `util-linux` source
    package, instead of the `shadow` source package, and no longer alters
    the `PATH` variable by default.

the change mentioned doesn't explain the difference you're seeing, but
maybe this other `su` has other changes (w.r.t $LOGNAME and $USER)
which do.


        Stefan "who always uses `su -`"


Reply | Threaded
Open this post in threaded view
|

Re: How to make emacs stop trying to load /home/sb/.emacs after su to root?

Steinar Bang
>>>>> Stefan Monnier <[hidden email]>:

> I can't find any relevant change in Emacs in that timeframe.
> OTOH it seems that the `su` that comes with Debian may have changed

Hm... so I may have been barking up the wrong tree...?

> between Debian 9 and Debian 10 (tho whether you see the change or not
> might depend on whether you did an upgrade or a fresh install).

> https://wiki.debian.org/NewInBuster says:

>     The `su` command in buster is provided by the `util-linux` source
>     package, instead of the `shadow` source package, and no longer alters
>     the `PATH` variable by default.

(I didn't even think about su changing.  It's so basic, it's just part
of the background)

> the change mentioned doesn't explain the difference you're seeing, but
> maybe this other `su` has other changes (w.r.t $LOGNAME and $USER)
> which do.

Thanks for the pointer.  I will dig down and report back.

>         Stefan "who always uses `su -`"

Ah well... old habits are so hard to break. :-)

Thanks!

Reply | Threaded
Open this post in threaded view
|

Re: How to make emacs stop trying to load /home/sb/.emacs after su to root?

Steinar Bang
>>>>> Steinar Bang <[hidden email]>:

>>>>> Stefan Monnier <[hidden email]>:
>> I can't find any relevant change in Emacs in that timeframe.
>> OTOH it seems that the `su` that comes with Debian may have changed

> Hm... so I may have been barking up the wrong tree...?

However, there is something that I would say actually is a bug, ie. this
bit, quoted from an earlier message:

>> And the difference is more drastic than it would appear to be, because
>> emacs loads the .emacs file in my home directory, and then fails
>> miserably because that confif files expects a lot of emacs packages that
>> emacs is unable to find (ie. it does not use the packages under the
>> original user, ie. ~sb/.emacs.d/elpa/ ).

IMO If emacs decides to load the .emacs from a different place, it
should also load all user specific config from that place (~/.emacs.d/
.gnus.el whatever).

(If emacs had loaded all of its config files from the same place it
loaded .emacs, I would never have noticed any breakage and would have
happily used my native emacs config as root)

Reply | Threaded
Open this post in threaded view
|

Re: How to make emacs stop trying to load /home/sb/.emacs after su to root?

Perry Smith-2
In reply to this post by Steinar Bang

> On Jul 12, 2019, at 4:41 PM, Steinar Bang <[hidden email]> wrote:
>
>>        Stefan "who always uses `su -`"
>
> Ah well... old habits are so hard to break. :-)

Just trying to help …

You could alias su.  Personally I find aliases have problems.  So, what I find better are small trivial functions (assuming you are using bash/ksh/…) that changes the command you like to type into the command that “works” (by your definition of “works”)

Reply | Threaded
Open this post in threaded view
|

Re: How to make emacs stop trying to load /home/sb/.emacs after su to root?

Steinar Bang
>>>>> Perry Smith <[hidden email]>:

> You could alias su.  Personally I find aliases have problems.  So,
> what I find better are small trivial functions (assuming you are using
> bash/ksh/…) that changes the command you like to type into the command
> that “works” (by your definition of “works”)

Thanks!

My definition of "works" is "starting up without an error message
because emacs can't find all of the things referred to in the .emacs
file picked by emacs". :-)