[j-nsp] terminate endless loop in SLAX
Martin T
m4rtntns at gmail.com
Tue Jun 26 16:38:16 EDT 2018
On Tue, Jun 26, 2018 at 9:35 PM Phil Shafer <phil at juniper.net> wrote:
>
> Martin T writes:
> >Thanks Phil! So in short, at the moment "terminate" statement inside
> >the while loop works in a way that when "terminate" statement is
> >executed, then immediately next iteration of while loop is started if
> >while expression returns true and this will loop infinitely? If this
> >while expression returns false, then terminate statement was the last
> >thing processed by the script and script exits. At least based on my
> >tests it seems to work like that.
>
> Yes, which does inspire a reasonable (if ugly) workaround:
>
> Bock % cat /tmp/foo.slax
> version 1.2;
>
> match / {
> mvar $working = true();
>
> <op-script-results> {
> while ($working) {
> set $working = false();
> terminate "doa";
> }
> }
> }
> Bock % slaxproc -E -g /tmp/foo.slax
> doa
> <?xml version="1.0"?>
> <op-script-results/>
> Bock %
>
> Hope this helps.
>
> Thanks,
> Phil
Heh, I thought about exactly the same workaround. I have a script with
multiple custom functions and if the function needs to terminate, then
it returns a number and if it does not need to terminate, then it
returns a string. In main match template inside the "while ( $chars )"
loop I check this with:
set $x = example:foo($i);
if ( exsl:object-type($x) == "number" ) {
set $chars = "";
terminate "Terminated on iteration #" _ $x;
}
Other functions I return a string in case I want the main match
template to terminate and check this with something similar:
set $x = example:bar($i);
if ( exsl:object-type($x) == "string" ) {
set $chars = "";
terminate "Terminated";
}
While this is indeed hackish, then as much as I tested, it seems to work fine.
Martin
More information about the juniper-nsp
mailing list