Message ID | 1433932164-16099-1-git-send-email-hendrik@linux-nerds.de |
---|---|
State | Superseded |
Headers | show |
* Hendrik Lüth <hendrik@linux-nerds.de> [10.06.2015 12:58]: > + for i in /etc/profile.d/* ; do > + if [ -r $i ]; then > + . $i > + fi > + done > + unset i > +fi i like the idea, but please use at least: command . $i or ( . $i ) otherwise a syntax error / file error will prevent a login. also use the unofficial simplified OpenWrt style here, it is OK to: for FILE in /etc/profile.d/*; do [ -e "$FILE" ] && ( . $FILE ) done i'am also unsure if 'unset FILE' is maybe overkill... bye, bastian
Hello Bastian, > > i like the idea, but please use at least: > > command . $i > or > ( . $i ) I think this will not work, as /etc/profile (and these additional files) is expected to be executed in the current shell context. Otherwise adding shell variables or extending $PATH will not work. So you cannot execute them in a subshell. > > otherwise a syntax error / file error will prevent a login. Maybe it is possible to skip this for FAILSAFE mode? If there are errors, they can be corrected in this way. > also use the unofficial simplified OpenWrt style here, it is OK to: > > for FILE in /etc/profile.d/*; do > [ -e "$FILE" ] && ( . $FILE ) > done The same issue with subshell... > > i'am also unsure if 'unset FILE' is maybe overkill... > > bye, bastian Best Regards, Thomas --- There are two hard things in computer science: cache invalidation, naming things, and off-by-one errors. ---
* thomas.langer@lantiq.com <thomas.langer@lantiq.com> [10.06.2015 13:59]: > I think this will not work, as /etc/profile (and these additional files) is expected to be executed in the current shell context. > Otherwise adding shell variables or extending $PATH will not work. So you cannot execute them in a subshell. ok, then please: [ -e "$FILE" ] && sh -n "$FILE" && . "$FILE" > Maybe it is possible to skip this for FAILSAFE mode? If there are errors, they can be corrected in this way. this is a good point: [ -z "$FAILSAFE" ] && { ...yourlogic... } bye, bastian
On 06/10/2015 02:01 PM, Bastian Bittorf wrote: > * thomas.langer@lantiq.com <thomas.langer@lantiq.com> [10.06.2015 13:59]: >> I think this will not work, as /etc/profile (and these additional files) is expected to be executed in the current shell context. >> Otherwise adding shell variables or extending $PATH will not work. So you cannot execute them in a subshell. > > ok, then please: > [ -e "$FILE" ] && sh -n "$FILE" && . "$FILE" > >> Maybe it is possible to skip this for FAILSAFE mode? If there are errors, they can be corrected in this way. > > this is a good point: > > [ -z "$FAILSAFE" ] && { > ...yourlogic... > } > > bye, bastian Why should errors in these files cause login issues? This is shell and there's no -e, problematic lines will print an error and be skipped. Hendrik's patch adds exactly the lines used by Debian. On Arch Linux, it looks very similar. The only way to break login using profile snippets is causing the shell to exit explicitly (using `exit` or something like that), but there's no sane way to protect against that... Matthias
* Matthias Schiffer <mschiffer@universe-factory.net> [10.06.2015 14:26]: > Why should errors in these files cause login issues? This is shell and > there's no -e, problematic lines will print an error and be skipped. i have seen a lot of strange things. think about flash readerrors or stack corruption or $youridea 8-) i think we can agree that we will not use a subshell, but ignore profile.d in failsafe mode, ok? the 'sh -n' thing is just a small 'insurance' - do you think it hurts/is too much? bye, bastian
Am 10.06.2015 um 14:31 schrieb Bastian Bittorf: > * Matthias Schiffer <mschiffer@universe-factory.net> [10.06.2015 14:26]: >> Why should errors in these files cause login issues? This is shell and >> there's no -e, problematic lines will print an error and be skipped. > i have seen a lot of strange things. think about > flash readerrors or stack corruption or $youridea 8-) > > i think we can agree that we will not use a subshell, > but ignore profile.d in failsafe mode, ok? the 'sh -n' > thing is just a small 'insurance' - do you think it hurts/is too much? > > bye, bastian I'd like to see, that the scripts in profile.d are getting called without the 'sh' because those scripts could be written in Lua, too. Weather a script needs to get called in failsafe mode or not depends on the script, so I'd like to not skip it. regards, Hendrik
On 06/10/2015 04:27 PM, Hendrik Lüth wrote: > Am 10.06.2015 um 14:31 schrieb Bastian Bittorf: >> * Matthias Schiffer <mschiffer@universe-factory.net> [10.06.2015 14:26]: >>> Why should errors in these files cause login issues? This is shell and >>> there's no -e, problematic lines will print an error and be skipped. >> i have seen a lot of strange things. think about >> flash readerrors or stack corruption or $youridea 8-) >> >> i think we can agree that we will not use a subshell, >> but ignore profile.d in failsafe mode, ok? the 'sh -n' >> thing is just a small 'insurance' - do you think it hurts/is too much? >> >> bye, bastian > > I'd like to see, that the scripts in profile.d are getting called > without the 'sh' because those scripts could be written in Lua, too. > Weather a script needs to get called in failsafe mode or not depends on > the script, so I'd like to not skip it. > > regards, Hendrik That's not at all what profile.d is about. profile.d is for shell snippets that are *sourced* into the login shell, not executed, so they must be shell code. If you want to call Lua scripts, just call Lua from the shell code. I agree that it would make sense to skip profile.d in failsafe mode.
On Jun 10, 2015 6:30 PM, "Hendrik Lüth" <hendrik@linux-nerds.de> wrote: > > OpenWrt should support an optinal /etc/profile.d directory like most other Linux > distributions. This allows packages to install their own scripts into > /etc/profile.d/. IMO, OpenWrt is not like most of other Linux distributions. So what are those other packages that need this and the current specific use cases? yousong > --- > package/base-files/files/etc/profile | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/package/base-files/files/etc/profile b/package/base-files/files/etc/profile > index 3dd58e1..c9e805f 100644 > --- a/package/base-files/files/etc/profile > +++ b/package/base-files/files/etc/profile > @@ -14,3 +14,12 @@ export PS1='\u@\h:\w\$ ' > > [ -x /usr/bin/arp ] || arp() { cat /proc/net/arp; } > [ -x /usr/bin/ldd ] || ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; } > + > +if [ -d /etc/profile.d ]; then > + for i in /etc/profile.d/* ; do > + if [ -r $i ]; then > + . $i > + fi > + done > + unset i > +fi > -- > 2.4.1 > _______________________________________________ > openwrt-devel mailing list > openwrt-devel@lists.openwrt.org > https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
* Hendrik Lüth <hendrik@linux-nerds.de> [10.06.2015 20:38]: > Weather a script needs to get called in failsafe mode or not depends > on the script, so I'd like to not skip it. no, failsafe is failsafe is failsafe and should do mostly nothing. bye, bastian
* Yousong Zhou <yszhou4tech@gmail.com> [10.06.2015 20:38]: > > distributions. This allows packages to install their own scripts into > > /etc/profile.d/. > > IMO, OpenWrt is not like most of other Linux distributions. So what are > those other packages that need this and the current specific use cases? I agree, that OpenWrt differs - and i have a usecase: 1) we like to have special helpers like alias n='wget -qO - http://127.0.0.1:2006/neighbours' (for OLSRd) and we source/include a special 'metascript' which makes adminstration much easier. for now we patch /etc/profile but having it in profile.d is more clean and: it is automatically removed if package XY is also removed... bye, bastian
On 06/10/2015 07:46 PM, Bastian Bittorf wrote: > * Yousong Zhou <yszhou4tech@gmail.com> [10.06.2015 20:38]: >>> distributions. This allows packages to install their own scripts into >>> /etc/profile.d/. >> >> IMO, OpenWrt is not like most of other Linux distributions. So what are >> those other packages that need this and the current specific use cases? > > I agree, that OpenWrt differs - and i have a usecase: > > 1) > we like to have special helpers like > > alias n='wget -qO - http://127.0.0.1:2006/neighbours' > (for OLSRd) > > and we source/include a special 'metascript' which > makes adminstration much easier. for now we patch /etc/profile > but having it in profile.d is more clean and: it is automatically > removed if package XY is also removed... Right. Also something more simple: I'd like to have ll='ls -la' on my systems and OpenWRT based "mini-distributions". Right now I have to change package/base-files/etc/profile or override /etc/profile completely from the files/ folder. In this case it's not too complicated, but its not maintainable very well. Another maybe more interesting example is the Java VM "jamvm". It depends on "classpath" which is quite big and one of my systems has to be installed on the SD card. Because the libraries are on /mnt/sd/ I need "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/mnt/sd/usr/lib/classpath" for jamvm to work properly. That could go into a "system" and "distribution" specific package which puts it into /etc/profile.d/... which is much cleaner than overriding /etc/profile or -worse- messing with /etc/profile in a postinst script... bruno
diff --git a/package/base-files/files/etc/profile b/package/base-files/files/etc/profile index 3dd58e1..c9e805f 100644 --- a/package/base-files/files/etc/profile +++ b/package/base-files/files/etc/profile @@ -14,3 +14,12 @@ export PS1='\u@\h:\w\$ ' [ -x /usr/bin/arp ] || arp() { cat /proc/net/arp; } [ -x /usr/bin/ldd ] || ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; } + +if [ -d /etc/profile.d ]; then + for i in /etc/profile.d/* ; do + if [ -r $i ]; then + . $i + fi + done + unset i +fi