diff -r 638e7dd1d560 -r 4b54d6f79d25 bmsd/bms.c --- a/bmsd/bms.c Thu May 07 14:59:50 2020 +0200 +++ b/bmsd/bms.c Mon May 11 17:32:08 2020 +0200 @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (C) 2017-2019 + * Copyright (C) 2017-2020 * * Michiel Broek * @@ -28,16 +28,19 @@ #include "mqtt.h" #include "mysql.h" #include "nodes.h" +#include "websocket.h" int my_shutdown = FALSE; int debug = FALSE; -static pid_t /*pgrp, */mypid; +static pid_t mypid; char *Private_Path = NULL; /* Users data path */ +pthread_t ws_thread; extern sys_config Config; + void help(void) { fprintf(stdout, "bmsd v%s starting\n\n", VERSION); @@ -128,19 +131,30 @@ goto endit2; } + rc = pthread_create(&ws_thread, NULL, ws_loop, NULL); + if (rc) { + fprintf(stderr, "ws_loop thread didn't start rc=%d\n", rc); + syslog(LOG_NOTICE, "ws_loop thread didn't start rc=%d", rc); + rc = 5; + goto endit3; + } + if (debug) fprintf(stdout, "[main] Entering main loop\n"); while (my_shutdown == FALSE) { - usleep(4000000); + usleep(3000000); nodes_check_online(); usleep(1000000); ispindel_mysql_check(); + usleep(1000000); + ws_check(); } if (debug) fprintf(stdout, "[main] Exit from main loop\n"); +endit3: /* * Remove our topics and close MQTT connection. */ @@ -212,17 +226,8 @@ } else { /* * Server initialization is complete. Now we can fork the - * daemon and return to the user. We need to do a setpgrp - * so that the daemon will no longer be assosiated with the - * users control terminal. This is done before the fork, so - * that the child will not be a process group leader. Otherwise, - * if the child were to open a terminal, it would become - * associated with that terminal as its control terminal. + * daemon and return to the user. */ -// if ((pgrp = setpgid(0, 0)) == -1) { -// syslog(LOG_NOTICE, "setpgid failed: %s", strerror(errno)); -// } - frk = fork(); switch (frk) { case -1: