[sr-dev] git:master:59d28758: kamctl: make jsonrpc filter portable

Sebastian Kemper sebastian_ml at gmx.net
Fri Oct 12 00:33:59 CEST 2018


Module: kamailio
Branch: master
Commit: 59d287586f502a8df71c2e91899fde49594e072e
URL: https://github.com/kamailio/kamailio/commit/59d287586f502a8df71c2e91899fde49594e072e

Author: Sebastian Kemper <sebastian_ml at gmx.net>
Committer: Sebastian Kemper <sebastian_ml at gmx.net>
Date: 2018-10-07T19:03:51+02:00

kamctl: make jsonrpc filter portable

The filter has a regex looking for a literal '{' in the beginning of a
line. Some awk implementations interpret this as a meta character, so
the regex is deemed broken. Example with busybox awk (POSIX):

root at hank2:~# kamctl ps
awk: bad regex '^{.+"id"[ 	]*:[ 	]*[0-9]+[ 	]*}$': Invalid contents of {}
root at hank2:~#

To fix this enclose the character in square brackets. This always
matches for a literal '{' and is portable.

Signed-off-by: Sebastian Kemper <sebastian_ml at gmx.net>

---

Modified: utils/kamctl/kamctl.base

---

Diff:  https://github.com/kamailio/kamailio/commit/59d287586f502a8df71c2e91899fde49594e072e.diff
Patch: https://github.com/kamailio/kamailio/commit/59d287586f502a8df71c2e91899fde49594e072e.patch

---

diff --git a/utils/kamctl/kamctl.base b/utils/kamctl/kamctl.base
index adeceb77fb..a776e10d82 100644
--- a/utils/kamctl/kamctl.base
+++ b/utils/kamctl/kamctl.base
@@ -715,7 +715,7 @@ filter_json()
 	$AWK 'function ltrim(s) { sub(/^[ \t\r\n]+/, "", s); return s }
 		BEGIN { line=0; IGNORECASE=1; }
 		{ line++; }
-		NR == 1 && /^{.+"id"[ \t]*:[ \t]*[0-9]+[ \t]*}$/ { print; next; }
+		NR == 1 && /^[{].+"id"[ \t]*:[ \t]*[0-9]+[ \t]*}$/ { print; next; }
 		NR == 1 && /^200 OK/ { next; }
 		/^[ \t]*"jsonrpc":[ \t]*"2.0"/ { print; next; }
 		/^[ \t]*"result":[ \t]*\[.+/ {




More information about the sr-dev mailing list