You are not logged in.
on desktops, you usually have a process tree that goes something like (well, this is only one branch):
init───login───bash───startx───xinit─┬─.xinitrc───sessionmanager─┬─WM
we all know that env vars are passed on "down the tree". but this sometimes bothers me, for example when using mpd. it uses a variable MPD_HOST
so when i have a running desktop, and i want to use an other mpd instance I must change MPD_HOST. I can only do this in the "local" environment. the widgets in my WM, the interfaces that I use etc cannot be aware of the changed variable.
how do you guys handle this?
I have some ideas for solutions:
1) make MPD_HOST=mpdhost and use /etc/hosts to make it point to other things. but that won't help for MPD_PORT or non-mpd related variables. not mentioning some apps might cache dns internally. and this requires root
2) hack my session manager so that i can somehow notify it (signals, let it listen to a socket, etc) and have it change an environment variable. but i don't know if the changed variable will automatically "propagate downstream" (probably not).
any more ideas?
thanks.
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline
I recently asked about a similar issue setting the http_proxy variable when starting vpnc. Seems like there is no way to make the variable global and visible to all other processes other than the child processes.
I'd be interested in other people's comments.
Offline
I tend to use a wrapper script for the app i want to run and a file from which it sources the environment variable
ie in ~/.bin/mpc
#!/bin/bash
source ~/.env/mpc
/usr/bin/mpc "$@"
and the contents of ~/.env/mpc would look like that:
export MPD_HOST=localhost
Last edited by raf_kig (2010-02-11 13:12:48)
Offline
I tend to use a wrapper script for the app i want to run and a file from which it sources the environment variable
(..)
Explain how this should solve the problem? I think you don't understand my question.
Last edited by Dieter@be (2010-02-11 13:14:14)
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline
hm yeah, it obviously won't work for running instances of programs - it just makes sure that changes in env (in the respective env-file) take effect for all new instances of $program.
You can eg use gdb to change the env of a running process (have a look at this script for reference http://www.nanonanonano.net/linux/chenv) , but most of the time that won't help you. Typically env vars are only evaluated at startup and then used to populate the appropriate structures. You'll probably have to implement the required functionality yourself in every single program.
For MPD a more or less simple workaround might be writing a small proxy that allows you to switch its destination on the fly - but i don't know whether MPD's protocol is stateful and whether clients will handle the transition gracefully.
Last edited by raf_kig (2010-02-12 14:55:02)
Offline
I think what you want is not possible. You would have to use something like what raf_kig has and restart the program. fork copies the env vars; there is no shared address space.
aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies
Offline
I just found that in my bookmarks, you might want to take a look at it :-)
Offline
aha mpd_proxy looks neat. that joey dude is a cool guy, every once in a while I'm pointed to an article or program and it turns out to be on his site.
and too bad about the limitations with env vars but glad it's cleared up.
An alternative I'm thinking about: my WM (awesome) can reload in place without loosing state (though i'm not sure it can get a new environment while doing that), and i could script it so that it restarts ncmpcpp (my mpd client) when it restarts.
< Daenyth> and he works prolifically
4 8 15 16 23 42
Offline