From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,59929ddffbbb8400,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!postnews.google.com!c20g2000yqj.googlegroups.com!not-for-mail From: Bryan Newsgroups: comp.lang.ada Subject: GNAT and SIGTERM (Linux x86_64) Date: Tue, 26 Oct 2010 08:52:57 -0700 (PDT) Organization: http://groups.google.com Message-ID: <18db9616-3c2c-4dfa-8ef1-160e06c22b2d@c20g2000yqj.googlegroups.com> NNTP-Posting-Host: 204.130.247.244 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1288108378 27392 127.0.0.1 (26 Oct 2010 15:52:58 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 26 Oct 2010 15:52:58 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c20g2000yqj.googlegroups.com; posting-host=204.130.247.244; posting-account=kI3R0woAAAAkETUXcbnWjzzG0TUmJmXv User-Agent: G2/1.0 X-HTTP-Via: 1.1 webf01.atdesk.com:8080 (http_scan/4.0.2.6.19) X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.4) Gecko/20091016 SUSE/3.5.4-1.1.2 Firefox/3.5.4,gzip(gfe) Xref: g2news1.google.com comp.lang.ada:14802 Date: 2010-10-26T08:52:57-07:00 List-Id: 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 : > ./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;