From: Charlie Root Date: Mon, 4 Apr 2016 13:44:58 +0000 (+0300) Subject: make it work with some workaround X-Git-Url: http://sigaev.ru/git/gitweb.cgi?a=commitdiff_plain;h=b827f82f2835499eba33653ab6379fc23be1f677;p=trinked.git make it work with some workaround --- diff --git a/main.c b/main.c index 3b689d8..c5ff3a9 100644 --- a/main.c +++ b/main.c @@ -7,10 +7,10 @@ * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -42,6 +42,7 @@ static int period = (300); /* in seconds */ static char* pidfile = NULL; static char* logfile = NULL; static bool daemonize = false; +static bool workaround = false; static char tfile[MAXPATHLEN], ofile[MAXPATHLEN]; @@ -51,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]"); + puts("trinketd [-d] [-l logfile] [-p pidfile] [-P period] [-D datadir] [-w]"); if (errmsg) { puts(""); @@ -76,6 +77,9 @@ restart: } while(42) { + if (workaround) + trinketPing(); + if (trinketGetCumDose(&curDose) != ERR_OK) { fprintf(stderr, "trinketGetCumDose fails\n"); trinketClose(); @@ -127,7 +131,7 @@ main(int argn, char* argv[]) { logfd; opterr = 0; - while((i=getopt(argn,argv,"dD:p:P:h")) != EOF) { + while((i=getopt(argn,argv,"dD:p:P:wh")) != EOF) { switch(i) { case 'd': daemonize = true; @@ -141,6 +145,9 @@ main(int argn, char* argv[]) { case 'P': period = atoi(optarg); break; + case 'w': + workaround = true; + break; case 'h': default: usage(NULL); diff --git a/trinket.c b/trinket.c index ba5fdb3..8f2cdc9 100644 --- a/trinket.c +++ b/trinket.c @@ -7,10 +7,10 @@ * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -105,6 +105,7 @@ dumpBuf(char *msg, uint8_t *buf, int len) { TrinketErrorCode trinketOpen() { + TrinketErrorCode r; #ifndef NDEBUG int i; @@ -119,7 +120,9 @@ trinketOpen() { return ERR_ERROR; } - return trinketPing(); + if ((r = trinketPing()) != ERR_OK) + trinketClose(); + return r; } void diff --git a/trinket.h b/trinket.h index b5bb5ca..2f7fba9 100644 --- a/trinket.h +++ b/trinket.h @@ -7,10 +7,10 @@ * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE