add option for signaling readyness
authorJosé Bollo <jose.bollo@iot.bzh>
Mon, 15 Feb 2016 10:46:37 +0000 (11:46 +0100)
committerJosé Bollo <jose.bollo@iot.bzh>
Mon, 15 Feb 2016 10:46:37 +0000 (11:46 +0100)
Change-Id: I22e64d41f51683c6c15df77b546e3cc98f427eec
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
include/local-def.h
src/main.c

index 7ad4e70..01f1062 100644 (file)
@@ -265,6 +265,7 @@ typedef struct {
   void *httpd;            // anonymous structure for httpd handler
   int  fakemod;           // respond to GET/POST request without interacting with sndboard
   int  forceexit;         // when autoconfig from script force exit before starting server
+  int  readyfd;           // a #fd to signal when ready to serve
   AFB_plugin **plugins;   // pointer to REST/API plugins 
   magic_t  magic;         // Mime type file magic lib
   sigjmp_buf restartCkpt; // context save for restart set/longjmp
index 57660ed..78d7f79 100644 (file)
@@ -80,6 +80,7 @@ static sigjmp_buf exitPoint; // context save for set/longjmp
 #define DISPLAY_HELP       151
 
 #define SET_MODE           160
+#define SET_READYFD        161
 
 
 // Supported option
@@ -115,6 +116,7 @@ static  AFB_options cliOptions [] = {
   {DISPLAY_HELP     ,0,"help"            , "Display this help"},
 
   {SET_MODE         ,1,"mode"            , "set the mode: either local, remote or global"},
+  {SET_READYFD      ,1,"readyfd"         , "set the #fd to signal when ready"},
   {0, 0, 0}
  };
 
@@ -242,6 +244,12 @@ static void listenLoop (AFB_session *session) {
         err = httpdStart (session);
         if (err != AFB_SUCCESS) return;
 
+       if (session->readyfd != 0) {
+               static const char readystr[] = "READY=1";
+               write(session->readyfd, readystr, sizeof(readystr) - 1);
+               close(session->readyfd);
+       }
+
         // infinite loop
         httpdLoop(session);
 
@@ -425,6 +433,11 @@ int main(int argc, char *argv[])  {
        else goto badMode;
        break;
 
+    case SET_READYFD:
+       if (optarg == 0) goto needValueForOption;
+       if (!sscanf (optarg, "%u", &session->readyfd)) goto notAnInteger;
+       break;
+
     case DISPLAY_VERSION:
        if (optarg != 0) goto noValueForOption;
        printVersion();