bakkeby / dwm-flexipatch

A dwm build with preprocessor directives to decide which patches to include during build time
MIT License
1.18k stars 238 forks source link

Program listed in autostart file starts as root user. #337

Open apoorv569 opened 1 year ago

apoorv569 commented 1 year ago

The autostart file under ~/.dwm/autostart.sh starts programs as root user which causes issues, sometimes the program reads wrong configuration file sometimes there are permission issues.

Is this normal behavior? Can I change this behavior?

bakkeby commented 1 year ago

What makes you think that the autostart file starts programs as the root user?

apoorv569 commented 1 year ago

What makes you think that the autostart file starts programs as the root user?

Because I had problems with 2 programs reading wrong configuration file mpd and syncthing. If I run any of these from terminal without specifying path to configuration file they read the correct config file i.e under ~/.config but if I put these in autostart file they use the config form /etc/ or whichever the default is.

Also if I try to kill the process I could not, without using sudo.

I also noticed the SHCMD in the config.h for dwm runs the command as root user as well. I have couple of keybinds like this,

        { MODKEY,                       XK_x,            spawn,                  SHCMD("~/.local/bin/scripts/dm-scripts/dm-session")},

the dmenu prompts does open but shows empty. So I am as a workaround point the keybind to another script which runs this script as my user.

bakkeby commented 1 year ago

I don't know, it sounds like you are running dwm as the root user.

apoorv569 commented 1 year ago

I don't know, it sounds like you are running dwm as the root user.

How do you mean? I login as my user from my login manager (lightdm). This keybind used to work fine when I was using my own fork of dwm.

bakkeby commented 1 year ago

To answer your question the autostart.sh should not run as the root user, it would not be normal.

The autostart file and when spawning commands from dwm should run as the user that is logged in.

ps -ef will tell you if the program is running as your user or not.

As for your symptoms:

A program may not necessarily adhere to a kill even if it is running as your user, but a kill -9 should usually work.

If you find that you can open a terminal and start a program (or script) fine, but that same program behaves differently when starting via .xinitrc, autostart.sh or when spawning via dwm then it may be that the program depends on some environment variables that are not set in the current session.

apoorv569 commented 1 year ago

ps -ef will tell you if the program is running as your user or not.

ps -ef says programs are running as the correct user..

As for your symptoms:

A program may not necessarily adhere to a kill even if it is running as your user, but a kill -9 should usually work.

If you find that you can open a terminal and start a program (or script) fine, but that same program behaves differently when starting via .xinitrc, autostart.sh or when spawning via dwm then it may be that the program depends on some environment variables that are not set in the current session.

I always use pkill -9 to kill processes.

About the env vars, I have set all my env vars related to programs I use correctly. I have even set the XDG dirs, cache, config and all.

I do use zsh could that be a issue?

bakkeby commented 1 year ago

Where do you set those environment variables?

bakkeby commented 1 year ago

If you run this then that may give you some insight into what environment variables are set for your session (although it is not particularly readable). This will usually be less than what you get when you run env in a terminal.

cat /proc/$(pidof dwm)/environ

What is being set may depend on the login / display manager. It may be that /etc/environment is being read, not sure.