summaryrefslogtreecommitdiff
path: root/anzeige.c
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-10-26 11:21:08 +0200
committerErich Eckner <git@eckner.net>2018-10-26 11:21:08 +0200
commit8b40ddb3f47c1faa3c671e701426c4a2c167022c (patch)
treee863ab44bbba8fcc4325f0038dac88464c346456 /anzeige.c
parent2be45d6c729a12213ef690aab3a21ec7be60bed2 (diff)
downloadanzeige-8b40ddb3f47c1faa3c671e701426c4a2c167022c.tar.xz
fetch signals
Diffstat (limited to 'anzeige.c')
-rw-r--r--anzeige.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/anzeige.c b/anzeige.c
index 52116bf..60ac8f9 100644
--- a/anzeige.c
+++ b/anzeige.c
@@ -8,17 +8,20 @@
#include <errno.h>
#include <string.h>
#include <pthread.h>
+#include <signal.h>
#include "fonts.h"
#include "input_gadgets.h"
#include "multiplexer.h"
void drop_privileges();
+void handle_signals(int signo);
+
+t_display_data display_data;
int main(int argc, char **argv)
{
pthread_t thread_id;
- t_display_data display_data;
int ret_val;
#define TEXT_BUFFER_LENGTH 256
char *text_buffer;
@@ -33,6 +36,21 @@ int main(int argc, char **argv)
// Drop root privileges
drop_privileges();
+ // set up / register signal handler
+ struct sigaction new_action, old_action;
+ new_action.sa_handler = handle_signals;
+ sigemptyset (&new_action.sa_mask);
+ new_action.sa_flags = 0;
+ sigaction (SIGINT, NULL, &old_action);
+ if (old_action.sa_handler != SIG_IGN)
+ sigaction (SIGINT, &new_action, NULL);
+ sigaction (SIGHUP, NULL, &old_action);
+ if (old_action.sa_handler != SIG_IGN)
+ sigaction (SIGHUP, &new_action, NULL);
+ sigaction (SIGTERM, NULL, &old_action);
+ if (old_action.sa_handler != SIG_IGN)
+ sigaction (SIGTERM, &new_action, NULL);struct sigaction action;
+
/************************************************************************\
* You are about to change the GPIO settings of your computer. *
* Mess this up and it will stop working! *
@@ -77,11 +95,13 @@ int main(int argc, char **argv)
scroll_buffers[0].scroll_len = render(text_buffer, TEXT_BUFFER_LENGTH, scroll_buffers[0].buf, sizeof(scroll_buffers[0].buf), 1);
- for (i=0; i>=0; i++) {
+ i=0;
+ while (display_data.keep_running) {
usleep(100000);
for (j=0; j<40; j++)
display_data.buf[(display_data.should_buf+1)%3][j] = scroll_buffers[0].buf[(i+j) % scroll_buffers[0].scroll_len];
display_data.should_buf = (display_data.should_buf+1)%3;
+ i++;
}
free(text_buffer);
@@ -108,3 +128,11 @@ void drop_privileges()
exit(-1);
}
} // drop_root
+
+void handle_signals(int signo)
+{
+ if ((signo == SIGINT) || (signo == SIGHUP) || (signo == SIGTERM)) {
+ fprintf(stderr, "stopping\n");
+ display_data.keep_running = 0;
+ }
+}