Cannot catch SIGINT while serial break condition occurs


 
Thread Tools Search this Thread
Top Forums Programming Cannot catch SIGINT while serial break condition occurs
# 1  
Old 09-10-2007
Cannot catch SIGINT while serial break condition occurs

I setup termios structure with IGNBRK is not set and BRKINT is set.
To allow the process to receive signals I call: fcntl(fd, F_SETOWN, getpid());
I have made a signal handler to catch all signals. I can catch SIGINT when pressing ctrl+c but when I send break signal over serial then it cannot catch SIGINT.
Is there anything I'm doing wrong?
Any suggestions and code samples would be appreciated.

Thanks
# 2  
Old 09-10-2007
fcntl has nothing to do with the break key. BRKINT only works with the controlling tty. The INT character, which you have mapped to CNTL-C, also only works with the controlling TTY. So the same keyboard that is sending the cntl-c character should be able to send the break signal. If that keyboard is a PC instead of a true ascii terminal, the program in the pc make need a special operation to send a break signal out the serial port. As one example see: SUMMARY: Send Break Signal Through HyperTerminal
# 3  
Old 09-11-2007
I use another computer to send data and break signal over serial. When my program receives data then i get SIGIO signal and i can use read to get the received data. But when I send break signal from the other computer then i receive no signal.
In manpage i can read that :" BRKINT If IGNBRK is set, a BREAK is ignored. If it is not set but RKINT is set, then a BREAK causes the input and output queues to be flushed, and if the terminal is the controlling terminal of a foreground process group, it will cause a SIGINT to be sent to this foreground process group.", but I'm not sure how to become controlling terminal of a foreground process.
I have no problem seting break condition on the serial line, but the problem is how to detect the break condition, without polling serial break counters or other things that stores information about break conditions.
# 4  
Old 09-11-2007
Like I said: "BRKINT only works with the controlling tty."
# 5  
Old 09-12-2007
Any specific functions to call to become a controlling terminal of ttyS0 for example? I have no idea how to achive that condition. Can ioctl(fd, TIOCSCTTY, (char *)NULL) or ioctl(fd, TIOCSCTTY, (char *)1) be used to become a controlling tty of ttyS0. If you have any specific suggestions then go a head.
# 6  
Old 09-12-2007
ioctl TIOCSCTTY always returns -1 (Operation not permitted) even if I am super user.
Is it even possible to receive SIGINT from serial driver without being super user?

Last edited by gzz; 09-12-2007 at 08:49 AM..
# 7  
Old 09-17-2007
maybe this thread should be moevd to programming forum, but if I started this here I wont start another thread for the same pbroblem.
-------------------------------------------------------------------------------------------------------
What am I missing?
What needs to be added to receive SIGINT from serial driver?

#include <termios.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/signal.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#define BAUDRATE B38400
#define MODEMDEVICE "/dev/ttyS0"
#define _POSIX_SOURCE 1 /* POSIX compliant source */
#include <unistd.h>
#include <errno.h>
#include <string.h>
void signal_handler_SIGINT (int status); /* definition of signal handler */

main()
{
int fd,c, res;
struct termios options;
char buf[255];
int pid;

fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (fd <0) {perror(MODEMDEVICE); exit(-1); }

signal(SIGINT,signal_handler_SIGINT);

fcntl(fd, F_SETOWN, getpid());
/* Make the file descriptor asynchronous (the manual page says only
O_APPEND and O_NONBLOCK, will work with F_SETFL...) */
fcntl(fd, F_SETFL, FASYNC);

memset (&options, 0x00, sizeof (options));
options.c_cflag |= (CREAD);
options.c_cflag |= CLOCAL;
options.c_cflag |= CS8; // Select 8 l2_data bits
options.c_iflag |= (BRKINT);
// options.c_cc[VMIN] = 1;
options.c_cc[VTIME] = 1;
if(ioctl(fd,TIOCSCTTY, 1) == -1)
printf("eh %s\n",strerror(errno));

}

/***************************************************************************
* signal handler. sets wait_flag to FALSE, to indicate above loop that *
* characters have been received. *
***************************************************************************/

void signal_handler_SIGINT (int status)
{
printf("received SIGINT signal.\n");
exit(0);
}
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to execute condition until an event occurs

I need a script to keep polling "receive_dir" directory till "stopfile" get written in the directory. This has to run despite empty directory. So far i have this but fails if receive_dir is empty with no files with "unary operator expected". Help !! #!/usr/bin/ksh until do for i... (1 Reply)
Discussion started by: iaav
1 Replies

2. Shell Programming and Scripting

Always pass SIGINT in ksh

The following command will run and wait for input from the user. /usr/sap/SAP/webdisp/wdispmon pf=/usr/sap/SAP/webdisp/profile What I would like to do is (in one command): - Add the above line to a ksh script - Receive the output - and send a SIGINT I have seen many posts on how to... (3 Replies)
Discussion started by: sapsid
3 Replies

3. UNIX for Dummies Questions & Answers

SIGINT issue

May i know what are the possible causes for SIGINT other than ctrl-c? Thanks (17 Replies)
Discussion started by: pandeesh
17 Replies

4. Shell Programming and Scripting

Sh script sends SIGINT to a process

Hello, What I want to accomplish is this: I have made a very simple script that runs 2 commands, polipo proxy and tor. The script runs successfully and the output of tor is visible to the screen. I am using the trap command in order to catch the ctrl+c button combo in order to stop polipo... (5 Replies)
Discussion started by: redsolja
5 Replies

5. Ubuntu

Ubuntu 9.04 Serial application to telnet to serial device

Hello! I am working on an application which reads environmental instruments which have serial ports. The application requires a serial port to be present to talk to the device (i.e. /dev/ttyS0 ). In some instances the environmental devices will be 100's of yards away from the computer, so a... (5 Replies)
Discussion started by: mvona
5 Replies

6. Shell Programming and Scripting

How to break a loop if condition is met

I am having trouble figuring this code I want to grep a text from a file and if it match certain text it break out of the loop or it should continue searching for the text Here is what I have written but it isn't working while true f=`grep 'END OF STATUS REPORT' filename` do if ... (9 Replies)
Discussion started by: Issemael
9 Replies

7. Shell Programming and Scripting

Intercepting SIGINT in a bash script

I've written a bash script which captures video with DVgrab. Because of the nature of the tapes that I am digitizing, sometimes I want to quit capturing before the time that I set for DVgrab. When this is the case I press Ctrl-c and DVgrab exits cleanly, my problem is that there is additional... (5 Replies)
Discussion started by: Starcast
5 Replies

8. Programming

[C] fgets problem with SIGINT singlal!!!

Hi all, I have this method to read a string from a STDIN: void readLine(char* inputBuffer){ fgets (inputBuffer, MAX_LINE, stdin); fflush(stdin); /* remove '\n' char from string */ if(strlen(inputBuffer) != 0) inputBuffer = '\0'; } All work fine but if i... (1 Reply)
Discussion started by: hurricane86
1 Replies

9. Solaris

Forcing OpenBoot: H/W Solution to no <BREAK> function on USB Serial

Please note: This solution does require some soldering ability. If, like me today, you really really need to get into OpenBoot on a non booting Solaris machine (in my case an Ultra 5) but your USB dongle won't send <BREAK> then here is a -really- simple hardware hack that works a treat: ... (0 Replies)
Discussion started by: HideawayStudio
0 Replies

10. Programming

Problem with handling SIGINT

For a program I am designing, which involves handling the keyboard input Ctrl^c (SIGINT), it is taking ages for the program to actually recognise and perform the corresponding action whenever I run it and hit Ctrl^C at the CL. I have to do at least 3 Ctrl^Cs before the program will actually... (3 Replies)
Discussion started by: JamesGoh
3 Replies
Login or Register to Ask a Question