Re: ifstated readability diff

2017-07-03 Thread Sebastian Benoit
commited, thanks.

Rob Pierce(r...@2keys.ca) on 2017.07.03 09:45:35 -0400:
> On Sun, Jul 02, 2017 at 11:50:56PM -0400, Rob Pierce wrote:
> > Remove obvious clear_config() comments and misleading state_change() 
> > comments.
> > 
> > Also relocate do_action() calls for the init block from change_state() to
> > occur with the corresponding do_action() calls for the body block within
> > the calling function for improved readability.
> > 
> > No functional change.
> > 
> > Rob
> 
> That diff was broken. This one is correct.
> 
> Rob
> 
> Index: ifstated.c
> ===
> RCS file: /cvs/src/usr.sbin/ifstated/ifstated.c,v
> retrieving revision 1.48
> diff -u -p -r1.48 ifstated.c
> --- ifstated.c2 Jul 2017 15:28:26 -   1.48
> +++ ifstated.c3 Jul 2017 13:42:13 -
> @@ -217,8 +217,10 @@ load_config(void)
>   conf->curstate->entered = time(NULL);
>   conf->nextstate = conf->curstate;
>   conf->curstate = NULL;
> - while (state_change())
> + while (state_change()) {
> + do_action(conf->curstate->init);
>   do_action(conf->curstate->body);
> + }
>   }
>   return (0);
>  }
> @@ -533,14 +535,13 @@ eval_state(struct ifsd_state *state)
>   if (external == NULL || external->lastexec >= state->entered ||
>   external->lastexec == 0) {
>   do_action(state->body);
> - while (state_change())
> + while (state_change()) {
> + do_action(conf->curstate->init);
>   do_action(conf->curstate->body);
> + }
>   }
>  }
>  
> -/*
> - *If a previous action included a state change, process it.
> - */
>  int
>  state_change(void)
>  {
> @@ -556,7 +557,6 @@ state_change(void)
>   conf->curstate->entered = time(NULL);
>   external_evtimer_setup(conf->curstate, IFSD_EVTIMER_ADD);
>   adjust_external_expressions(conf->curstate);
> - do_action(conf->curstate->init);
>   return (1);
>   }
>   return (0);
> @@ -627,9 +627,6 @@ fetch_state(void)
>   close(sock);
>  }
>  
> -/*
> - * Clear the config.
> - */
>  void
>  clear_config(struct ifsd_config *oconf)
>  {
> 



Re: ifstated readability diff

2017-07-03 Thread Rob Pierce
On Sun, Jul 02, 2017 at 11:50:56PM -0400, Rob Pierce wrote:
> Remove obvious clear_config() comments and misleading state_change() comments.
> 
> Also relocate do_action() calls for the init block from change_state() to
> occur with the corresponding do_action() calls for the body block within
> the calling function for improved readability.
> 
> No functional change.
> 
> Rob

That diff was broken. This one is correct.

Rob

Index: ifstated.c
===
RCS file: /cvs/src/usr.sbin/ifstated/ifstated.c,v
retrieving revision 1.48
diff -u -p -r1.48 ifstated.c
--- ifstated.c  2 Jul 2017 15:28:26 -   1.48
+++ ifstated.c  3 Jul 2017 13:42:13 -
@@ -217,8 +217,10 @@ load_config(void)
conf->curstate->entered = time(NULL);
conf->nextstate = conf->curstate;
conf->curstate = NULL;
-   while (state_change())
+   while (state_change()) {
+   do_action(conf->curstate->init);
do_action(conf->curstate->body);
+   }
}
return (0);
 }
@@ -533,14 +535,13 @@ eval_state(struct ifsd_state *state)
if (external == NULL || external->lastexec >= state->entered ||
external->lastexec == 0) {
do_action(state->body);
-   while (state_change())
+   while (state_change()) {
+   do_action(conf->curstate->init);
do_action(conf->curstate->body);
+   }
}
 }
 
-/*
- *If a previous action included a state change, process it.
- */
 int
 state_change(void)
 {
@@ -556,7 +557,6 @@ state_change(void)
conf->curstate->entered = time(NULL);
external_evtimer_setup(conf->curstate, IFSD_EVTIMER_ADD);
adjust_external_expressions(conf->curstate);
-   do_action(conf->curstate->init);
return (1);
}
return (0);
@@ -627,9 +627,6 @@ fetch_state(void)
close(sock);
 }
 
-/*
- * Clear the config.
- */
 void
 clear_config(struct ifsd_config *oconf)
 {



ifstated readability diff

2017-07-02 Thread Rob Pierce
Remove obvious clear_config() comments and misleading state_change() comments.

Also relocate do_action() calls for the init block from change_state() to
occur with the corresponding do_action() calls for the body block within
the calling function for improved readability.

No functional change.

Rob


Index: ifstated.c
===
RCS file: /cvs/src/usr.sbin/ifstated/ifstated.c,v
retrieving revision 1.48
diff -u -p -r1.48 ifstated.c
--- ifstated.c  2 Jul 2017 15:28:26 -   1.48
+++ ifstated.c  3 Jul 2017 03:41:14 -
@@ -218,6 +218,7 @@ load_config(void)
conf->nextstate = conf->curstate;
conf->curstate = NULL;
while (state_change())
+   do_action(conf->curstate->init);
do_action(conf->curstate->body);
}
return (0);
@@ -534,13 +535,11 @@ eval_state(struct ifsd_state *state)
external->lastexec == 0) {
do_action(state->body);
while (state_change())
+   do_action(conf->curstate->init);
do_action(conf->curstate->body);
}
 }
 
-/*
- *If a previous action included a state change, process it.
- */
 int
 state_change(void)
 {
@@ -556,7 +555,6 @@ state_change(void)
conf->curstate->entered = time(NULL);
external_evtimer_setup(conf->curstate, IFSD_EVTIMER_ADD);
adjust_external_expressions(conf->curstate);
-   do_action(conf->curstate->init);
return (1);
}
return (0);
@@ -627,9 +625,6 @@ fetch_state(void)
close(sock);
 }
 
-/*
- * Clear the config.
- */
 void
 clear_config(struct ifsd_config *oconf)
 {