Interrupted system calls (socket read) , EINTR and SIGTERM

Hi All,

  I have a scenario like this


  Function 1

 {

       Send a message 
       Wait for the reply for that message in a while(1) loop

}


Function 2

{
  Processes requests and replies.

I have a code snippet like this

while(1)
  {

      while((n = read(connection->sock, buf, len)) < 0 && errno ==
EINTR);

     if (n>0)
               return n;
     if(n==0)
           close the connection

        if(errno==EINTR)
             retry the read call
  

}


In one of the scenario I receive SIGTERM, and code switched to the
signal handler. From the
signal handler I will do a siglong jump and do some celan up
processing.

   

If I receive the signal when middle of the read doing some thing,
after signal handler return. The read function trying to read some
thing on the socket and got hung there.Is it because, after returnig
from the signal handler, I lost the context to previous read, and the
other guy continuously looking for the reply for this message. So the
read() got the garbage after return from the signal handler
Some sample log 
---------------
Sent the message 0x307 looking for reply
Entering Readit before while(1) of sock read()with len 4000<---signal
hit
 TADI:Iam in handle_arbot_sig and the signal mask before calling
siglongjmp:
  TADI: abortsig  with signo 15 sig_flag 1
 
 Entering Readit before while(1) of sock read() 
 sock read() n> 0 cas and returning 48 bytese
 Entering Readit before while(1) of sock read()
<Got hung here>

If I receive a signal, not in the middle of the read everyting  I will
get a reply for the message which I sent.

What could be the possible solution.

This what I thought, set a global flag in the signal handler, check
that flag in the Function 2 and return -1 from there, this will make
the thread 1 guy to take appropriate action and come out of the while
loop.


I couldn't understad why the read is hung after return from the signal
handler,is it because of I am siglongjumping  in the signal handler,
After return to the read in Function 2, I lost the previous read
context.

Looking for suggestions.

Thanks
-Tadi
0
sudhakar
11/19/2004 11:12:30 AM
comp.unix.programmer 10730 articles. 0 followers. kokososo56 (349) is leader. Post Follow

1 Replies
1332 Views

Similar Articles

[PageSpeed] 0
Tadi <sudhakar.tadi@gmail.com> wrote:
>   I have a scenario like this
>   Function 1

>  {
>        Send a message 
>        Wait for the reply for that message in a while(1) loop
> }

> Function 2

> {
>   Processes requests and replies.

> I have a code snippet like this

> while(1)
>   {
>       while((n = read(connection->sock, buf, len)) < 0 && errno ==
> EINTR);
>      if (n>0)
>                return n;
>      if(n==0)
>            close the connection

>         if(errno==EINTR)
>              retry the read call

How is this supposed to happen? You already checked errno within the
loop where you are reading. And you are supposed to check errno only
when the call returned -1, otherwise the value stored in errno does
not have any significance and shouldn't be evaluated.

> }

> In one of the scenario I receive SIGTERM, and code switched to the
> signal handler. From the
> signal handler I will do a siglong jump and do some celan up
> processing.

Why a longjmp()? Sounds rather dangerous unless you know extremely
well what you're doing... And how do you want to return from the
signal handler back to the function that does the reading/writing
after a longjmp() call?

> If I receive the signal when middle of the read doing some thing,

A read() call is interrupted by a signal only before any data are
read, never while the read is already in progress. But I don't
know if you are aware that read() can return less bytes than you
are waiting for. If you are sure that more data are going to come
you have to call read() again. The same holds for write(), so
always check how much got read or written and, if reasonable, call
the function again for the rest of the data.

> after signal handler return. The read function trying to read some
> thing on the socket and got hung there.Is it because, after returnig
> from the signal handler, I lost the context to previous read, and the
> other guy continuously looking for the reply for this message. So the
> read() got the garbage after return from the signal handler

Sorry, but I am at a loss to understand what you're writing here.
What's "the context to previous read"?

                                  Regards, Jens
-- 
  \   Jens Thoms Toerring  ___  Jens.Toerring@physik.fu-berlin.de
   \__________________________  http://www.toerring.de
0
Jens
11/19/2004 1:03:18 PM
Reply:
Similar Artilces:

interrupts
hello, I am confused with software and hardware interrupts and also what are top half and bottom half interrupts and differene between them. can anyone help to explain me. i did google search but i got some old links and i am not sure whether kernel internals has changed from 1996 or not?because links i got from linux journal. rahul8143@gmail.com wrote: > hello, > I am confused with software and hardware interrupts and also > what are top half and bottom half interrupts and differene between > them. can anyone help to explain me. i did google search but i got s...

Linux crapware: victim can't empty the trash... system freezes
"Ubuntu 14.04. Just started happening, I am unable to completely empty the trash and when I try, my computer freezes. I used the terminal to empty the trash and some folders did delete, but some folders still won't go and when I try my computer freezes. What can I do?" 1 post at http://ubuntuforums.org/showthread.php?t=2265140 Let the Trash build up... enjoy the stench of rotting Linux. On Thu, 12 Feb 2015 19:26:01 -0500, DFS <nospam@dfs.com> wrote: > "Ubuntu 14.04. Just started happening, I am unable to completely empty > the trash and whe...

Problem with reading in a listing file
The problem below has caused my headache for a long time.=0A=C2=A0=0Afilena= me list "/Unix/report/demo.rpt ";=0A=C2=A0=0A*Read in data from a listing;= =0Adata test;=0A=C2=A0=C2=A0=C2=A0=C2=A0 infile list delimiter=3D'0C'x miss= over pad;=0A=C2=A0=C2=A0=C2=A0=C2=A0 format lis $120.;=0A=C2=A0=C2=A0=C2=A0= =C2=A0 input lis;=0Arun;=0Aproc print;run;=0A=C2=A0=0AThe following is part= of the original listing (a =E2=80=98x=E2=80=99 is used to represent a spac= e): =0A=C2=A0=0AROBERTxxx5KG=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 =0Axxxxxxxxxxxx5KG=C2=A0=C2=A0=C2=A0=C2=A0...

ping program to probe a remote system
hi experts, i have a ping program written in c on linux platform. it is working fine but it has a bug.lets say i am probing a remote system with IP 192.168.15.1. every second ICMP datagram is sent. now if i deactivate the NIC then the ping just stops and does not return any error message. It works fine if i use unicast address and select works fine .. but if i use a broadcast IP (192.168.15.255) then the ping just hangs up if the destination system is suddenly shutdown or NIC is deactivated. although ethereal flags an error message that the network is down, my program is not able handle this c...

Re: reading a simple delimited file...
Add the option DSD to the INFILE statement. On Jan 4, 2008 10:16 AM, Gradowsky <marchi.gianluca@libero.it> wrote: > Hi all, > > a "simple" input from an external file is getting me crazy.... > > I am trying to read into a dataset the following semicolon delimited > file named "file.csv": > > v1;v2;v3 > abc;def;ghi > jkl;;yhi > ;iuu;jak > ass;asz; > ;;awo > > where first row are variables names. > > This is the code I am using: > > data ds1; > infile 'c:\file.csv' delimiter=';' firstobs=2 miss...

I wish I could do this with my Pick system...
Let's stir up some discussion... When you're working with your system, you'll undoubtedly hit some point where things become difficult, and you say to yourself "I just wish I could do ...this". I hit that point every day, whether with MV environments, .NET, PHP, or any of the tools or products I work with. I know I can find or write tools to get over the obstacles, or maybe I just need to read more documentation. But I'd rather not have that bump in the road in the first place. Why is that obstacle there? Why can't I just do ...this? Do I take t...

Vectorizing a the same function called many times
I have a function, let's call it SC, that calls a lot of loops. There's nothing I can do about that, since each iteration depends on the previous iteration. For example, h = SC(a,b,c). SC outputs a 1xM vector. I have to run this function on a lot of different sets of variables. The outputs of each SC function call are unrelated to each other. Currently, I'm looping through each set of data and performing SC each time. e.g. for i = 1:n h(:,i)= SC(a{i},b{i},c{i}); end I was wondering if there was a way to speed this up. Specifically, I'm wondering if performing cellfun on SC f...

SS5 TurboSparc 170 Mhz System (w/s24!)
For auction,SS5 TurboSparc 170 Mhz System with an s24 frame buffer; http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=3037992491&category=11224&rd=1 enjoy, Ben ...

Interrupts in U-boot
I am attempting to implement interrupt in u-boot, is there any example code. I have noticed that some of the code is implemented, however there are messages which say there is no IRQ support in u-boot. What does this mean? What is the state of u-boot in this regard? It seems u-boot is slower than linux? Are there any reseaons an AT91RM9200 would work slower? Clearly thats my target. Thanks Nicholas Karsen "Nicholas Karsen" <nicholas@sanpeople.com> writes: >I am attempting to implement interrupt in u-boot, is >there any example code. I have noticed that some of Su...

Linux Interrupt handling
Hi all! I would be most grateful for your help. I have to implement an interrupt handler triggered by a hardware interrupt under Linux. As far as I understand the problem, I need to write a Linux kernel driver which I suppose may be quite tedious for an inexperienced Linux driver writer like I am. I would appreciate it very much if someone could say something on this problem or send a code example Thanks & regards, Branko Branko schrieb: > > Hi all! > > I would be most grateful for your help. > > I have to implement an interrupt handler triggere...

Polling a file without using huge amount of system resources
I would like to check a file continuously to see if something has been written to it. If so, immediately run a script. I can do this successfully by repeatedly polling the file, as shown below, but this uses up lots of system resources. I can, of course, add a 'sleep' to the while loop, which reduces the drag on the system, but it also slows down the response time. Can someone recommend a replacement for this code using some more elegant means? Ideally, I would like to set some sort of interrupt as soon as the \n character is written to the file. That way, I can avoid doing any p...

IJCAI 2013 Angry Birds AI Competition
*************************************************************** Call for Participation IJCAI 2013 Angry Birds AI Competition http://www.aibirds.org Beijing, China, 6-9 August 2013 *************************************************************** Angry Birds is a popular video game where players shoot birds in order to destroy pigs protected by complicated structures. The task of this competition is to develop an intelligent Angry Birds playing agent that is able to successfully play the game autonomously a...

audio SNDCTL_DSP_SYNC Interrupted system call
I've been trying to set up appointment notification functions. Everything seems to be working (the mode line is correctly impacted) except that I do not get any sound. I just get the following error message: audio SNDCTL_DSP_SYNC Interrupted system call Here is what is in my placed in my config file. (setq appt-display-duration t) (setq appt-audible t) (setq appt-display-mode-line t) (appt-activate 1) About my Linux box: Ubuntu 8.04, kernel 2.6.24-18-generic XEmacs 21.4.20 "Double Solitaire" configured for `i486-pc-linux'. Thanks for y...

Apple Q4 Conference Call
get ready for some financial excitement... could be a record breaker on several levels... mac sales are off the charts, that's for sure... so tune in on Wednesday... ----- Appleļæ½s conference call webcast discussing Q4 - 2006 financial results will begin at 2pm PT/5pm ET on Wednesday, October 18, 2006. http://www.apple.com/quicktime/qtv/earningsq406/ Oxford wrote: > get ready for some financial excitement... could be a record breaker on > several levels... mac sales are off the charts, that's for sure... so > tune in on Wednesday... "Off the charts" being a ...

A new reader? Welcome to comp.os.linux.setup, read this first if you're new here (FAQ) #289
Netiquette 2006-04#1 New reader? Great! Welcome! Here's how to make best use of this newsgroup and get yourself a slice of the best help available. Now read on ... TESTING YOUR CONNECTION Errm, first a delicate point. Often users accessing a forum like this for the first time don't realize that posts don't show up immediately, certainly not for several minutes, and maybe not for some hours. In the old days, it took as long as the camel bearing the news took! So they tend to post "test" ...

RichTextBox Control
Hello, I have searched the net for a routine that will allow me to read 1 line of text at a time from a RichTextBox control and then do the same for every line of text in the control. Each line in the control has a fixed length and each line is the same length as all others. There may be 5000 lines of text in the control and I have to be able to read each one and then analyze it. So far I'm going to brute force it by writing the contents of the RichTextBox to a file using SaveFile, then opening the file using Open, using Line Input #x and going from there. Is there a more ele...

Best Resources to Buy MAC Systems at Affordable Prices
Buy Used Laptop and notebook at Affordable Prices http://laptop4you.blogspot.com/2007/04/best-resources-to-buy-used-laptop-at_12.html ...

System News for Sun Users: TOC Vol 114 Issue 3: August 13 to August 19
The "System News for Sun Users" newsletters are sent each week to 50,000+ subscribers around the world. It is also posted to several newsgroups and to http://sun.systemnews.com You are encouraged to sign up for your own subscription to have a tailored newsletter delivered to you via email. The newsletter is built dynamically for each subscriber. You choose the technology areas that interest you. Each week the news is grouped into sections. Your newsletter is built from the sections that are available that match your selections. Current sections include: News, Feature...

US-TX-Austin: Sr. Systems Eng.,10yrs comm systems eng. exp, WPAN/WLAN; Perm (45313532407)
US-TX-Austin: Sr. Systems Eng.,10yrs comm systems eng. exp, WPAN/WLAN; Perm (45313532407) ========================================================================================= Position: Sr. Systems Eng. Reference: SMC01566 Location: Austin TX Duration: Perm Skills: BSEE required, MSEE preferred, with a PhDEE a plus. 10 years of applicable communications systems engineering experience is required, with 15+ years experience preferred. Communications systems design and analysis experience required. ...

debugging a system freeze
Hi, I have a WLAN driver that freezes the system when I associate to an AP!! It does not hit the debugger (softice). This happens only on a DELL dual CPU machine (2 XEON processors running @ 2GHz each). I have a similar machine with CPUs running @ 1.7 MHz & there the driver is perfectly fine. I figure this has something to do with timing. But, how will I debug this if it simply hangs? Any clues? Again, on the same server, if i turn off the 2nd CPU, everything is fine. TIA HV harishv@rocketmail.com wrote: > I have a WLAN driver that freezes the system when I associa...

US-MI-Auburn Hills: Systems Admin, J2EE Technologies, EJB, JMS, Portal, UNIX; 9M (45335832408)
US-MI-Auburn Hills: Systems Admin, J2EE Technologies, EJB, JMS, Portal, UNIX; 9M (45335832408) ============================================================================================== Position: Systems Admin Reference: SMC01854 Location: Auburn Hills MI Duration: 9M Skills: J2EE Technologies WebSphere Prefered WebSphere 3.5, 4.0 to 5.0 migration EJB and JMS and MQseries configuration Business Intelligence Technologies Portal Technologies Content Management Tech ...

Call for Participation
18th Software Engineering Process Group Conference (SEPG 2006) March 6-9, 2006 Gaylord Opryland Nashville, Tennessee Web: http://www.sei.cmu.edu/sepg/ **** All inquiries to customer-relations@sei.cmu.edu **** The Software Engineering Process Group (SEPG) Conference is the world's leading annual conference and exhibit showcase for process improvement. Now in its 18th year, the conference brings together international representatives from government, industry, and academia for a global perspective on process improvement activities and results. The four-day event is gea...

MinGW - Variadic Templates
I am attemting to compile the code below, using MinGW on windows, as below: g++ -std=c++0x -Wall -Os -o varTest varTest.cpp I receive the following compilation error: In file included from d:\apps\qt\2009.05\mingw\bin\../lib/gcc/ mingw32/4.4.0/incude/c++/bits/postypes.h:42, from d:\apps\qt\2009.05\mingw\bin\../lib/gcc/mingw32/4.4.0/incude/c++/ iosfwd:42, from d:\apps\qt\2009.05\mingw\bin\../lib/gcc/mingw32/4.4.0/incude/c++/ ios:39, from d:\apps\qt\2009.05\mingw\bin\../lib/gcc/mingw32/4.4.0/incude/c++/ ostream:40, from d:\apps\qt\2009.05\mingw\bin\../lib/gcc/mingw32/4.4.0/incude/...

US-TX-Austin: Sr. Systems Eng.,Verilog, Simulation tools, DSP, FPGA, IC routing; (45336357606)
US-TX-Austin: Sr. Systems Eng.,Verilog, Simulation tools, DSP, FPGA, IC routing; (45336357606) ============================================================================================== Position: Sr. Systems Eng. Reference: SMC01859 Location: Austin TX Duration: C-H Skills: BSEE (MSEE preferred) with 3-8 yrs experience. Should have skills in verilog, simulation tools, DSP architectures, FPGA implementation tools, IC routing and synthesis tools, and audio signal processing. Communication knowledge and...

JButton inputStream to System.in
Hello, I have an applet that I would like to gather the keyboard input once someone clicks on the JButton. At first I thought that I could just read System.in, but that provided no solution. I have since found that to get the input once the JButton has focus it needs to have a KeyListener added. However I would like to push the KeyListener keyTyped character to the System Input Stream. Any ideas on how I can do this? My best guess, but does not work is below. public void addJButton(){ JButton jbtNext = new JButton("Click Here To Take Keyboard Input"); jbtNex...