aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-02-15 11:46:37 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2016-02-15 11:46:37 +0100
commit1edf05100332c85ee28abc0754fcb825648157c4 (patch)
tree07f81dfd5dd196eabeab60aa78623e2d9a946899
parentd11b338cea727ef1463c06b94b89653d1a168727 (diff)
add option for signaling readyness
Change-Id: I22e64d41f51683c6c15df77b546e3cc98f427eec Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--include/local-def.h1
-rw-r--r--src/main.c13
2 files changed, 14 insertions, 0 deletions
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();