From 1edf05100332c85ee28abc0754fcb825648157c4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Bollo?= Date: Mon, 15 Feb 2016 11:46:37 +0100 Subject: [PATCH] add option for signaling readyness MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: I22e64d41f51683c6c15df77b546e3cc98f427eec Signed-off-by: José Bollo --- include/local-def.h | 1 + src/main.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/local-def.h b/include/local-def.h index 7ad4e705..01f10626 100644 --- a/include/local-def.h +++ b/include/local-def.h @@ -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 diff --git a/src/main.c b/src/main.c index 57660edf..78d7f79e 100644 --- a/src/main.c +++ b/src/main.c @@ -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(); -- 2.16.6