Bug fix and improvement - nanosleep

This commit is contained in:
Ashish Kumar Yadav 2020-12-29 13:56:08 +05:30
parent 3bd2416d86
commit 152b3668f7

View file

@ -203,19 +203,23 @@ statusloop()
getcmd(block, NILL); getcmd(block, NILL);
setroot(); setroot();
sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL); sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL);
/* main loop */ t.tv_sec = INTERVALs, t.tv_nsec = INTERVALn;
for (i = 1;; t.tv_sec = INTERVALs, t.tv_nsec = INTERVALn, i += 1) {
while (nanosleep(&t, &t) == -1) while (nanosleep(&t, &t) == -1)
if (errno != EINTR) { if (errno != EINTR) {
perror("statusloop - nanosleep"); perror("statusloop - nanosleep");
exit(1); exit(1);
} }
i = 1;
/* main loop */
for (;; i++) {
sigprocmask(SIG_BLOCK, &blocksigmask, NULL); sigprocmask(SIG_BLOCK, &blocksigmask, NULL);
for (Block *block = blocks; block->pathu; block++) for (Block *block = blocks; block->pathu; block++)
if (block->interval > 0 && i % block->interval == 0) if (block->interval > 0 && i % block->interval == 0)
getcmd(block, NILL); getcmd(block, NILL);
setroot(); setroot();
sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL); sigprocmask(SIG_UNBLOCK, &blocksigmask, NULL);
t.tv_sec = INTERVALs, t.tv_nsec = INTERVALn;
while (nanosleep(&t, &t) == -1);
} }
} }