Re: ifstated body executing before init?

2011-03-28 Thread Kapetanakis Giannis

Any thought on this?

Giannis

On 25/03/11 16:48, Kapetanakis Giannis wrote:

Hi,

According to ifstated.conf(5)
The init block is used to initialise the state and is executed each 
time the state is entered.


This should be the first thing to be executed right? In debug I see 
the body executed first.

Isn't the code bellow more reasonable?

--- /tmp/ifstated.c Fri Mar 25 16:32:13 2011
+++ ifstated.c  Fri Mar 25 16:32:24 2011
@@ -543,9 +543,9 @@
conf-curstate = conf-nextstate;
conf-nextstate = NULL;
conf-curstate-entered = time(NULL);
+   do_action(conf-curstate-init);
external_evtimer_setup(conf-curstate, IFSD_EVTIMER_ADD);
adjust_external_expressions(conf-curstate);
-   do_action(conf-curstate-init);
return (1);
}
return (0);

Also one more thing. In the state bellow:
state promoted {
init {
run ifconfig carp0 advskew 101
run ifconfig carp1 advskew 101
}
if $net
set-state primary
if ! $net  $peer
set-state backup
}

Both expressions in the body are evaluated the first time we enter the 
state. Why?
If first expression is true, shouldn't we go directly on primary state 
without evaluating second if?


thanx

Giannis




Re: ifstated body executing before init?

2011-03-26 Thread Christian Kildau
Sorry for hijacking your thread, but this seems related to a problem I have:

I'm running ifstated to monitor my DSL connection, which my provider
disconnects automatically every 24h. But instead of starting my backup via
UMTS, I'd like ifstated to wait 30s or so, and if pppoe0 is still down, it
might start the UMTS connection. (see config below)

Is this a bug or a feature? If the latter, how can I solve this?

init-state auto
pppoe0_up = pppoe0.link.up

state auto {
if $pppoe0_up {
set-state dsl_up
}
if !$pppoe0_up {
set-state dsl_down
}
}

state dsl_up {
init {
run /sbin/ifconfig | mail -s 'DSL up' root
}
if !$pppoe0_up {
set-state dsl_down
}
}
state dsl_down {
init {
run /bin/sleep 30; /sbin/ifconfig | mail -s 'DSL down' root
}
if !$pppoe0_up {
set-state umts_start
}
if $pppoe0_up {
set-state dsl_up
}
}
state umts_start {
init {
run /usr/sbin/pppd call o2
run sleep 30; /sbin/ifconfig | mail -s 'Starting UMTS' root
}
if $pppoe0_up {
set-state umts_stop
}
}
state umts_stop {
init {
run /usr/bin/pkill pppd
run /sbin/ifconfig | mail -s 'Stopping UMTS' root
}
set-state dsl_up
}



On Mar 25, 2011, at 3:48 PM, Kapetanakis Giannis wrote:

 Hi,

 According to ifstated.conf(5)
 The init block is used to initialise the state and is executed each time
the state is entered.

 This should be the first thing to be executed right? In debug I see the body
executed first.
 Isn't the code bellow more reasonable?

 --- /tmp/ifstated.c Fri Mar 25 16:32:13 2011
 +++ ifstated.c  Fri Mar 25 16:32:24 2011
 @@ -543,9 +543,9 @@
conf-curstate = conf-nextstate;
conf-nextstate = NULL;
conf-curstate-entered = time(NULL);
 +   do_action(conf-curstate-init);
external_evtimer_setup(conf-curstate, IFSD_EVTIMER_ADD);
adjust_external_expressions(conf-curstate);
 -   do_action(conf-curstate-init);
return (1);
}
return (0);

 Also one more thing. In the state bellow:
 state promoted {
init {
run ifconfig carp0 advskew 101
run ifconfig carp1 advskew 101
}
if $net
set-state primary
if ! $net  $peer
set-state backup
 }

 Both expressions in the body are evaluated the first time we enter the
state. Why?
 If first expression is true, shouldn't we go directly on primary state
without evaluating second if?

 thanx

 Giannis


--
http://www.chrisk.de



Re: ifstated body executing before init?

2011-03-26 Thread Christian Kildau
Damn, hit send to early.

Of course it doesn't work as I expected. Switches directly to umts_start and
only delays the mail notification.


On Mar 26, 2011, at 10:28 AM, Christian Kildau wrote:

 Sorry for hijacking your thread, but this seems related to a problem I
have:

 I'm running ifstated to monitor my DSL connection, which my provider
disconnects automatically every 24h. But instead of starting my backup via
UMTS, I'd like ifstated to wait 30s or so, and if pppoe0 is still down, it
might start the UMTS connection. (see config below)

 Is this a bug or a feature? If the latter, how can I solve this?

 init-state auto
 pppoe0_up = pppoe0.link.up

 state auto {
if $pppoe0_up {
set-state dsl_up
}
if !$pppoe0_up {
set-state dsl_down
}
 }

 state dsl_up {
init {
run /sbin/ifconfig | mail -s 'DSL up' root
}
if !$pppoe0_up {
set-state dsl_down
}
 }
 state dsl_down {
init {
run /bin/sleep 30; /sbin/ifconfig | mail -s 'DSL down'
root
}
if !$pppoe0_up {
set-state umts_start
}
if $pppoe0_up {
set-state dsl_up
}
 }
 state umts_start {
init {
run /usr/sbin/pppd call o2
run sleep 30; /sbin/ifconfig | mail -s 'Starting UMTS'
root
}
if $pppoe0_up {
set-state umts_stop
}
 }
 state umts_stop {
init {
run /usr/bin/pkill pppd
run /sbin/ifconfig | mail -s 'Stopping UMTS' root
}
set-state dsl_up
 }



 On Mar 25, 2011, at 3:48 PM, Kapetanakis Giannis wrote:

 Hi,

 According to ifstated.conf(5)
 The init block is used to initialise the state and is executed each time
the state is entered.

 This should be the first thing to be executed right? In debug I see the
body executed first.
 Isn't the code bellow more reasonable?

 --- /tmp/ifstated.c Fri Mar 25 16:32:13 2011
 +++ ifstated.c  Fri Mar 25 16:32:24 2011
 @@ -543,9 +543,9 @@
   conf-curstate = conf-nextstate;
   conf-nextstate = NULL;
   conf-curstate-entered = time(NULL);
 +   do_action(conf-curstate-init);
   external_evtimer_setup(conf-curstate, IFSD_EVTIMER_ADD);
   adjust_external_expressions(conf-curstate);
 -   do_action(conf-curstate-init);
   return (1);
   }
   return (0);

 Also one more thing. In the state bellow:
 state promoted {
   init {
   run ifconfig carp0 advskew 101
   run ifconfig carp1 advskew 101
   }
   if $net
   set-state primary
   if ! $net  $peer
   set-state backup
 }

 Both expressions in the body are evaluated the first time we enter the
state. Why?
 If first expression is true, shouldn't we go directly on primary state
without evaluating second if?

 thanx

 Giannis


 --
 http://www.chrisk.de



ifstated body executing before init?

2011-03-25 Thread Kapetanakis Giannis

Hi,

According to ifstated.conf(5)
The init block is used to initialise the state and is executed each 
time the state is entered.


This should be the first thing to be executed right? In debug I see the 
body executed first.

Isn't the code bellow more reasonable?

--- /tmp/ifstated.c Fri Mar 25 16:32:13 2011
+++ ifstated.c  Fri Mar 25 16:32:24 2011
@@ -543,9 +543,9 @@
conf-curstate = conf-nextstate;
conf-nextstate = NULL;
conf-curstate-entered = time(NULL);
+   do_action(conf-curstate-init);
external_evtimer_setup(conf-curstate, IFSD_EVTIMER_ADD);
adjust_external_expressions(conf-curstate);
-   do_action(conf-curstate-init);
return (1);
}
return (0);

Also one more thing. In the state bellow:
state promoted {
init {
run ifconfig carp0 advskew 101
run ifconfig carp1 advskew 101
}
if $net
set-state primary
if ! $net  $peer
set-state backup
}

Both expressions in the body are evaluated the first time we enter the 
state. Why?
If first expression is true, shouldn't we go directly on primary state 
without evaluating second if?


thanx

Giannis