diff options
| author | onelin <oscar@nelin.dk> | 2026-05-01 20:07:18 +0000 |
|---|---|---|
| committer | onelin <oscar@nelin.dk> | 2026-05-01 20:07:18 +0000 |
| commit | 823c6deede5cbb4c5d584d30af063f2ea5694d9c (patch) | |
| tree | 11f44fba16310b11361399f0f53a37cbeeac0a17 /status.c | |
| parent | e0df63bec58088742f4419d94ffa3e87a74cb1b5 (diff) | |
Cleanup atexit & minor fixes
Diffstat (limited to 'status.c')
| -rw-r--r-- | status.c | 23 |
1 files changed, 12 insertions, 11 deletions
@@ -102,6 +102,12 @@ static struct element statusbar[] = { #undef ELEMENT }; +static void cleanup(void) { + if (mq_unlink("/status") == -1) { + fprintf(stderr, "Failed to unlink mq: %s\n", strerror(errno)); + } +} + // "fail fast strcmp", neat to find inequalities between strings static int ffast_strcmp(char* a, const char *const b) { int i = 0; @@ -416,7 +422,6 @@ update_element_thread(union sigval sv) { struct message_t msg; struct mq_data mq_data = *((struct mq_data*)sv.sival_ptr); - char* buf = mq_data.dstbuffer; if (mq_getattr(mq_data.mqfd, &attr) == -1) { fprintf(stderr, "Failed to get mq attributes: %s\n", strerror(errno)); return; @@ -454,7 +459,7 @@ update_element_thread(union sigval sv) { struct element* e = &statusbar[i]; assert(e->f != NULL); struct timespec now; - struct timespec next_fire = time_add(e->fire_previous, e->fire_interval); + struct timespec next_fire; clock_gettime(CLOCK_REALTIME, &now); memset(e->buf, 0, ELEMENT_STRBUF_SZ); @@ -472,7 +477,7 @@ update_element_thread(union sigval sv) { struct element* e = &statusbar[msg.element]; assert(e->f != NULL); struct timespec now; - struct timespec next_fire = time_add(e->fire_previous, e->fire_interval); + struct timespec next_fire; clock_gettime(CLOCK_REALTIME, &now); memset(e->buf, 0, ELEMENT_STRBUF_SZ); @@ -486,9 +491,10 @@ update_element_thread(union sigval sv) { ((struct mq_data*)(sv.sival_ptr))->next_update = next_fire; } } - } - update_statusbuffer(mq_data.dstbuffer); + + update_statusbuffer(mq_data.dstbuffer); + // EAGAIN indicates the queue is empty if (errno != EAGAIN) { fprintf(stderr, "Failed to receive mq message: %s\n", strerror(errno)); @@ -569,12 +575,7 @@ main(void) { } } - struct sigevent sev = (struct sigevent){ - .sigev_notify = SIGEV_THREAD, - .sigev_notify_function = update_element_thread, - .sigev_notify_attributes = NULL, - .sigev_value.sival_ptr = &mq_data, - }; + atexit(&cleanup); // We need to run update_element_thread in the first place to make sure we // empty the queue |
