Welcome to little lamb

Code » anopa » commit f10a397

start/stop: Fix possible warning "no service for id"

author Olivier Brunel
2017-01-27 18:25:16 UTC
committer Olivier Brunel
2017-06-18 12:28:56 UTC
parent 2b7319ca94ca5c9b0208e20653c5781c39025278

start/stop: Fix possible warning "no service for id"

A warning "unable to find longrun service for id#x" could be shown at
times. This was because we first subscribe to a service, then check its
current status and if what we want, unsubscribe & process the service
as already up/not up.

However, for one-time subscription if the event happens to have been
triggered right in between, then we're already unsubscribed and the
event for that id already queued up.

So, we now check that unsubscribing was successful, and if not because
the id isn't of a subscription anymore then we'll properly treat the
event later as usual.

src/libanopa/exec_longrun.c +14 -6

diff --git a/src/libanopa/exec_longrun.c b/src/libanopa/exec_longrun.c
index f1c8578..abd696d 100644
--- a/src/libanopa/exec_longrun.c
+++ b/src/libanopa/exec_longrun.c
@@ -88,10 +88,19 @@ _exec_longrun (int si, aa_mode mode)
 
         if (!is_start || !s->gets_ready || st6.flagready)
         {
-            already = 1;
-            /* already there; unsubcribe */
-            ftrigr_unsubscribe_g (&_aa_ft, s->ft_id, &deadline);
-            s->ft_id = 0;
+            /* already there: unsubcribe.
+             *
+             * Failure to unsubscribe w/ EINVAL means that the service got where
+             * we wanted *after* we subscribed, and the event was already
+             * treated/is queued up (when non-repeating, i.e. no FTRIGR_REPEAT).
+             * Then, we want to process it later as usual (i.e. keep it & not
+             * set already).
+             */
+            if (aa_unsubscribe_for (s->ft_id) == 0 || errno != EINVAL)
+            {
+                already = 1;
+                s->ft_id = 0;
+            }
         }
 
         /* make sure our status is correct, and timestamped before s6 */
@@ -154,8 +163,7 @@ _exec_longrun (int si, aa_mode mode)
                 (mode & AA_MODE_STOP_ALL) ? 2 : 1);
         if (r <= 0 && !already)
         {
-            tain_addsec_g (&deadline, 1);
-            ftrigr_unsubscribe_g (&_aa_ft, s->ft_id, &deadline);
+            aa_unsubscribe_for (s->ft_id);
             s->ft_id = 0;
 
             s->st.event = (is_start) ? AA_EVT_STARTING_FAILED : AA_EVT_STOPPING_FAILED;