From 502935fc645fa31235e232df916a620887d74f72 Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Wed, 6 Apr 2016 22:34:18 +0300 Subject: [PATCH] remove workaround, now reopen trinket every loop --- main.c | 29 ++++++++++------------------- rc.d/trinketd | 2 +- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/main.c b/main.c index 7c48a37..4552672 100644 --- 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 "); - 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); diff --git a/rc.d/trinketd b/rc.d/trinketd index b9540e0..9e92010 100755 --- a/rc.d/trinketd +++ b/rc.d/trinketd @@ -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 -- 2.46.1