Něco takového jsem tuhle psal. Tu je lehce upravená verze.
V tty1 to pude přerušit jenom Ctrl+\, přepnutím tty a (rozumě pomalým) napsáním obsahu proměnné pass ("ayy lmao").
Kdyby někdo věděl, proč to po napsání pass ještě před vypnutím znovu vyplivne poslední řádku, rád se nechám poučit.
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <time.h>
#include <unistd.h>
void sig_exit(int sig)
{
/*
sigflag_exit = 1;
fprintf (stderr, "received signal %d: exiting\n", sig);
return;
*/
}
int main(int argc, char **argv) {
signal(SIGHUP, &sig_exit);
signal(SIGINT, &sig_exit);
signal(SIGPIPE, &sig_exit);
signal(SIGTERM, &sig_exit);
signal(SIGCHLD, &sig_exit);
size_t wa;
struct termios tms;
tcgetattr(0, &tms);
tms.c_cc[VMIN] = 0;
tms.c_cc[VTIME] = 0;
tms.c_lflag = tms.c_lflag & ~ICANON;
tcsetattr(0, TCSANOW, &tms);
char *buf = calloc(20, sizeof(char));
int m,n;
m = 0;
char *pass = "ayy lmao";
while ((n = read(0, buf, 20)) != -1){
if (!n){
nanosleep(&(struct timespec) {0,100}, NULL);
continue;
}
buf[n] = '\0';
printf("%c", *buf);
if (*buf == pass[m]) ++m;
else m = 0;
if (m == strlen(pass)) break;
}
return 0;
}