From 5de85f8273c7284aa93e35c40f025d4d43d42df9 Mon Sep 17 00:00:00 2001
From: Etienne Cordonnier <ecordonnier@snap.com>
Date: Thu, 16 Mar 2023 18:59:35 +0100
Subject: [PATCH] Fixes for yocto build

Signed-off-by: JJ Robertson <jrobertson@snapchat.com>
[rebased on version 29]
Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com>

---
Upstream-Status: Pending

 system/core/adb/daemon/file_sync_service.cpp | 4 ++--
 system/core/adb/daemon/framebuffer_service.h | 2 --
 system/core/adb/daemon/main.cpp              | 5 +++--
 system/core/adb/daemon/restart_service.h     | 2 --
 system/core/adb/daemon/services.cpp          | 6 ++----
 system/core/adb/daemon/shell_service.cpp     | 5 ++++-
 system/core/adb/types.h                      | 1 +
 7 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/system/core/adb/daemon/file_sync_service.cpp b/system/core/adb/daemon/file_sync_service.cpp
index d6af7087..92e7087a 100644
--- a/system/core/adb/daemon/file_sync_service.cpp
+++ b/system/core/adb/daemon/file_sync_service.cpp
@@ -111,7 +111,7 @@ static bool secure_mkdirs(const std::string& path) {
         partial_path += path_component;
 
         if (should_use_fs_config(partial_path)) {
-            fs_config(partial_path.c_str(), 1, nullptr, &uid, &gid, &mode, &capabilities);
+            // fs_config(partial_path.c_str(), 1, nullptr, &uid, &gid, &mode, &capabilities);
         }
         if (adb_mkdir(partial_path.c_str(), mode) == -1) {
             if (errno != EEXIST) {
@@ -469,7 +469,7 @@ static bool do_send(int s, const std::string& spec, std::vector<char>& buffer) {
         uint64_t capabilities = 0;
         if (should_use_fs_config(path)) {
             unsigned int broken_api_hack = mode;
-            fs_config(path.c_str(), 0, nullptr, &uid, &gid, &broken_api_hack, &capabilities);
+            // fs_config(path.c_str(), 0, nullptr, &uid, &gid, &broken_api_hack, &capabilities);
             mode = broken_api_hack;
         }
 
diff --git a/system/core/adb/daemon/framebuffer_service.h b/system/core/adb/daemon/framebuffer_service.h
index bab44be3..264da597 100644
--- a/system/core/adb/daemon/framebuffer_service.h
+++ b/system/core/adb/daemon/framebuffer_service.h
@@ -18,6 +18,4 @@
 
 #include "adb_unique_fd.h"
 
-#if defined(__ANDROID__)
 void framebuffer_service(unique_fd fd);
-#endif
diff --git a/system/core/adb/daemon/main.cpp b/system/core/adb/daemon/main.cpp
index 3322574c..e807d13d 100644
--- a/system/core/adb/daemon/main.cpp
+++ b/system/core/adb/daemon/main.cpp
@@ -208,6 +208,9 @@ int adbd_main(int server_port) {
     umask(0);
 
     signal(SIGPIPE, SIG_IGN);
+    signal(SIGINT, SIG_DFL);
+    signal(SIGQUIT, SIG_DFL);
+
 
 #if defined(__BIONIC__)
     auto fdsan_level = android_fdsan_get_error_level();
@@ -254,13 +257,11 @@ int adbd_main(int server_port) {
 
     bool is_usb = false;
 
-#if defined(__ANDROID__)
     if (access(USB_FFS_ADB_EP0, F_OK) == 0) {
         // Listen on USB.
         usb_init();
         is_usb = true;
     }
-#endif
 
     // If one of these properties is set, also listen on that port.
     // If one of the properties isn't set and we couldn't listen on usb, listen
diff --git a/system/core/adb/daemon/restart_service.h b/system/core/adb/daemon/restart_service.h
index 19840bd5..7a97614b 100644
--- a/system/core/adb/daemon/restart_service.h
+++ b/system/core/adb/daemon/restart_service.h
@@ -18,9 +18,7 @@
 
 #include "adb_unique_fd.h"
 
-#if defined(__ANDROID__)
 void restart_root_service(unique_fd fd);
 void restart_unroot_service(unique_fd fd);
 void restart_tcp_service(unique_fd fd, int port);
 void restart_usb_service(unique_fd fd);
-#endif
diff --git a/system/core/adb/daemon/services.cpp b/system/core/adb/daemon/services.cpp
index 4ec90d27..d8541c23 100644
--- a/system/core/adb/daemon/services.cpp
+++ b/system/core/adb/daemon/services.cpp
@@ -156,7 +156,7 @@ static void spin_service(unique_fd fd) {
     }
 #endif
     // Fall through
-    std::string cmd = "/system/bin/reboot ";
+    std::string cmd = "/sbin/reboot ";
     cmd += name;
     return StartSubprocess(cmd, nullptr, SubprocessType::kRaw, SubprocessProtocol::kNone);
 }
@@ -265,11 +265,10 @@ unique_fd daemon_service_to_fd(std::string_view name, atransport* transport) {
     }
 #endif
 
-#if defined(__ANDROID__)
     if (name.starts_with("framebuffer:")) {
         return create_service_thread("fb", framebuffer_service);
     } else if (android::base::ConsumePrefix(&name, "remount:")) {
-        std::string cmd = "/system/bin/remount ";
+        std::string cmd = "/sbin/remount ";
         cmd += name;
         return StartSubprocess(cmd, nullptr, SubprocessType::kRaw, SubprocessProtocol::kNone);
     } else if (android::base::ConsumePrefix(&name, "reboot:")) {
@@ -303,7 +302,6 @@ unique_fd daemon_service_to_fd(std::string_view name, atransport* transport) {
     } else if (name.starts_with("usb:")) {
         return create_service_thread("usb", restart_usb_service);
     }
-#endif
 
     if (android::base::ConsumePrefix(&name, "dev:")) {
         return unique_fd{unix_open(name, O_RDWR | O_CLOEXEC)};
diff --git a/system/core/adb/daemon/shell_service.cpp b/system/core/adb/daemon/shell_service.cpp
index f62032d0..ebcfe18d 100644
--- a/system/core/adb/daemon/shell_service.cpp
+++ b/system/core/adb/daemon/shell_service.cpp
@@ -273,13 +273,16 @@ bool Subprocess::ForkAndExec(std::string* error) {
         env["HOSTNAME"] = GetHostName();
         env["LOGNAME"] = pw->pw_name;
         env["SHELL"] = pw->pw_shell;
-        env["TMPDIR"] = "/data/local/tmp";
         env["USER"] = pw->pw_name;
     }
 
     if (!terminal_type_.empty()) {
         env["TERM"] = terminal_type_;
     }
+    if (env.find("PS1") == env.end()) {
+        env["PS1"] = "\\h:\\w\\$ ";
+    }
+
 
     std::vector<std::string> joined_env;
     for (const auto& it : env) {
diff --git a/system/core/adb/types.h b/system/core/adb/types.h
index c619fffc..f8e0f521 100644
--- a/system/core/adb/types.h
+++ b/system/core/adb/types.h
@@ -22,6 +22,7 @@
 #include <memory>
 #include <utility>
 #include <vector>
+#include <string.h>
 
 #include <android-base/logging.h>
 
