Milan Stephan
Fotografie & IT

Zurück zur SP2 Übersicht

T05-troll.c

#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>


static void handler(int signum) {
	(void) signum;

	int errno_backup = errno;

	const char *buf = "How do I exit vim?";
	write(STDOUT_FILENO, buf, strlen(buf));

	errno = errno_backup;
}

int main(void) {

	struct sigaction act = {
		.sa_handler = handler,
		.sa_flags = SA_RESTART,
	};
	sigemptyset(&act.sa_mask);

	sigaction(SIGINT, &act, NULL);


	while (1) {
		printf(".");
		fflush(stdout);
		sleep(1);
	}

}