Note that there are some explanatory texts on larger screens.

plurals
  1. POLinux receive signal break for ttycontrol program
    primarykey
    data
    text
    <p>I would like to receive SIGINT if my process controlling /dev/ttyS2 receives BREAK on a serial port. I run this program from a shell. From what I discovered only "the terminal is the controlling terminal of a foreground process group, it will cause a SIGINT to be sent to this foreground process group" I tried make process making controller of terminal but it fails. </p> <pre><code>#include &lt;sys/types.h&gt; #include &lt;sys/stat.h&gt; #include &lt;sys/ioctl.h&gt; #include &lt;unistd.h&gt; #include &lt;fcntl.h&gt; #include &lt;termios.h&gt; #include &lt;errno.h&gt; #include &lt;stdio.h&gt; #include &lt;signal.h&gt; #include &lt;string.h&gt; #define BAUDRATE B115200 #define MODEMDEVICE "/dev/ttyS2" #define _POSIX_SOURCE 1 /* POSIX compliant source */ #define FALSE 0 #define TRUE 1 __sighandler_t sighandle(int signum, __sighandler_t h) { fprintf(stderr, "BREAK DETECTED\n"); signal(SIGINT, (__sighandler_t) sighandle); return SIG_IGN; } volatile int STOP=FALSE; int main() { int fd,c, res; struct termios oldtio,newtio; char buf[255]; pid_t pid; signal(SIGINT, (__sighandler_t) sighandle); fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY ); if (fd &lt;0) {perror(MODEMDEVICE); return (-1); } tcgetattr(fd,&amp;oldtio); /* save current port settings */ memset(&amp;newtio, 0,sizeof(newtio)); newtio.c_cflag |= BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD | BRKINT; newtio.c_iflag &amp;= ~IGNBRK ; newtio.c_oflag = 0; /* set input mode (non-canonical, no echo,...) */ newtio.c_lflag = 0; newtio.c_cc[VTIME] = 0; /* inter-character timer unused */ newtio.c_cc[VMIN] = 1; /* blocking read until 5 chars received */ tcflush(fd, TCIFLUSH); tcsetattr(fd,TCSANOW,&amp;newtio); if( ioctl(fd, TIOCSCTTY, 1) &lt;0 ) { printf("Error number: %d\n", errno); } if ( tcsetpgrp(fd, tcgetpgrp(0) ) &lt; 0 ) { syslog(LOG_PERROR,"tcsetpgrp failed: %d " ,errno); syslog(LOG_PERROR,"EBADF is %d " ,EBADF); syslog(LOG_PERROR,"EINVAL is %d " ,EINVAL); syslog(LOG_PERROR,"ENOTTY is %d " ,ENOTTY); syslog(LOG_PERROR,"EPERM is %d " ,EPERM); } while (STOP==FALSE) { /* loop for input */ res = read(fd,buf,255); /* returns after 5 chars have been input */ buf[res]=0; /* so we can printf... */ printf(":%s:%d\n", buf, res); if (buf[0]=='z') {STOP=TRUE;} } tcsetattr(fd,TCSANOW,&amp;oldtio); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload