From 377f4e7e3155ee98055dfb07373709915887876b Mon Sep 17 00:00:00 2001 From: Cristiano Giuffrida Date: Sun, 27 Jun 2010 09:01:15 +0000 Subject: [PATCH] Fix and comment a race in SEF Init --- lib/libsys/sef.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/libsys/sef.c b/lib/libsys/sef.c index 6e8d920d6..985722534 100644 --- a/lib/libsys/sef.c +++ b/lib/libsys/sef.c @@ -50,6 +50,7 @@ PUBLIC void sef_startup() #if INTERCEPT_SEF_INIT_REQUESTS /* Intercept SEF Init requests. */ if(sef_self_endpoint == RS_PROC_NR) { + /* RS initialization is special. */ if((r = do_sef_rs_init()) != OK) { panic("unable to complete init: %d", r); } @@ -57,17 +58,22 @@ PUBLIC void sef_startup() else { message m; - r = receive(RS_PROC_NR, &m, &status); - if(r != OK) { - panic("unable to receive from RS: %d", r); - } - if(IS_SEF_INIT_REQUEST(&m)) { - if((r = do_sef_init_request(&m)) != OK) { - panic("unable to process init request: %d", r); + /* Wait for an initialization message from RS. We need this to learn the + * initialization type and parameters. When restarting after a crash, we + * may get some spurious IPC messages from RS (e.g. update request) that + * were originally meant to be delivered to the old instance. We discard + * these messages and block till a proper initialization request arrives. + */ + do { + r = receive(RS_PROC_NR, &m, &status); + if(r != OK) { + panic("unable to receive from RS: %d", r); } - } - else { - panic("got an unexpected message type %d", m.m_type); + } while(!IS_SEF_INIT_REQUEST(&m)); + + /* Process initialization request for this system service. */ + if((r = do_sef_init_request(&m)) != OK) { + panic("unable to process init request: %d", r); } } #endif -- 2.44.0