You are not logged in.

#1 2020-01-11 01:49:31

wpkzz
Member
Registered: 2020-01-10
Posts: 43

emacs run as root insists on using user config file

I am not sure if this is an Arch Issue, but with other distros I never have seen this behavior.

I start my user session in Arch and startx. I open some terminals and to do some administrative tasks in one of them I start a root shell by "su".
Then I want to edit some config files and I call emacs on this terminal. Emacs then tries to use my user configuration file, and, then complains by not finding the appropriate
color theme in the .emacs.d directory.  root doesn't have a .emacs.d directory, then it restores to other personalized color theme, which was also defined by my
personal user before the installation of the first one. Of course this comes with a bothersome emacs frame complaining about the problem.

The same home directory, when I was using another linux distro, didn't show this behavior. I had my color theme for emacs, and if root initated another instance of emacs
on my x11 session, it would use the default color theme without complain.

It is a minor nuisance but a curious one and I would like to understand its origin.

Thanks in advance.


Moyocoyani, Tloque Nahuaque.

Offline

#2 2020-01-11 01:58:37

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,739

Re: emacs run as root insists on using user config file

Interesting.  I can duplicate the behavior.   Running as sudo emacs, however, works as expected.

I tried from my user's home, and from /root.   

Did the 'other distro' use systemd-login?


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#3 2020-01-11 09:43:06

seth
Member
Registered: 2012-09-03
Posts: 49,981

Re: emacs run as root insists on using user config file

Some environment variable…


export FOO=BAR
su
echo $FOO
exit
sudo -i
echo $FOO

Sidenote: will you please use sudoedit and not run emacs (the tool traditionally being mocked as good OS which just lacks a decent text editor) out of all processes as root?

Edit: not, bbcode can't do that …

Last edited by seth (2020-01-11 09:43:55)

Offline

#4 2020-01-11 15:19:45

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,739

Re: emacs run as root insists on using user config file

seth wrote:

Sidenote: will you please use sudoedit and not run emacs (the tool traditionally being mocked as good OS which just lacks a decent text editor) out of all processes as root?

Of course, I recommend using tramp mode when there is a need to edit files with elevated permissions.  For example, visiting the file: /sudo:://etc/ will open a nice dired buffer in which you can see all the files in /etc, select them, and edit them with root permissions -- all while using a emacs session running as your user.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#5 2020-01-11 17:01:53

wpkzz
Member
Registered: 2020-01-10
Posts: 43

Re: emacs run as root insists on using user config file

Thanks, I did not now about "tramp mode", I'll research it and see what it is.

Well, seth, I have been using emacs for almost 16 years, and I really like its OS like behaviour, and for me is confortable enough. Sometimes the conf files are quite complicated and long, and other more simplistic tools don't make the nice things that emacs does. I shall make your experiment, (FOO was correctly exported to the su user, but I did not make the second half of the experiment as my user is not sudoer... yet).

Ah, yes, the "other distro" (it was gentoo) used init.d, not systemd.

Thanks


Moyocoyani, Tloque Nahuaque.

Offline

#6 2020-01-11 17:49:20

seth
Member
Registered: 2012-09-03
Posts: 49,981

Re: emacs run as root insists on using user config file

The point is more that it's too complex to be reasonably run as root - less https://xkcd.com/378/ or https://xkcd.com/1823/

I'm pretty sure about the su/sudo environment behavior, so my suggestion is actually to look which environment variable might influence this.

Offline

#7 2020-01-12 19:29:45

ronmon
Member
Registered: 2011-04-15
Posts: 48

Re: emacs run as root insists on using user config file

You might try "su -" instead of just "su". From the man page.

-, -l, --login
              Start the shell as a login shell with an environment similar to a real login:

                 o      clears all the environment variables except TERM and variables specified by --whitelist-environment

                 o      initializes the environment variables HOME, SHELL, USER, LOGNAME, and PATH

                 o      changes to the target user's home directory

                 o      sets argv[0] of the shell to '-' in order to make the shell a login shell

It will use all your config files from "/root", including .bashrc, .bash_profile, etc.

Offline

#8 2020-01-18 03:59:09

wpkzz
Member
Registered: 2020-01-10
Posts: 43

Re: emacs run as root insists on using user config file

Well, the ronmon answer is a stronger solution: in that way emacs doesn't even try to use x11 or anything, it just starts in the terminal. Which is slightly more to the point, but still different to what I used to like. I'll keep digging on the enviroment variables. It may be something with systemd vs init.d also....


Moyocoyani, Tloque Nahuaque.

Offline

#9 2020-01-18 08:54:05

seth
Member
Registered: 2012-09-03
Posts: 49,981

Re: emacs run as root insists on using user config file

You can unset the DISPLAY variable anytime and emacs for sure has an option to run in terminal mode despite a GUI server (because https://xkcd.com/378/ )
However:

seth wrote:

will you please use sudoedit and not run emacs (the tool traditionally being mocked as good OS which just lacks a decent text editor) out of all processes as root?

Offline

#10 2020-01-20 20:27:54

wpkzz
Member
Registered: 2020-01-10
Posts: 43

Re: emacs run as root insists on using user config file

Aaah... no, no. I shall keep using emacs, thank you. I guess we longtime gnulinux users are very opinionated, and I am allready very used to emacs for file editing. I know, I know... emacs is tooo much for simple config files editing. But sometimes in the past I have fought with complex files and emacs behaves nice with those.

Okey, I have to state what I had in mind or the thing that I was used to do:
When I ran emacs on the "other" distro as users I had my color scheme, in my x11 (fluxbox). If I did a "su" (root) sesion, started emacs, it started as gui window frame and all eye candy, also, but using the default (horrible) color scheme (red and white, reminds you of root at a glance). So I  could discern in a obvious way which emacs had the root powers and which not, and I could use all the emacs magic also between them. That was the default behavior on Gentoo, and I got used to it. I mean, I can learn new things, of course... but I would like to know exactly what is going on here and how different the users behave from Gentoo to Arch, which seem to be very similar distros in user-base and philosophy after all.


Moyocoyani, Tloque Nahuaque.

Offline

#11 2020-01-20 21:07:54

seth
Member
Registered: 2012-09-03
Posts: 49,981

Re: emacs run as root insists on using user config file

sudoedit will run your favorite editor ($EDITOR) with your UID on a temporary copy of the target file and then elevate to UID0 to only write it into the desired position.
You *will* be using emacs, but not as UID0 and still be able to edit files that require elevated (or different) permissions.

This is not a vim ./. emacs thing, but a "emacs is a fat and convoluted process that can be scripted to do virtually everything. don't run it as root" thing. I won't sugget to run vim as UID0 either (though it's not *as* fat as emacs ;-)

Offline

#12 2020-01-21 01:45:34

wpkzz
Member
Registered: 2020-01-10
Posts: 43

Re: emacs run as root insists on using user config file

Yep, seth, I got you. But my question has become something more general now, it seems... now I am intrigued on why on Gentoo emacs started on an graphical enviroment used one "profile" or configfile called by the user, and aparently restorted to default config for the root, but both of them with graphical candy and windows and the such. On the other hand on Arch it seems that the only options are going for the full user config file if called inside the user graphical session, no matter who calls it... or to get rid of the enviromental variables with "su -", and then to run inside the terminal, no eye candy whatsoever. Somewhere around must be a config spec that can be changed to do behave in one or the other way. The existence of that file is what is intriguing me now. By the way, I tried visudo which seems to operate similar to sudoedit, but of course i shall be using MY color theme instead of the OTHER one, ¿no? I know  that this is allready being a bit pettifogging, but I would like to know what is going on.
On the other hand, by the way, ¿where are the default EDITOR and such variables declared?


Moyocoyani, Tloque Nahuaque.

Offline

#13 2020-01-21 08:35:34

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,425

Re: emacs run as root insists on using user config file

As has been mentioned, read the environments before and after changing the user on Arch and on Gentoo. Everything here stands and falls with it. Make sure you didn't accidentally alias su on either system to something that would invoke this.

As for how and where they are set: https://wiki.archlinux.org/index.php/En … _variables

Last edited by V1del (2020-01-21 08:36:33)

Offline

Board footer

Powered by FluxBB