Revision
118298
Author
cal@macports.org
Date
2014-03-29 08:47:26 -0700 (Sat, 29 Mar 2014)

Log Message

base: setup signal handling in mportinit

Given the code already in registry2.0/portimage.tcl this will finally prevent
inconsistent state when an activation operation is interrupted. The code there
will correctly catch the error and roll back the changes made to the
filesystem.

There might be further places where MacPorts could be smarter now that is has
signal handling code, but I think this change is already a huge improvement.

Modified Paths

Diff

Modified: trunk/base/src/macports1.0/macports.tcl (118297 => 118298)


--- trunk/base/src/macports1.0/macports.tcl	2014-03-29 15:44:08 UTC (rev 118297)
+++ trunk/base/src/macports1.0/macports.tcl	2014-03-29 15:47:26 UTC (rev 118298)
@@ -36,6 +36,7 @@
 package provide macports 1.0
 package require macports_dlist 1.0
 package require macports_util 1.0
+package require Tclx
 
 namespace eval macports {
     namespace export bootstrap_options user_options portinterp_options open_mports ui_priorities port_phases
@@ -588,6 +589,11 @@
     # Set the system encoding to utf-8
     encoding system utf-8
 
+    # Set up signal handling for SIGTERM and SIGINT
+    # Specifying error here will case the program to abort where it is with
+    # a Tcl error, which can be caught, if necessary.
+    signal -restart error {TERM INT}
+
     # set up platform info variables
     set os_arch $tcl_platform(machine)
     if {$os_arch eq {Power Macintosh}} {set os_arch "powerpc"}