From: Bryan <brobinson.eng@gmail.com>
Subject: GNAT and SIGTERM (Linux x86_64)
Date: Tue, 26 Oct 2010 08:52:57 -0700 (PDT)
Date: 2010-10-26T08:52:57-07:00 [thread overview]
Message-ID: <18db9616-3c2c-4dfa-8ef1-160e06c22b2d@c20g2000yqj.googlegroups.com> (raw)
I'm trying to capture SIGTERM in a very simple test program but I'm
running into some issues. When I execute the code (at the end of
message), I get the following output in my terminal when I send "kill -
SIGTERM <PID>:
> ./entry_point
SIGTERM handler is NOT reserved
!!! SIGTERM handler is NOT attached !!!
Terminated
I attached the signal handler in signals.ads, but it seems the handler
is still not attached. The sample program in the Big Book of Ada
Programming for Linux attaches the handler in the package
specification, and I tried to follow the sample program. To make
things more interesting, If I run this same code on a Mac OS X with
GNAT, I get the following as my output:
> ./entry_point
SIGTERM handler is reserved
raised PROGRAM_ERROR : Interrupt 15 is reserved
This happens even with the Unreserve_All_Interrupts in signals.ads.
The behavior of both the Linux and the Mac binary are leading me to--
perhaps wrongly--consider that there is something I am missing with
GNAT to allow it to work with UNIX signals.
Questions:
1) Do my pragma statements need to be in the specification or the
body?
2) Do I need to pass some sort of flag to gnat to enable signals?
I would greatly appreciate any input or advice on this issue.
--------------------------------------
Test program source code:
--------------------------------------
-- Signals.ads
with Ada.Interrupts; use Ada.Interrupts;
with Ada.Interrupts.Names; use Ada.Interrupts.Names;
package Signals is
pragma Unreserve_All_Interrupts;
protected type Signal_Handler is
procedure Handle_SIGTERM;
pragma Attach_Handler(Handle_SIGTERM, SIGTERM);
pragma Interrupt_State (SIGTERM, System);
end Signal_Handler;
end Signals;
-- Signals.adb
with Ada.Text_IO; use Ada.Text_IO;
package body Signals is
protected body Signal_Handler is
procedure Handle_SIGTERM is
begin
Put_Line( "SIGTERM caught!" );
end Handle_SIGTERM;
end Signal_Handler;
end Signals;
-- Entrypoint.adb
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Interrupts; use Ada.Interrupts;
with Ada.Interrupts.Names; use Ada.Interrupts.Names;
with Signals; use Signals;
procedure Entry_Point is
Shutdown_Flag : Boolean := False;
begin
if Is_Reserved(SIGTERM) then
Put_Line("SIGTERM handler is reserved");
else
Put_Line("SIGTERM handler is NOT reserved");
end if;
if Is_Attached(SIGTERM) then
Put_Line("SIGTERM handler is attached");
else
Put_Line("!!! SIGTERM handler is NOT attached !!!");
end if;
loop
-- do nothing
exit when Shutdown_Flag = True;
end loop;
end Entry_Point;
next reply other threads:[~2010-10-26 15:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-26 15:52 Bryan [this message]
2010-10-26 16:36 ` GNAT and SIGTERM (Linux x86_64) Yannick Duchêne (Hibou57)
2010-10-27 7:43 ` Ludovic Brenta
2010-10-27 14:21 ` Bryan
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox