From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4147 invoked by alias); 7 Aug 2002 22:36:00 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 4126 invoked by uid 71); 7 Aug 2002 22:36:00 -0000 Resent-Date: 7 Aug 2002 22:36:00 -0000 Resent-Message-ID: <20020807223600.4125.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org, java-prs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, Received: (qmail 2026 invoked from network); 7 Aug 2002 22:27:17 -0000 Received: from unknown (HELO smtp.internal.avlsi.com) (65.119.15.68) by sources.redhat.com with SMTP; 7 Aug 2002 22:27:17 -0000 Received: from churchill.internal.avlsi.com (churchill.internal.avlsi.com [10.0.0.7]) by smtp.internal.avlsi.com (Postfix) with ESMTP id 4309C17744E for ; Wed, 7 Aug 2002 15:27:17 -0700 (PDT) Received: (from jmr@localhost) by churchill.internal.avlsi.com (8.11.6/8.11.2) id g77MRHf03653; Wed, 7 Aug 2002 15:27:17 -0700 Message-Id: <200208072227.g77MRHf03653@churchill.internal.avlsi.com> Date: Wed, 07 Aug 2002 16:16:00 -0000 From: To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: 3.113 Subject: libgcj/7532: shutdown hooks not run upon abnormal termination X-SW-Source: 2002-08/txt/msg00147.txt.bz2 List-Id: >Number: 7532 >Category: libgcj >Synopsis: shutdown hooks not run upon abnormal termination >Confidential: no >Severity: non-critical >Priority: low >Responsible: unassigned >State: open >Class: change-request >Submitter-Id: net >Arrival-Date: Wed Aug 07 15:36:00 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Jesse Rosenstock >Release: 3.3 20020806 (experimental) >Organization: >Environment: System: Linux churchill 2.4.3-12 #1 Fri Jun 8 15:05:56 EDT 2001 i686 unknown Architecture: i686 host: i686-pc-linux-gnu build: i686-pc-linux-gnu target: i686-pc-linux-gnu configured with: ../gcc/configure --prefix=/scratch/app/gcc --enable-threads=posix --enable-shared --enable-languages=c++,java >Description: Shutdown hooks added with Runtime.addShutdownHook() are not run if the program terminates abnormally, ie due to Ctrl-C. >How-To-Repeat: W.java: public class W { public static void main(String[] args) throws Exception { Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { public void run() { System.err.println("shutting down"); } })); final Object o = new Object(); synchronized (o) { o.wait(); } } } ; gcj -C W.java ; gij W ; java W shutting down >Fix: Here's a patch that installs a signal handler to catch SIGHUP, SIGINT, and SIGTERM. The handler calls System.exit() so the shutdown hooks run. Installation of the signal handlers can be disabled with --reduce-signal-usage. Index: gij.cc =================================================================== RCS file: /cvsroot/gcc/gcc/libjava/gij.cc,v retrieving revision 1.18 diff -c -r1.18 gij.cc *** gij.cc 27 Feb 2002 05:32:13 -0000 1.18 --- gij.cc 7 Aug 2002 22:13:46 -0000 *************** *** 32,37 **** --- 32,39 ---- printf (" --help print this help, then exit\n"); printf (" --ms=NUMBER set initial heap size\n"); printf (" --mx=NUMBER set maximum heap size\n"); + printf (" --reduce-signal-usage\n"); + printf (" reduce use of OS signals\n"); printf (" --version print version number, then exit\n"); printf ("\nSee http://gcc.gnu.org/java/ for information on reporting bugs\n"); exit (0); *************** *** 115,120 **** --- 117,124 ---- goto no_arg; _Jv_SetMaximumHeapSize (argv[++i]); } + else if (! strcmp (arg, "-reduce-signal-usage")) + _Jv_SetReduceSignalUsage (true); else { fprintf (stderr, "gij: unrecognized option -- `%s'\n", argv[i]); Index: posix.cc =================================================================== RCS file: /cvsroot/gcc/gcc/libjava/posix.cc,v retrieving revision 1.7 diff -c -r1.7 posix.cc *** posix.cc 7 Apr 2002 11:26:58 -0000 1.7 --- posix.cc 7 Aug 2002 22:13:46 -0000 *************** *** 17,22 **** --- 17,23 ---- #include #include + #include #include #include #include *************** *** 48,53 **** --- 49,60 ---- #endif } + static void + shutdown (int signum) + { + ::java::lang::System::exit (128 + signum); + } + // Platform-specific VM initialization. void _Jv_platform_initialize (void) *************** *** 59,66 **** --- 66,88 ---- sigemptyset (&act.sa_mask); act.sa_flags = 0; sigaction (SIGPIPE, &act, NULL); + + if (! ::gcj::reduceSignalUsage) + { + act.sa_handler = &shutdown; + sigaction (SIGHUP, &act, NULL); + sigaction (SIGINT, &act, NULL); + sigaction (SIGTERM, &act, NULL); + } #else signal (SIGPIPE, SIG_IGN); + + if (! ::gcj::reduceSignalUsage) + { + signal (SIGHUP, &shutdown); + signal (SIGINT, &shutdown); + signal (SIGTERM, &shutdown); + } #endif } Index: prims.cc =================================================================== RCS file: /cvsroot/gcc/gcc/libjava/prims.cc,v retrieving revision 1.72 diff -c -r1.72 prims.cc *** prims.cc 10 Mar 2002 03:53:12 -0000 1.72 --- prims.cc 7 Aug 2002 22:13:46 -0000 *************** *** 874,879 **** --- 874,880 ---- _Jv_Utf8Const *finit_name; bool runtimeInitialized = false; + bool reduceSignalUsage = false; } jint *************** *** 1051,1056 **** --- 1052,1063 ---- { size_t size = parse_heap_size (arg); _Jv_GCSetMaximumHeapSize (size); + } + + void + _Jv_SetReduceSignalUsage (bool reduce_signal_usage) + { + ::gcj::reduceSignalUsage = reduce_signal_usage; } Index: include/jvm.h =================================================================== RCS file: /cvsroot/gcc/gcc/libjava/include/jvm.h,v retrieving revision 1.51 diff -c -r1.51 jvm.h *** include/jvm.h 11 Apr 2002 15:57:56 -0000 1.51 --- include/jvm.h 7 Aug 2002 22:13:47 -0000 *************** *** 148,153 **** --- 148,158 ---- /* Set to true by _Jv_CreateJavaVM. */ extern bool runtimeInitialized; + + /* Controls whether or not the usage of signals by the runtime should + be reduced. If set to true, shutdown hooks registered with + Runtime.addShutdownHook() may not run upon abnormal termination. */ + extern bool reduceSignalUsage; }; /* Type of pointer used as finalizer. */ *************** *** 225,230 **** --- 230,241 ---- number which can optionally have "k" or "m" appended and calls _Jv_GCSetMaximumHeapSize. */ void _Jv_SetMaximumHeapSize (const char *arg); + + /* External interface to controlling whether or not the usage of signals + by the runtime should be reduced. If set to true, shutdown hooks + registered with Runtime.addShutdownHook() may not run upon abnormal + termination. */ + void _Jv_SetReduceSignalUsage (bool reduce_signal_usage); extern "C" void JvRunMain (jclass klass, int argc, const char **argv); void _Jv_RunMain (jclass klass, const char *name, int argc, const char **argv, >Release-Note: >Audit-Trail: >Unformatted: