Fix sigchainlib's implementation of sigaction

  Correctly handles the case when old_action == new_action

Bug: 18740478
Change-Id: I97092318439e4f6f0a2513d4336496c72f8c5599
diff --git a/sigchainlib/sigchain.cc b/sigchainlib/sigchain.cc
index 4f16c7f..938faf1 100644
--- a/sigchainlib/sigchain.cc
+++ b/sigchainlib/sigchain.cc
@@ -162,12 +162,13 @@
   // Note that we check that the signal number is in range here.  An out of range signal
   // number should behave exactly as the libc sigaction.
   if (signal > 0 && signal < _NSIG && user_sigactions[signal].IsClaimed()) {
-    if (old_action != NULL) {
-      *old_action = user_sigactions[signal].GetAction();
-    }
+    struct sigaction saved_action = user_sigactions[signal].GetAction();
     if (new_action != NULL) {
       user_sigactions[signal].SetAction(*new_action);
     }
+    if (old_action != NULL) {
+      *old_action = saved_action;
+    }
     return 0;
   }