diff --git a/include/base.h b/include/base.h index 49ccbc2..f6abc91 100644 --- a/include/base.h +++ b/include/base.h @@ -123,6 +123,7 @@ struct { struct { pthread_t id; bool pleaseStop; + int returnValue; int sockfd; } typedef Server_t; diff --git a/src/main.c b/src/main.c index 50b5c8f..b1c15d1 100644 --- a/src/main.c +++ b/src/main.c @@ -28,6 +28,7 @@ int main(int argc, char **argv) { time_t t; Server_t *server0; + int returnValue = 0; // Go! printLog("Starting gem-graph-server...\n"); @@ -48,9 +49,10 @@ int main(int argc, char **argv) ServerWait(server0); // Exiting + returnValue |= server0->returnValue; ServerDestroy(server0); ModelSystemDestroy(); free(server0); - return 0; + return returnValue; } diff --git a/src/server.c b/src/server.c index a33280a..4ffecb5 100644 --- a/src/server.c +++ b/src/server.c @@ -130,12 +130,14 @@ static void *serverMain(void *server) // Get args args = (Server_t*) server; + args->returnValue = 0; printLog("Server #%lu online\n", args->id); // Create socket args->sockfd = socket(AF_INET, SOCK_STREAM, 0); if (args->sockfd == -1) { printLog("Socket creation failed!\n"); + args->returnValue = 1; goto serverExiting; } @@ -143,12 +145,14 @@ static void *serverMain(void *server) flags = fcntl(args->sockfd, F_GETFL); if (flags == -1) { printLog("Socket parameters getting failed!\n"); + args->returnValue = 1; goto serverExiting; } // Change socket flags to non-blocking if (fcntl(args->sockfd, F_SETFL, flags | O_NONBLOCK) < 0) { printLog("Socket non-blocking setting failed!\n"); + args->returnValue = 1; goto serverExiting; } @@ -163,12 +167,14 @@ static void *serverMain(void *server) // Binding newly created socket if ((bind(args->sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr))) == -1) { printLog("Socket bind failed!\n"); + args->returnValue = 1; goto serverExiting; } // Now server is ready to listen and verification if (listen(args->sockfd, MAX_CONNECTION) == -1) { printLog("Socket listening failed!\n"); + args->returnValue = 1; goto serverExiting; } @@ -177,6 +183,7 @@ static void *serverMain(void *server) if (getsockname(args->sockfd, (struct sockaddr *) &servaddr, &socklen) == -1) { printLog("Could not get sock name!\n"); + args->returnValue = 1; goto serverExiting; } @@ -217,6 +224,7 @@ static void *serverMain(void *server) (void*)&serverSlots[serverSlotIndex]); if(threadStatus != 0) { printLog("Error from pthread: %d\n", threadStatus); + args->returnValue = 1; goto serverExiting; }