Hi everybody,

I'm trying to handle signals in picogui, and have some problems. In
the enclosed sample code, I try to leave cleanly the pgui event loop
upon reception of a SIGUSR1 signal. 

Is it my code, or is there a bug that make this code fail ? It simply
ignores my ExitEventLoop request...

bye,
Fr�d�ric

-- 
Fr�d�ric Gobry    SMARTDATA       
      ---         http://www.smartdata.ch
Software Engineer Lausanne - Switzerland
                  +41 21 693 84 98
                                  
#include <picogui.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>

int release_me = 0;

void
handler (int sig)
{

  signal (SIGUSR1, handler);
}

int
my_select (int max_fd,
           fd_set * r_fd,
           fd_set * w_fd,
           fd_set * e_fd,
           struct timeval * timeout)
{
  int status;

  printf ("enter select\n");
  status = select (max_fd, r_fd, w_fd, e_fd, timeout);
  printf ("leave select\n");

  if (status == -1 && errno == EINTR) {
    FD_ZERO (r_fd);
    status = 1;

    release_me = 1;
    printf ("please let me out !\n");
  }

  return status;
}

void
my_bh (int result, fd_set * readfs) 
{
  printf ("in bottom handler\n");

  if (release_me) {
    release_me = 0;

    printf ("trying to release the loop\n");
    pgExitEventLoop ();
  }
}

int
main (int argc, char * argv [])
{
  pgInit (argc, argv);

  signal (SIGUSR1, handler);

  pgCustomizeSelect (my_select, my_bh);

  pgEventLoop ();
}

Attachment: msg00614/pgp00000.pgp
Description: PGP signature

Reply via email to