From 4ea54bc97c222f737f0a1b48c0e4a35d01833790 Mon Sep 17 00:00:00 2001
From: Utz-Uwe Haus <uhaus@cray.com>
Date: Tue, 17 Nov 2020 16:31:26 +0100
Subject: [PATCH] ensure JOIN:after event has proper appid

---
 include/maestro/pool.h          |  1 +
 maestro/pool_manager.c          |  4 +++-
 maestro/subscription_registry.c | 17 ++++++++++++++---
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/include/maestro/pool.h b/include/maestro/pool.h
index 359ce2b6..8f853260 100644
--- a/include/maestro/pool.h
+++ b/include/maestro/pool.h
@@ -376,6 +376,7 @@ struct mstro_pool_event_ {
     /* JOIN */
     struct {
       char               *component_name; /**< component that is trying to join */
+      mstro_app_id        appid; /**< the app ID assigned (MSTRO_APP_ID_INVALID if JOIN:pre is observed) */
     } join;
 
     /* WELCOME */
diff --git a/maestro/pool_manager.c b/maestro/pool_manager.c
index 88978166..d7bf7030 100644
--- a/maestro/pool_manager.c
+++ b/maestro/pool_manager.c
@@ -2020,7 +2020,9 @@ mstro_pm__handle_join_phase2(mstro_event event,
   /* it's safe to refer to the Appid object since the Event object is
    * on stack and will only be alive until notify-and-continue is
    * done */
-  ev.origin_id = cont->msg->token->appid;
+  Mstro__Pool__Appid aid = MSTRO__POOL__APPID__INIT;
+  aid.id = regentry->appid;
+  ev.origin_id = &aid;
 
 
   status = mstro_pm__event_notify_and_continue(
diff --git a/maestro/subscription_registry.c b/maestro/subscription_registry.c
index 4fb434a6..9e9b7314 100644
--- a/maestro/subscription_registry.c
+++ b/maestro/subscription_registry.c
@@ -1848,7 +1848,14 @@ mstro_pool_event_consume(const Mstro__Pool__Event *eventmsg)
         free(ev);
         return MSTRO_NOMEM;
       }
-      DEBUG("Event: %s JOINed\n", ev->join.component_name);
+      if(eventmsg->origin_id)
+        ev->join.appid = eventmsg->origin_id->id; /* may be MSTRO_APP_ID_INVALID for JOIN:pre */
+      else
+        ev->join.appid = MSTRO_APP_ID_INVALID;
+        
+      
+      DEBUG("Event: %s JOINed (appid %" PRIappid ")\n",
+            ev->join.component_name, ev->join.appid);
       break;
       
     case MSTRO_POOL_EVENT_APP_LEAVE:
@@ -1972,6 +1979,12 @@ mstro_pool_event_consume(const Mstro__Pool__Event *eventmsg)
       }
       break;
 
+    case MSTRO_POOL_EVENT_APP_BYE:
+      assert(eventmsg->payload_case==MSTRO__POOL__EVENT__PAYLOAD_BYE);
+      ev->bye.appid = eventmsg->origin_id->id;
+      DEBUG("Event: %" PRIu64 " granted BYE\n", ev->bye.appid);
+      break;
+
     case MSTRO_POOL_EVENT_SEAL_GROUP:
     case MSTRO_POOL_EVENT_DEMAND:
     case MSTRO_POOL_EVENT_RETRACT:
@@ -1981,8 +1994,6 @@ mstro_pool_event_consume(const Mstro__Pool__Event *eventmsg)
     case MSTRO_POOL_EVENT_TRANSPORT_COMPLETED:
       
         /* pool-related */
-    case MSTRO_POOL_EVENT_APP_WELCOME:
-    case MSTRO_POOL_EVENT_APP_BYE:
     case MSTRO_POOL_EVENT_POOL_CHECKPOINT:
     case MSTRO_POOL_EVENT_SUBSCRIBE:
     case MSTRO_POOL_EVENT_UNSUBSCRIBE:
-- 
GitLab