[OpenWrt-Devel] [PATCHv2] [netifd/scripts] make netifd scripts recognize signal strings such as INT/TERM/KILL/... signal in proto_kill_command()

2014-10-15 Thread Bastian Bittorf
[netifd/scripts] make netifd scripts recognize signal strings such as 
INT/TERM/KILL/...

instead of let the caller do the conversion of symbolic to numeric (e.g. 
SIGUSR1 -> 16),
do the conversion internally - the old mode (numeric) is still supported

Signed-off-by: Bastian Bittorf 
---
 scripts/netifd-proto.sh |   15 +--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/scripts/netifd-proto.sh b/scripts/netifd-proto.sh
index ce316c4..6625053 100644
--- a/scripts/netifd-proto.sh
+++ b/scripts/netifd-proto.sh
@@ -286,11 +286,22 @@ proto_run_command() {
 }
 
 proto_kill_command() {
-   local interface="$1"; shift
+   local interface="$1"
+   local signal="$2"
 
json_init
json_add_int action 2
-   [ -n "$1" ] && json_add_int signal "$1"
+
+   case "$signal" in
+   [0-9]|[0-9][0-9])
+   json_add_int signal "$signal"
+   ;;
+   [a-zA-Z]*)
+   signal="$( kill -l "$signal" )"
+   json_add_int signal "$signal"
+   ;;
+   esac
+
_proto_notify "$interface"
 }
 
-- 
1.7.10.4
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCHv2] [netifd/scripts] make netifd scripts recognize signal strings such as INT/TERM/KILL/... signal in proto_kill_command()

2014-10-18 Thread Yousong Zhou
Am 16.10.2014 14:59 schrieb "Bastian Bittorf" :
>
> [netifd/scripts] make netifd scripts recognize signal strings such as
INT/TERM/KILL/...
>
> instead of let the caller do the conversion of symbolic to numeric (e.g.
SIGUSR1 -> 16),
> do the conversion internally - the old mode (numeric) is still supported
>
> Signed-off-by: Bastian Bittorf 
> ---
>  scripts/netifd-proto.sh |   15 +--
>  1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/netifd-proto.sh b/scripts/netifd-proto.sh
> index ce316c4..6625053 100644
> --- a/scripts/netifd-proto.sh
> +++ b/scripts/netifd-proto.sh
> @@ -286,11 +286,22 @@ proto_run_command() {
>  }
>
>  proto_kill_command() {
> -   local interface="$1"; shift
> +   local interface="$1"
> +   local signal="$2"
>
> json_init
> json_add_int action 2
> -   [ -n "$1" ] && json_add_int signal "$1"
> +
> +   case "$signal" in
> +   [0-9]|[0-9][0-9])
> +   json_add_int signal "$signal"
> +   ;;
> +   [a-zA-Z]*)
> +   signal="$( kill -l "$signal" )"

the quotes may not work...

yousong

> +   json_add_int signal "$signal"
> +   ;;
> +   esac
> +
> _proto_notify "$interface"
>  }
>
> --
> 1.7.10.4
> ___
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCHv2] [netifd/scripts] make netifd scripts recognize signal strings such as INT/TERM/KILL/... signal in proto_kill_command()

2014-10-18 Thread Bastian Bittorf
* Yousong Zhou  [18.10.2014 17:58]:
> > +   signal="$( kill -l "$signal" )"
> 
> the quotes may not work...

they work and you should always quote a var,
unless you are really sure it is an integer...

root@box:~ kill -l "15"
TERM
root@box:~ kill -l "TERM"
15

bye, bastian
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCHv2] [netifd/scripts] make netifd scripts recognize signal strings such as INT/TERM/KILL/... signal in proto_kill_command()

2014-10-18 Thread Yousong Zhou
Am 18.10.2014 23:58 schrieb "Bastian Bittorf" :
>
> * Yousong Zhou  [18.10.2014 17:58]:
> > > +   signal="$( kill -l "$signal" )"
> >
> > the quotes may not work...
>
> they work and you should always quote a var,
> unless you are really sure it is an integer...
>

yes.  it's just that the syntax of the quoting here is a little misleading
to me, i.e. concatenation of 3 different part with the var seemingly not
protected by quotes.  but i have just tried it with ash and it did work.

   yousong

> root@box:~ kill -l "15"
> TERM
> root@box:~ kill -l "TERM"
> 15
>
> bye, bastian
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel