remove workaround, now reopen trinket every loop
authorTeodor Sigaev <teodor@sigaev.ru>
Wed, 6 Apr 2016 19:34:18 +0000 (22:34 +0300)
committerTeodor Sigaev <teodor@sigaev.ru>
Wed, 6 Apr 2016 19:34:18 +0000 (22:34 +0300)
main.c
rc.d/trinketd

diff --git a/main.c b/main.c
index 7c48a37..4552672 100644 (file)
--- a/main.c
+++ b/main.c
@@ -43,7 +43,6 @@ static int            tics = 1;
 static char*   pidfile = NULL;
 static char*   logfile = NULL;
 static bool            daemonize = false;
-static bool            workaround = false;
 static char            tfile[MAXPATHLEN],
                                ofile[MAXPATHLEN];
 
@@ -53,7 +52,7 @@ static void
 usage(const char *errmsg) {
        puts("trinketd - collecting info from AtomPro");
        puts("Copyright (c) 2016, Teodor Sigaev <teodor@sigaev.ru>");
-       puts("trinketd [-d] [-l logfile] [-p pidfile] [-P period] [-D datadir] [-i tics] [-w]");
+       puts("trinketd [-d] [-l logfile] [-p pidfile] [-P period] [-D datadir] [-i tics]");
 
        if (errmsg) {
                puts("");
@@ -68,7 +67,7 @@ main_loop() {
        double  *prevDose,
                        curDose;
        int             i;
-       int             collected;
+       int             collected = 0;
 
        prevDose = malloc(sizeof(*prevDose) * (tics + 1));
        if (!prevDose) {
@@ -76,25 +75,21 @@ main_loop() {
                return;
        }
 
-restart:
        collected = 0;
 
-       if (trinketOpen() != ERR_OK) {
-               fprintf(stderr, "trinketOpen fails\n");
-               sleep(1);
-               goto restart;
-       }
-
        while(42) {
 
-               if (workaround)
-                       trinketPing();
+               if (trinketOpen() != ERR_OK) {
+                       fprintf(stderr, "trinketOpen fails\n");
+                       sleep(1);
+                       continue;
+               }
 
                if (trinketGetCumDose(&curDose) != ERR_OK) {
                        fprintf(stderr, "trinketGetCumDose fails\n");
                        trinketClose();
                        sleep(1);
-                       goto restart;
+                       continue;
                }
 
                if (collected <= tics) {
@@ -133,10 +128,9 @@ restart:
                        }
                }
 
+               trinketClose();
                sleep(period);
        }
-
-       trinketClose();
 }
 
 
@@ -150,7 +144,7 @@ main(int argn, char* argv[]) {
                logfd;
 
        opterr = 0;
-       while((i=getopt(argn,argv,"dD:i:l:p:P:wh")) != EOF) {
+       while((i=getopt(argn,argv,"dD:i:l:p:P:h")) != EOF) {
                switch(i) {
                        case 'd':
                                daemonize = true;
@@ -170,9 +164,6 @@ main(int argn, char* argv[]) {
                        case 'P':
                                period = atoi(optarg);
                                break;
-                       case 'w':
-                               workaround = true;
-                               break;
                        case 'h':
                        default:
                                usage(NULL);
index b9540e0..9e92010 100755 (executable)
@@ -21,7 +21,7 @@ dbdir="/var/db/trinket"
 procname="/usr/local/sbin/trinketd"
 
 command="${procname}"
-command_args=" -d -p ${pidfile} -P 300 -i 12 -D ${dbdir} -l ${logfile} -w"
+command_args=" -d -p ${pidfile} -P 300 -i 12 -D ${dbdir} -l ${logfile}"
 
 load_rc_config $name