Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating a timer which runs approximately every second and which is waiting for a key to be pressed (which i am not doing). While it is running it shows:

Objective-C
select : interrupted system call 
select : interrupted system call 
select : interrupted system call 
select : interrupted system call


struct sigaction s1;
static timer_t tid3;    
sigfillset(&s1.sa_mask);
s1.sa_flags = SA_SIGINFO;
s1.sa_sigaction = SignalHandler;
if (sigaction(SIGU, &s1, NULL) == -1) 
{
  perror("s1 failed");
  exit( EXIT_FAILURE );
}
printf("\nTimer %d is setting up \n",TimerIdentity);    
tid3=SetTimer(SIGU, 1000, 1);

// ---------- SET timer values -------------------
static struct sigevent sigev;
static timer_t tid;
static struct itimerspec itval;
static struct itimerspec oitval;
sigev.sigev_notify = SIGEV_SIGNAL;
sigev.sigev_signo = signo;
sigev.sigev_value.sival_ptr = &tid;

if (timer_create(CLOCK_REALTIME, &sigev, &tid) == 0) 
{
    itval.it_value.tv_sec = sec/1000;
    itval.it_value.tv_nsec = (long)(sec % 1000) * (1000000L);
    //itval.it_value.tv_nsec = 0;

    if (mode == 1) 
    {
        itval.it_interval.tv_sec = itval.it_value.tv_sec;
        itval.it_interval.tv_nsec = itval.it_value.tv_nsec;
    }
    if (timer_settime(tid, 0, &itval, NULL) == 0) 
    {
        printf("Timer_settime \n");
    }
    else
    {
        perror("time_settime error!");
    }
}

//---------------- SIGNAL HANDLER ---------------- 

void SignalHandler(int signo, siginfo_t* info, void* context)
{
    else if (signo == SIGU) // for keypad being pressed
   {
      calltimer3function();
   }

}

//-----------------calltimer3function------------------------  

unsigned char key5_debounce=0,key5_debounce_count=0;
calltimer3function()
{
    if(!key5_debounce)
   {
       if((GPIORead(INPUT_SW5)==0))
       {
          key5_debounce=1;
       }
   }
   if(key5_debounce)
   {
       if((GPIORead(INPUT_SW5)==0))
       {
          key5_debounce_count++;
       }
       else
       key5_debounce=0;

        if(key5_debounce_count>=KEY_DEBOUNCE)
        {
           printf("key5 pressed\n");
           extr_count=1;
           printf("\nDisplay menu called");
           display_menu();

          key5_debounce=0;
          key5_debounce_count=0;
        }

   }
}
Posted
Updated 28-Jan-16 21:24pm
v2
Comments
Jochen Arndt 29-Jan-16 3:27am    
I have formatted the code in your question to be better readable.

The first code line in your SignalHandler() function is

else if (signo == SIGU)

This will not compile. Please check it and edit your question using the green 'Improve question link'.

1 solution

The message indicates that a call to select() has been interrupted. But your code snippets did not contain a call to select().

There are a lot of questions and notes (besides my above comment about the incomplete handler function):

Why did you use sigfillset() when only handling specific signals?
It would be better to use sigempty() and add the signals that are handled.

What is SIGU?
It is not a standard signal.

A signal handler should call async-signal-safe functions only. See man 7 signal[^]. printf() does not belong to these functions. When display_menu() does what it sounds like, it should definitely not called by a signal handler.
 
Share this answer
 
Comments
Member 12294410 29-Jan-16 8:11am    
1. sorry about that #define SIGU SIGUSR2
2. i am not pressing any key so it will not execute (its an empty handler for now )
3. as timer is running fine but every time it run it show that message
select: interrupt system call
4. i am only calling calltimer3function no other printf or sync functions
Jochen Arndt 29-Jan-16 8:25am    
2. But it seems your intention is to do so later: It will not work that way.
3. Did you replaced sigfillset() and checked if that helps?
If not, you should show the code that calls select().

It looks like you have some kind of embedded device and want to act upon a key press where the key is connected to a GPIO port. Then I suggest to forget your actual implementation and look for alternatives.

If the system supports some kind of gpio_keys (a driver simulating input upon GPIO changes), you can use that.

If you still want to use a signal handler, you can create a socketpair and write into that from with the handler. Then you can watch that socketpair using another select() and did not have the restrictions of signal handlers.
Member 12294410 1-Feb-16 0:45am    
1. there is some hardware problem so i am unable to test sigemptyset() - give me a day
2. actually i am just started as an intern and working on small modules of a project and i am not very good with embbeded linux

here is code what i can find where select is used
can u help me what its doing (select function)

<pre lang="objc">char uart5_getchar(void)
{
//printf("gerchar started...\n");
fd_set set;
struct timeval timeout;
int rv;
char c[1];
FD_ZERO(&amp;set);
FD_SET(fd3,&amp;set);
timeout.tv_sec=0;
timeout.tv_usec=100000;
rv=select(fd3+1,&amp;set,NULL,NULL, &amp;timeout);
if(rv==-1)
perror("select");
else if (rv == 0)
return 0;
else
{
if(read(fd3,&amp;c,1) &gt; 0)
{
//printf("%c",c[0]);
return c[0];
}
else
printf("port failed to read...\n");
}
return 0;</pre>
Member 12294410 1-Feb-16 0:54am    
another can i use first empty to null the sigaction variable and than use
sigfillset to set sigaction variable value is this a valid and proper way to do ?
Jochen Arndt 1-Feb-16 3:21am    
See the description for those functions (man 3 sigfillset). They will initialise the sa_mask member of the sigaction structure. See man 3 sigaction:

sa_mask specifies a mask of signals which should be blocked (i.e., added to the signal mask of the thread in which the signal handler is invoked) during execution of the signal handler. In addition, the signal which triggered the handler will be blocked, unless the SA_NODEFER flag is used.

So when using sigfillset(), all other signals will be blocked while handling your signal (SIGUSR2 here). That is happening here. Each time SIGUSR2 occurs, the select() call from the above code snippet is interrupted and returns with -1 and errno set to EINTR.

Use sigemptyset(), and no signal is blocked except SIGUSR2 when actually handling it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900