Catching Ctrl-C SIGINT

From: Christopher Broeg (broeg_at_astro.uni-jena.de~)
Date: 01/17/05


Date: Mon, 17 Jan 2005 13:26:06 +0100

Hi,

I am having some trouble with protected types. I am trying to do some
cleanup work if the user presses Ctrl-C SIGINT.
For this I wrote a little test program. The problem is getting the
information about the raised interrupt back to the main program. I tried
using a little task that calls a entry in a protected type:

with Catch_Interrupt;

with Ada.Text_IO;use Ada.Text_IO;
procedure Test1 is
    Stop: exception;

    task Get_Info is
       entry Stop;
    end Get_info;
    task body Get_Info is
    begin
       loop
          Catch_Interrupt.Event.wait;
         -- here comes the code that handles the interrupt received
          select
             accept Stop do
                Stop;
             end Stop;
          or
             terminate;
          end select;
       end loop;
    end Get_Info;

begin

    for i in 1 .. 5 loop
       Put(Integer'Image(i));
       delay 1.0;
    end loop;

end Test1;

the package actually doing the interrupt catching is:

with Ada.Interrupts;
with Ada.Interrupts.names;
package Catch_Interrupt is

    Sig_Int_Caught : exception;

    procedure Signal_Public;

    protected Catch_Interrupt is
       procedure Clean_up;
       pragma Unreserve_All_Interrupts;
       --pragma interrupt_Handler(Clean_Up);
       pragma Attach_Handler(Clean_Up,Ada.Interrupts.Names.SIGINT);
    end Catch_Interrupt;

    protected Event is
       entry Wait;
       procedure Signal;
    private
       Allowed : Boolean := False;
    end Event;
end Catch_Interrupt;

with Ada.Text_IO;
use Ada.Text_IO;
package body Catch_Interrupt is

    procedure Signal_Public is
    begin
       Event.Signal;
    end Signal_Public;

    protected body Catch_Interrupt is
       procedure Clean_up is
       begin
          Put_line("Interrupt SIGINT caught. sending signal ");
          Signal_public;
          Put_line("SIGNAL SENT. ");
       end Clean_Up;
    end Catch_Interrupt;

    protected body Event is
       entry Wait when allowed is
       begin
          Put_line("catch_interrupt msg: in entry wait");
       end Wait;
       procedure Signal is
       begin
          Put_line("Signal received!!!");
          Allowed := True;
       end Signal;
    end Event;
end Catch_Interrupt;

Here the problem:
I do get the message
"Interrupt SIGINT caught. sending signal "
but the signal_public procedure never manages to send the signal. I
don't know why. If I call the signal_public procedure from test1 it
works, but is of course useless.

Can you give me any hints on what I am doing wrong? I am lost.

Maybe there is a better way to react upon the interrupt? But still I am
wondering why my solution is not working.

Thanx a lot,

Chris



Relevant Pages

  • Catching Ctrl-C SIGINT
    ... I am having some trouble with protected types. ... cleanup work if the user presses Ctrl-C SIGINT. ... information about the raised interrupt back to the main program. ... the package actually doing the interrupt catching is: ...
    (comp.lang.ada)
  • Catching Ctrl-C SIGINT
    ... I am having some trouble with protected types. ... cleanup work if the user presses Ctrl-C SIGINT. ... information about the raised interrupt back to the main program. ... the package actually doing the interrupt catching is: ...
    (comp.lang.ada)
  • Re: Isnt this in favour of Ada??
    ... abstraction that could be either hardware triggered, OS triggered or software triggered so that the protected procedure could do what it is currently doing to connect to an interrupt, but you could hide the triggering mechanism under a package body somewhere. ... What I'm looking for is a mechanism that lets you hide the SOURCE of the interrupt in a package BODY so that the embedded executive developer and the workstation simulation developer can both work from a common specification and all we have to do to get off the target and on to the simulation is substitute one package body. ... Also in the package would be a generic package with two procedures for binding and unbinding the interrupt to a task or protected object entry. ...
    (comp.lang.ada)
  • Toshiba Satellite L25 followup
    ... fixes the battery status and interrupt routing. ... driver in a modified qemu. ... Can get temperature through ACPI ... 0x00}, Package { ...
    (freebsd-hackers)