multiple: Wait D-Bus interface in hwsec daemons upstart

BUG=b:202223651, b:209926646
TEST=boot ok.

Change-Id: Ib9602c0c1cea1998336ecb02dc9d974695982109
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/3208287
Tested-by: Yi Chou <yich@google.com>
Commit-Queue: Yi Chou <yich@google.com>
Reviewed-by: Leo Lai <cylai@google.com>
Reviewed-by: John L Chen <zuan@chromium.org>
(cherry picked from commit 9183a92181b4a3d58717e48a052f486132e526a3)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/3326826
Tested-by: John L Chen <zuan@chromium.org>
diff --git a/attestation/server/attestationd.conf b/attestation/server/attestationd.conf
index 34408ce..5278de6 100644
--- a/attestation/server/attestationd.conf
+++ b/attestation/server/attestationd.conf
@@ -78,5 +78,12 @@
 end script
 
 expect fork
+
 exec /usr/sbin/attestationd
-post-start exec rm -f "${ABE_DATA_FILE}"
+
+post-start script
+  rm -f "${ABE_DATA_FILE}"
+  # Wait for daemon to claim its D-Bus name.
+  exec minijail0 -u attestation -G \
+    /usr/bin/gdbus wait --system --timeout 15 org.chromium.Attestation
+end script
diff --git a/chaps/init/chapsd.conf b/chaps/init/chapsd.conf
index e917534..998b164 100644
--- a/chaps/init/chapsd.conf
+++ b/chaps/init/chapsd.conf
@@ -24,6 +24,9 @@
 exec /usr/sbin/chapsd --auto_load_system_token
 
 post-start script
+  # Wait for daemon to claim its D-Bus name.
+  minijail0 -u chaps -G \
+    /usr/bin/gdbus wait --system --timeout 15 org.chromium.Chaps
   # Running this in background to prevent upstart deadlock on chapsd.
   # For example: chapsd crashed before the it restores TPM tokens.
   (cryptohome --action=pkcs11_restore_tpm_tokens | logger -e -t chaps-restore) &
diff --git a/cryptohome/init/cryptohomed.conf b/cryptohome/init/cryptohomed.conf
index a8da97e..309937d 100644
--- a/cryptohome/init/cryptohomed.conf
+++ b/cryptohome/init/cryptohomed.conf
@@ -56,9 +56,6 @@
   exec cryptohomed "$@"
 end script
 
-# TODO(zuan): Remove this cleanup after M93. This is here so that there's no
-# lingering flag files on the system.
-post-start script
-  rm -f "${USERDATAAUTH_FLAG_STORAGE_FILE}"
-  rm -f "${USERDATAAUTH_INTERFACE_CTRL_FILE}"
-end script
+# Wait for daemon to claim its D-Bus name.
+post-start exec minijail0 -u cryptohome -G \
+  /usr/bin/gdbus wait --system --timeout 15 org.chromium.UserDataAuth
diff --git a/tpm_manager/server/tpm_managerd.conf b/tpm_manager/server/tpm_managerd.conf
index 447cefa..bbb1f56 100644
--- a/tpm_manager/server/tpm_managerd.conf
+++ b/tpm_manager/server/tpm_managerd.conf
@@ -19,3 +19,7 @@
 end script
 
 exec /usr/sbin/tpm_managerd --wait_for_ownership_trigger
+
+# Wait for daemon to claim its D-Bus name.
+post-start exec minijail0 -u tpm_manager -G \
+    /usr/bin/gdbus wait --system --timeout 15 org.chromium.TpmManager