But in the program below, breaks is never incrementing, nor is anything
returned by the read (other than a zero) when a break condition happens,
and it detects characters properly. It also detects control-c causing
sigint on the console (which does increment breaks).
Or is there something wrong in the kernel not generating or masking
signals, or otherwise not propogating them up to the user program?
---#include <unistd.h> #include <stdio.h> #include <fcntl.h> #include <termios.h> #include <sys/ioctl.h> #include <signal.h>
int breaks;
__sighandler_t sighandle(int signum, __sighandler_t h) { breaks++; fprintf(stderr, "BREAK DETECTED\n"); signal(SIGINT, (__sighandler_t) sighandle); return SIG_IGN; }
int main(int argc, char *argv[]) { int i; unsigned char skresp[2];
int serfd; int spd = -1; struct termios tty;
breaks = 0; signal(SIGINT, (__sighandler_t) sighandle);
serfd = open("/dev/modem", O_RDWR);
tcgetattr(serfd, &tty);
spd = B9600; cfsetospeed(&tty, (speed_t) spd); cfsetispeed(&tty, (speed_t) spd);
tty.c_iflag = BRKINT; tty.c_lflag = ISIG; tty.c_cflag = CS8 | CREAD | CLOCAL;
tcsetattr(serfd, TCSANOW, &tty);
while (1) { i = read(serfd, skresp, 1); if (i) fprintf(stderr, "%d %d %02x\n", breaks, i, skresp[0]); } }