summaryrefslogtreecommitdiff
path: root/adb/daemon/file_sync_service.cpp
diff options
context:
space:
mode:
authorJosh Gao <jmgao@google.com>2019-01-22 19:36:15 -0800
committerJosh Gao <jmgao@google.com>2019-01-23 12:59:41 -0800
commit776c2ec08c7b9736a4c7a635daa8687aa19f8f70 (patch)
tree88571887ac6ea6d9af20377c4e90c40f3defdcc8 /adb/daemon/file_sync_service.cpp
parent09158b1d5a2da7d71b7046734e1f96c98d8fc81f (diff)
adbd: compile for host.
Preparatory step for testing adb on GCE on non-linux hosts: instead of pointing them at a device (emulated or otherwise), point them at adbd running on a linux host instead. Test: adbd & adb connect localhost:5555; adb -e wait-for-device shell Change-Id: Ib22d51a4fc9e6e68f71bf1b3b9b2e1b0bd844760
Diffstat (limited to 'adb/daemon/file_sync_service.cpp')
-rw-r--r--adb/daemon/file_sync_service.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/adb/daemon/file_sync_service.cpp b/adb/daemon/file_sync_service.cpp
index d55096aa8..62c18c57d 100644
--- a/adb/daemon/file_sync_service.cpp
+++ b/adb/daemon/file_sync_service.cpp
@@ -22,13 +22,11 @@
#include <dirent.h>
#include <errno.h>
-#include <linux/xattr.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <sys/xattr.h>
#include <unistd.h>
#include <utime.h>
@@ -37,11 +35,17 @@
#include <vector>
#include <android-base/file.h>
+#include <android-base/macros.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
+
#include <private/android_filesystem_config.h>
#include <private/android_logger.h>
+
+#if defined(__ANDROID__)
#include <selinux/android.h>
+#include <sys/xattr.h>
+#endif
#include "adb.h"
#include "adb_io.h"
@@ -55,11 +59,17 @@ using android::base::Dirname;
using android::base::StringPrintf;
static bool should_use_fs_config(const std::string& path) {
+#if defined(__ANDROID__)
// TODO: use fs_config to configure permissions on /data too.
return !android::base::StartsWith(path, "/data/");
+#else
+ UNUSED(path);
+ return false;
+#endif
}
static bool update_capabilities(const char* path, uint64_t capabilities) {
+#if defined(__ANDROID__)
if (capabilities == 0) {
// Ensure we clean up in case the capabilities weren't 0 in the past.
removexattr(path, XATTR_NAME_CAPS);
@@ -73,6 +83,10 @@ static bool update_capabilities(const char* path, uint64_t capabilities) {
cap_data.data[1].permitted = (capabilities >> 32);
cap_data.data[1].inheritable = 0;
return setxattr(path, XATTR_NAME_CAPS, &cap_data, sizeof(cap_data), 0) != -1;
+#else
+ UNUSED(path, capabilities);
+ return true;
+#endif
}
static bool secure_mkdirs(const std::string& path) {
@@ -105,8 +119,10 @@ static bool secure_mkdirs(const std::string& path) {
} else {
if (chown(partial_path.c_str(), uid, gid) == -1) return false;
+#if defined(__ANDROID__)
// Not all filesystems support setting SELinux labels. http://b/23530370.
selinux_android_restorecon(partial_path.c_str(), 0);
+#endif
if (!update_capabilities(partial_path.c_str(), capabilities)) return false;
}
@@ -242,8 +258,10 @@ static bool handle_send_file(int s, const char* path, uid_t uid, gid_t gid, uint
goto fail;
}
+#if defined(__ANDROID__)
// Not all filesystems support setting SELinux labels. http://b/23530370.
selinux_android_restorecon(path, 0);
+#endif
// fchown clears the setuid bit - restore it if present.
// Ignore the result of calling fchmod. It's not supported