Hi,
On Sat, Nov 23, 2013 at 11:30:27AM +0100, Bastian Bittorf wrote:
> * Yousong Zhou <[email protected]> [23.11.2013 10:58]:
> > > > Looks like most of them `exit` for a reason. Maybe we could instead just
> > > > document explicitly the way hotplug scripts are run and let scripts
> > > > take the
> > > > shortcut `exit` at appropriate time.
> > >
> > > i think there is no change needed. i have changed nothing with the
> > > patch, just the look and feel. IMHO the protection against exit is
> > > needed anyway, because a script can exit be accident (crash).
> >
> > Unexpected crash should be better fixed, not just isolated by forking a
> > sub-shell for it. Also the added load of forking a new shell for each
> > of those hotplug scripts is too much, I think.
>
> you are right. i did a debug session here:
> http://intercity-vpn.de/files/openwrt/hotplug-debug.txt
> http://intercity-vpn.de/files/openwrt/hotplug-debug-output.txt
>
> and read here:
> http://www.gnu.org/software/bash/manual/bashref.html#Command-Grouping
>
> was puzzles me: the "PID_inside" is the same like from the main-script.
> should'nt it change?
It's weird. I found the following description from bash manual [1] that
`$$`:
Expands to the process ID of the shell. In a () subshell, it
expands to the process ID of the current shell, not the sub‐
shell.
There are other ways to get the PID of current shell. Like the
following:
cut -d ' ' -f 4 /proc/self/stat && ( cut -d ' ' -f 4 /proc/self/stat &&
: )
echo $$ && ( sh -c 'echo $PPID' && : )
Note that ` && : ` in the `( list )` is required, otherwise it would be
interpreted as `( expression )` in which case the parenthesis are just for
operator precedence overidden purpose [2].
[1] http://www.gnu.org/software/bash/manual/bashref.html#Special-Parameters-1
[2] http://www.gnu.org/software/bash/manual/bashref.html#Lists-of-Commands
>
> i also found, that it is possible to simply change all calls to "exit"
> to a "return", so the sourcing of a script will be aborted and no
> subshell is needed anymore.
>
> this must be somehow "enforced" by the openwrt-build: all files in
> "/etc/hotplug.d/"* cannot have the keyword "exit" in there 8-) otherwise
> we break the execution of further calls in the loop...
I agree with you. Script handlers for the same event should not
intervene with each other.
yousong
_______________________________________________
openwrt-devel mailing list
[email protected]
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel