Do AIDL initialization after daemonizing the process

Supplicant start from command line is failing when -B option used to
daemonize the supplicant process due to process forked for daemonizing
is not able access the AIDL file decriptor.

To avoid this do AIDL initialization after daemonizing the process.

Bug: 270241817
Test: Manual test. See comments in pa/2427759
Change-Id: I7d8c5c7863f9bf5ac95d3bf141a31c01d71609af
diff --git a/wpa_supplicant/notify.c b/wpa_supplicant/notify.c
index 3122c58..0f2556c 100644
--- a/wpa_supplicant/notify.c
+++ b/wpa_supplicant/notify.c
@@ -37,12 +37,6 @@
 	}
 #endif /* CONFIG_CTRL_IFACE_DBUS_NEW */
 
-#ifdef CONFIG_AIDL
-	global->aidl = wpas_aidl_init(global);
-	if (!global->aidl)
-		return -1;
-#endif /* CONFIG_AIDL */
-
 	return 0;
 }
 
@@ -68,9 +62,17 @@
 			return -1;
 	}
 
+#ifdef CONFIG_AIDL
+	/* AIDL initialization may not be complete at this point.
+	 * Initialization is done after daemonizing in order to avoid
+	 * issues with the file descriptor.
+	 */
+	if (!wpa_s || !wpa_s->global->aidl)
+		return 0;
 	/* HIDL interface wants to keep track of the P2P mgmt iface. */
 	if (wpas_aidl_register_interface(wpa_s))
 		return -1;
+#endif
 
 	return 0;
 }
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index 521ff90..d84f308 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -69,6 +69,7 @@
 #include "ap/ap_config.h"
 #include "ap/hostapd.h"
 #endif /* CONFIG_MESH */
+#include "aidl/aidl.h"
 
 const char *const wpa_supplicant_version =
 "wpa_supplicant v" VERSION_STR "\n"
@@ -7826,6 +7827,12 @@
 					wpa_s->ctrl_iface);
 	}
 
+#ifdef CONFIG_AIDL
+	global->aidl = wpas_aidl_init(global);
+	if (!global->aidl)
+		return -1;
+#endif /* CONFIG_AIDL */
+
 	eloop_register_signal_terminate(wpa_supplicant_terminate, global);
 	eloop_register_signal_reconfig(wpa_supplicant_reconfig, global);