Merge pull request #3 from mtearle/master
[tpg/opendispense2.git] / src / server / main.c
index 6c2f691..cbebee2 100644 (file)
@@ -9,6 +9,7 @@
  */
 #include <stdlib.h>
 #include <stdio.h>
+#include <stdbool.h>
 #include <string.h>
 #include <signal.h>
 #include "common.h"
@@ -20,6 +21,7 @@
 #include <syslog.h>
 #include <pthread.h>
 #include "../cokebank.h"
+#include "../common/config.h"
 
 // === IMPORTS ===
 extern void    Init_Handlers(void);
@@ -30,6 +32,7 @@ extern int    giServer_Port;
 extern const char      *gsItemListFile;
 extern const char      *gsCoke_ModbusAddress;
 extern const char      *gsDoor_SerialPort;
+extern bool    gbSyslogEnabled;
 
 // === PROTOTYPES ===
 void   *Periodic_Thread(void *Unused);
@@ -128,6 +131,7 @@ int main(int argc, char *argv[])
        gsItemListFile       = Config_GetValue("items_file", 0);
 
        gbNoCostMode         = (Config_GetValue_Bool("test_mode", 0) == 1);
+       gbSyslogEnabled      = (Config_GetValue_Bool("disable_syslog", 0) == 0);
 
        signal(SIGINT, sigint_handler);
        signal(SIGTERM, sigint_handler);
@@ -184,38 +188,6 @@ void AddPeriodicFunction(void (*Fcn)(void))
        fprintf(stderr, "Error: No space for %p in periodic list\n", Fcn);
 }
 
-int RunRegex(regex_t *regex, const char *string, int nMatches, regmatch_t *matches, const char *errorMessage)
-{
-        int    ret;
-       
-       ret = regexec(regex, string, nMatches, matches, 0);
-       if( ret == REG_NOMATCH ) {
-               return -1;
-       }
-       if( ret ) {
-               size_t  len = regerror(ret, regex, NULL, 0);
-               char    errorStr[len];
-               regerror(ret, regex, errorStr, len);
-               printf("string = '%s'\n", string);
-               fprintf(stderr, "%s\n%s", errorMessage, errorStr);
-               exit(-1);
-       }
-       
-       return ret;
-}
-
-void CompileRegex(regex_t *regex, const char *pattern, int flags)
-{
-        int    ret = regcomp(regex, pattern, flags);
-       if( ret ) {
-               size_t  len = regerror(ret, regex, NULL, 0);
-               char    errorStr[len];
-               regerror(ret, regex, errorStr, len);
-               fprintf(stderr, "Regex compilation failed - %s\n%s\n", errorStr, pattern);
-               exit(-1);
-       }
-}
-
 // Serial helper
 int InitSerial(const char *File, int BaudRate)
 {
@@ -231,7 +203,9 @@ int InitSerial(const char *File, int BaudRate)
        case 1200:      baud = B1200;   break;
        case 9600:      baud = B9600;   break;
        case 115200:    baud = B115200; break;
-       default:        close(fd);      return -1;
+       default:
+               fprintf(stderr, "ERROR: Invalid baud rate to InitSerial (%i)\n", BaudRate);
+               exit(1);
        }
        
        info.c_lflag = 0;       // Non-Canoical, No Echo

UCC git Repository :: git.ucc.asn.au