diff options
| author | Loic Guegan <manzerbredes@mailbox.org> | 2023-07-16 14:50:53 +0200 |
|---|---|---|
| committer | Loic Guegan <manzerbredes@mailbox.org> | 2023-07-16 14:50:53 +0200 |
| commit | 33c54437949aaefacc3326a1c2d577db072cbacd (patch) | |
| tree | 985241d4701cf57a8c7912a3a97ebe3bf1acc00d /src/logger.c | |
| parent | e0fdde7cd04550e6a13aa626d2ef6517bf6e5608 (diff) | |
Minor changes
Diffstat (limited to 'src/logger.c')
| -rw-r--r-- | src/logger.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/logger.c b/src/logger.c index 4e9aee9..842aec7 100644 --- a/src/logger.c +++ b/src/logger.c @@ -8,6 +8,7 @@ #include <sys/stat.h> #include "utils.h" #include <time.h> +#include <signal.h> #ifndef LOGGER_DELAY #define LOGGER_DELAY 0 @@ -18,6 +19,14 @@ char *__client; char __logdir[STATIC_LEN]; char __regpower[STATIC_LEN]; int __loginterval; +unsigned char __stop=0; + +void sighandler(int signo){ + if (signo == SIGINT){ + printf("Stopping...\n"); + __stop=1; + } +} int main (int argc, char *argv []) { @@ -41,6 +50,7 @@ int main (int argc, char *argv []) strcat(__regpower,INA260_POWER_REGISTER); //----- Sanity checks + signal(SIGINT,sighandler); mkdirp(__logdir); if(__loginterval<MIN_INTERVAL){ printf("Log interval is too small (min=%ds)\n",MIN_INTERVAL); @@ -62,7 +72,7 @@ int main (int argc, char *argv []) time_t interval; struct timespec power_ts; - while(1){ + while(!__stop){ interval=INTERVAL(__loginterval); *logfilepath='\0'; sprintf(logfilepath,"%s/%ld",__logdir,interval); |
