Fix use of link_to_death

Fix the existing use of link_to_death in compos_client; I had a
fundamental misconception about how this worked.

Also add a use of it in composd_cmd (which I'd tried previously and
couldn't get to work).

Bug: 204044765
Test: presubmits
Test: Manual; kill composd & observe failure detected immediately.
Change-Id: I521caa38b571c9642f147d87fc6b6ee2c10585cb
diff --git a/compos/common/compos_client.rs b/compos/common/compos_client.rs
index c60a602..94ded00 100644
--- a/compos/common/compos_client.rs
+++ b/compos/common/compos_client.rs
@@ -104,10 +104,12 @@
         let vm_state = Arc::new(VmStateMonitor::default());
 
         let vm_state_clone = Arc::clone(&vm_state);
-        vm.as_binder().link_to_death(&mut DeathRecipient::new(move || {
+        let mut death_recipient = DeathRecipient::new(move || {
             vm_state_clone.set_died();
             log::error!("VirtualizationService died");
-        }))?;
+        });
+        // Note that dropping death_recipient cancels this, so we can't use a temporary here.
+        vm.as_binder().link_to_death(&mut death_recipient)?;
 
         let vm_state_clone = Arc::clone(&vm_state);
         let callback = BnVirtualMachineCallback::new_binder(
diff --git a/compos/composd_cmd/composd_cmd.rs b/compos/composd_cmd/composd_cmd.rs
index baad035..0422b44 100644
--- a/compos/composd_cmd/composd_cmd.rs
+++ b/compos/composd_cmd/composd_cmd.rs
@@ -21,10 +21,12 @@
         ICompilationTaskCallback::{BnCompilationTaskCallback, ICompilationTaskCallback},
         IIsolatedCompilationService::IIsolatedCompilationService,
     },
-    binder::{wait_for_interface, Interface, ProcessState, Result as BinderResult},
+    binder::{
+        wait_for_interface, BinderFeatures, DeathRecipient, IBinder, Interface, ProcessState,
+        Result as BinderResult,
+    },
 };
 use anyhow::{bail, Context, Result};
-use binder::BinderFeatures;
 use compos_common::timeouts::timeouts;
 use std::sync::{Arc, Condvar, Mutex};
 use std::time::Duration;
@@ -112,7 +114,13 @@
     // Make sure composd keeps going even if we don't hold a reference to its service.
     drop(service);
 
-    // TODO: Handle composd dying without sending callback?
+    let state_clone = state.clone();
+    let mut death_recipient = DeathRecipient::new(move || {
+        eprintln!("CompilationTask died");
+        state_clone.set_outcome(Outcome::Failed);
+    });
+    // Note that dropping death_recipient cancels this, so we can't use a temporary here.
+    task.as_binder().link_to_death(&mut death_recipient)?;
 
     println!("Waiting");