The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Yabin Cui | 19bec5b | 2015-09-22 15:52:57 -0700 | [diff] [blame] | 17 | #define TRACE_TAG SYNC |
Dan Albert | db6fe64 | 2015-03-19 15:21:08 -0700 | [diff] [blame] | 18 | |
| 19 | #include "sysdeps.h" |
| 20 | #include "file_sync_service.h" |
| 21 | |
Dan Albert | b302d12 | 2015-02-24 15:51:19 -0800 | [diff] [blame] | 22 | #include <dirent.h> |
| 23 | #include <errno.h> |
Elliott Hughes | 02c9474 | 2016-06-07 17:18:25 -0700 | [diff] [blame] | 24 | #include <linux/xattr.h> |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 25 | #include <stdio.h> |
Dan Albert | b302d12 | 2015-02-24 15:51:19 -0800 | [diff] [blame] | 26 | #include <stdlib.h> |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 27 | #include <string.h> |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 28 | #include <sys/stat.h> |
| 29 | #include <sys/types.h> |
Elliott Hughes | 02c9474 | 2016-06-07 17:18:25 -0700 | [diff] [blame] | 30 | #include <sys/xattr.h> |
Liang Cheng | 155c49a | 2014-01-02 18:27:51 -0800 | [diff] [blame] | 31 | #include <unistd.h> |
Dan Albert | b302d12 | 2015-02-24 15:51:19 -0800 | [diff] [blame] | 32 | #include <utime.h> |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 33 | |
Colin Cross | e679407 | 2017-02-23 21:23:05 -0800 | [diff] [blame] | 34 | #include <android-base/file.h> |
Mark Salyzyn | 5f17a90 | 2016-09-28 15:54:45 -0700 | [diff] [blame] | 35 | #include <android-base/stringprintf.h> |
| 36 | #include <android-base/strings.h> |
| 37 | #include <private/android_filesystem_config.h> |
Mark Salyzyn | 81a870e | 2016-10-05 08:13:56 -0700 | [diff] [blame] | 38 | #include <private/android_logger.h> |
Mark Salyzyn | 5f17a90 | 2016-09-28 15:54:45 -0700 | [diff] [blame] | 39 | #include <selinux/android.h> |
| 40 | |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 41 | #include "adb.h" |
Dan Albert | 66a91b0 | 2015-02-24 21:26:58 -0800 | [diff] [blame] | 42 | #include "adb_io.h" |
Josh Gao | 14ed70a | 2016-11-22 14:33:08 -0800 | [diff] [blame] | 43 | #include "adb_trace.h" |
Josh Gao | fe1a612 | 2015-11-04 14:51:23 -0800 | [diff] [blame] | 44 | #include "adb_utils.h" |
Rubin Xu | 29a64f9 | 2016-01-11 10:23:47 +0000 | [diff] [blame] | 45 | #include "security_log_tags.h" |
Josh Gao | a2cf375 | 2016-12-05 17:11:34 -0800 | [diff] [blame] | 46 | #include "sysdeps/errno.h" |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 47 | |
Josh Gao | 14ed70a | 2016-11-22 14:33:08 -0800 | [diff] [blame] | 48 | using android::base::StringPrintf; |
| 49 | |
Elliott Hughes | d189cfb | 2015-07-30 17:42:01 -0700 | [diff] [blame] | 50 | static bool should_use_fs_config(const std::string& path) { |
Elliott Hughes | dedf767 | 2015-03-16 21:58:32 +0000 | [diff] [blame] | 51 | // TODO: use fs_config to configure permissions on /data. |
Elliott Hughes | d189cfb | 2015-07-30 17:42:01 -0700 | [diff] [blame] | 52 | return android::base::StartsWith(path, "/system/") || |
| 53 | android::base::StartsWith(path, "/vendor/") || |
| 54 | android::base::StartsWith(path, "/oem/"); |
Daniel Rosenberg | e9a1c9c | 2014-06-30 20:29:40 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Elliott Hughes | 02c9474 | 2016-06-07 17:18:25 -0700 | [diff] [blame] | 57 | static bool update_capabilities(const char* path, uint64_t capabilities) { |
| 58 | if (capabilities == 0) { |
| 59 | // Ensure we clean up in case the capabilities weren't 0 in the past. |
| 60 | removexattr(path, XATTR_NAME_CAPS); |
| 61 | return true; |
| 62 | } |
| 63 | |
| 64 | vfs_cap_data cap_data = {}; |
| 65 | cap_data.magic_etc = VFS_CAP_REVISION | VFS_CAP_FLAGS_EFFECTIVE; |
| 66 | cap_data.data[0].permitted = (capabilities & 0xffffffff); |
| 67 | cap_data.data[0].inheritable = 0; |
| 68 | cap_data.data[1].permitted = (capabilities >> 32); |
| 69 | cap_data.data[1].inheritable = 0; |
| 70 | return setxattr(path, XATTR_NAME_CAPS, &cap_data, sizeof(cap_data), 0) != -1; |
| 71 | } |
| 72 | |
Alex Vallée | 28d1f8d | 2015-05-06 16:26:00 -0400 | [diff] [blame] | 73 | static bool secure_mkdirs(const std::string& path) { |
Nick Kralevich | 29e7813 | 2014-01-17 16:16:42 -0800 | [diff] [blame] | 74 | uid_t uid = -1; |
| 75 | gid_t gid = -1; |
Liang Cheng | 155c49a | 2014-01-02 18:27:51 -0800 | [diff] [blame] | 76 | unsigned int mode = 0775; |
Elliott Hughes | 02c9474 | 2016-06-07 17:18:25 -0700 | [diff] [blame] | 77 | uint64_t capabilities = 0; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 78 | |
Alex Vallée | 28d1f8d | 2015-05-06 16:26:00 -0400 | [diff] [blame] | 79 | if (path[0] != '/') return false; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 80 | |
Elliott Hughes | d189cfb | 2015-07-30 17:42:01 -0700 | [diff] [blame] | 81 | std::vector<std::string> path_components = android::base::Split(path, "/"); |
Elliott Hughes | d189cfb | 2015-07-30 17:42:01 -0700 | [diff] [blame] | 82 | std::string partial_path; |
Elliott Hughes | 8595283 | 2015-10-07 15:59:35 -0700 | [diff] [blame] | 83 | for (const auto& path_component : path_components) { |
Elliott Hughes | d189cfb | 2015-07-30 17:42:01 -0700 | [diff] [blame] | 84 | if (partial_path.back() != OS_PATH_SEPARATOR) partial_path += OS_PATH_SEPARATOR; |
| 85 | partial_path += path_component; |
| 86 | |
| 87 | if (should_use_fs_config(partial_path)) { |
Elliott Hughes | 02c9474 | 2016-06-07 17:18:25 -0700 | [diff] [blame] | 88 | fs_config(partial_path.c_str(), 1, nullptr, &uid, &gid, &mode, &capabilities); |
Liang Cheng | 155c49a | 2014-01-02 18:27:51 -0800 | [diff] [blame] | 89 | } |
Elliott Hughes | d189cfb | 2015-07-30 17:42:01 -0700 | [diff] [blame] | 90 | if (adb_mkdir(partial_path.c_str(), mode) == -1) { |
Alex Vallée | 28d1f8d | 2015-05-06 16:26:00 -0400 | [diff] [blame] | 91 | if (errno != EEXIST) { |
| 92 | return false; |
Liang Cheng | 155c49a | 2014-01-02 18:27:51 -0800 | [diff] [blame] | 93 | } |
Alex Vallée | 28d1f8d | 2015-05-06 16:26:00 -0400 | [diff] [blame] | 94 | } else { |
Elliott Hughes | 02c9474 | 2016-06-07 17:18:25 -0700 | [diff] [blame] | 95 | if (chown(partial_path.c_str(), uid, gid) == -1) return false; |
| 96 | |
Elliott Hughes | bfd8937 | 2015-08-25 16:33:50 -0700 | [diff] [blame] | 97 | // Not all filesystems support setting SELinux labels. http://b/23530370. |
Elliott Hughes | d189cfb | 2015-07-30 17:42:01 -0700 | [diff] [blame] | 98 | selinux_android_restorecon(partial_path.c_str(), 0); |
Elliott Hughes | 02c9474 | 2016-06-07 17:18:25 -0700 | [diff] [blame] | 99 | |
| 100 | if (!update_capabilities(partial_path.c_str(), capabilities)) return false; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 101 | } |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 102 | } |
Alex Vallée | 28d1f8d | 2015-05-06 16:26:00 -0400 | [diff] [blame] | 103 | return true; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 104 | } |
| 105 | |
Josh Gao | a2cf375 | 2016-12-05 17:11:34 -0800 | [diff] [blame] | 106 | static bool do_lstat_v1(int s, const char* path) { |
| 107 | syncmsg msg = {}; |
| 108 | msg.stat_v1.id = ID_LSTAT_V1; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 109 | |
Elliott Hughes | 02c9474 | 2016-06-07 17:18:25 -0700 | [diff] [blame] | 110 | struct stat st = {}; |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 111 | lstat(path, &st); |
Josh Gao | a2cf375 | 2016-12-05 17:11:34 -0800 | [diff] [blame] | 112 | msg.stat_v1.mode = st.st_mode; |
| 113 | msg.stat_v1.size = st.st_size; |
| 114 | msg.stat_v1.time = st.st_mtime; |
| 115 | return WriteFdExactly(s, &msg.stat_v1, sizeof(msg.stat_v1)); |
| 116 | } |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 117 | |
Josh Gao | a2cf375 | 2016-12-05 17:11:34 -0800 | [diff] [blame] | 118 | static bool do_stat_v2(int s, uint32_t id, const char* path) { |
| 119 | syncmsg msg = {}; |
| 120 | msg.stat_v2.id = id; |
| 121 | |
| 122 | decltype(&stat) stat_fn; |
| 123 | if (id == ID_STAT_V2) { |
| 124 | stat_fn = stat; |
| 125 | } else { |
| 126 | stat_fn = lstat; |
| 127 | } |
| 128 | |
| 129 | struct stat st = {}; |
| 130 | int rc = stat_fn(path, &st); |
| 131 | if (rc == -1) { |
| 132 | msg.stat_v2.error = errno_to_wire(errno); |
| 133 | } else { |
| 134 | msg.stat_v2.dev = st.st_dev; |
| 135 | msg.stat_v2.ino = st.st_ino; |
| 136 | msg.stat_v2.mode = st.st_mode; |
| 137 | msg.stat_v2.nlink = st.st_nlink; |
| 138 | msg.stat_v2.uid = st.st_uid; |
| 139 | msg.stat_v2.gid = st.st_gid; |
| 140 | msg.stat_v2.size = st.st_size; |
| 141 | msg.stat_v2.atime = st.st_atime; |
| 142 | msg.stat_v2.mtime = st.st_mtime; |
| 143 | msg.stat_v2.ctime = st.st_ctime; |
| 144 | } |
| 145 | |
| 146 | return WriteFdExactly(s, &msg.stat_v2, sizeof(msg.stat_v2)); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 147 | } |
| 148 | |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 149 | static bool do_list(int s, const char* path) { |
| 150 | dirent* de; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 151 | |
Elliott Hughes | d189cfb | 2015-07-30 17:42:01 -0700 | [diff] [blame] | 152 | syncmsg msg; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 153 | msg.dent.id = ID_DENT; |
| 154 | |
Elliott Hughes | d189cfb | 2015-07-30 17:42:01 -0700 | [diff] [blame] | 155 | std::unique_ptr<DIR, int(*)(DIR*)> d(opendir(path), closedir); |
| 156 | if (!d) goto done; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 157 | |
Elliott Hughes | d189cfb | 2015-07-30 17:42:01 -0700 | [diff] [blame] | 158 | while ((de = readdir(d.get()))) { |
Josh Gao | 14ed70a | 2016-11-22 14:33:08 -0800 | [diff] [blame] | 159 | std::string filename(StringPrintf("%s/%s", path, de->d_name)); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 160 | |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 161 | struct stat st; |
| 162 | if (lstat(filename.c_str(), &st) == 0) { |
| 163 | size_t d_name_length = strlen(de->d_name); |
Elliott Hughes | 9e8e355 | 2015-08-24 14:27:03 -0700 | [diff] [blame] | 164 | msg.dent.mode = st.st_mode; |
| 165 | msg.dent.size = st.st_size; |
| 166 | msg.dent.time = st.st_mtime; |
| 167 | msg.dent.namelen = d_name_length; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 168 | |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 169 | if (!WriteFdExactly(s, &msg.dent, sizeof(msg.dent)) || |
| 170 | !WriteFdExactly(s, de->d_name, d_name_length)) { |
| 171 | return false; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | } |
| 175 | |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 176 | done: |
| 177 | msg.dent.id = ID_DONE; |
| 178 | msg.dent.mode = 0; |
| 179 | msg.dent.size = 0; |
| 180 | msg.dent.time = 0; |
| 181 | msg.dent.namelen = 0; |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 182 | return WriteFdExactly(s, &msg.dent, sizeof(msg.dent)); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 183 | } |
| 184 | |
Josh Gao | bd446be | 2016-01-28 16:21:12 -0800 | [diff] [blame] | 185 | // Make sure that SendFail from adb_io.cpp isn't accidentally used in this file. |
| 186 | #pragma GCC poison SendFail |
| 187 | |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 188 | static bool SendSyncFail(int fd, const std::string& reason) { |
Yabin Cui | 815ad88 | 2015-09-02 17:44:28 -0700 | [diff] [blame] | 189 | D("sync: failure: %s", reason.c_str()); |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 190 | |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 191 | syncmsg msg; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 192 | msg.data.id = ID_FAIL; |
Elliott Hughes | 9e8e355 | 2015-08-24 14:27:03 -0700 | [diff] [blame] | 193 | msg.data.size = reason.size(); |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 194 | return WriteFdExactly(fd, &msg.data, sizeof(msg.data)) && WriteFdExactly(fd, reason); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 195 | } |
| 196 | |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 197 | static bool SendSyncFailErrno(int fd, const std::string& reason) { |
Josh Gao | 14ed70a | 2016-11-22 14:33:08 -0800 | [diff] [blame] | 198 | return SendSyncFail(fd, StringPrintf("%s: %s", reason.c_str(), strerror(errno))); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 199 | } |
| 200 | |
Elliott Hughes | 02c9474 | 2016-06-07 17:18:25 -0700 | [diff] [blame] | 201 | static bool handle_send_file(int s, const char* path, uid_t uid, gid_t gid, uint64_t capabilities, |
| 202 | mode_t mode, std::vector<char>& buffer, bool do_unlink) { |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 203 | syncmsg msg; |
| 204 | unsigned int timestamp = 0; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 205 | |
Rubin Xu | 29a64f9 | 2016-01-11 10:23:47 +0000 | [diff] [blame] | 206 | __android_log_security_bswrite(SEC_TAG_ADB_SEND_FILE, path); |
| 207 | |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 208 | int fd = adb_open_mode(path, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, mode); |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 209 | if (fd < 0 && errno == ENOENT) { |
Colin Cross | e679407 | 2017-02-23 21:23:05 -0800 | [diff] [blame] | 210 | if (!secure_mkdirs(android::base::Dirname(path))) { |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 211 | SendSyncFailErrno(s, "secure_mkdirs failed"); |
| 212 | goto fail; |
Liang Cheng | 155c49a | 2014-01-02 18:27:51 -0800 | [diff] [blame] | 213 | } |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 214 | fd = adb_open_mode(path, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, mode); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 215 | } |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 216 | if (fd < 0 && errno == EEXIST) { |
Nick Kralevich | 777523e | 2014-07-18 20:57:35 -0700 | [diff] [blame] | 217 | fd = adb_open_mode(path, O_WRONLY | O_CLOEXEC, mode); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 218 | } |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 219 | if (fd < 0) { |
| 220 | SendSyncFailErrno(s, "couldn't create file"); |
| 221 | goto fail; |
Liang Cheng | 155c49a | 2014-01-02 18:27:51 -0800 | [diff] [blame] | 222 | } else { |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 223 | if (fchown(fd, uid, gid) == -1) { |
| 224 | SendSyncFailErrno(s, "fchown failed"); |
| 225 | goto fail; |
Liang Cheng | 155c49a | 2014-01-02 18:27:51 -0800 | [diff] [blame] | 226 | } |
Nick Kralevich | 29e7813 | 2014-01-17 16:16:42 -0800 | [diff] [blame] | 227 | |
Elliott Hughes | bfd8937 | 2015-08-25 16:33:50 -0700 | [diff] [blame] | 228 | // Not all filesystems support setting SELinux labels. http://b/23530370. |
| 229 | selinux_android_restorecon(path, 0); |
Elliott Hughes | 4f97b61 | 2015-08-25 13:14:07 -0700 | [diff] [blame] | 230 | |
| 231 | // fchown clears the setuid bit - restore it if present. |
| 232 | // Ignore the result of calling fchmod. It's not supported |
Elliott Hughes | 02c9474 | 2016-06-07 17:18:25 -0700 | [diff] [blame] | 233 | // by all filesystems, so we don't check for success. b/12441485 |
Nick Kralevich | 29e7813 | 2014-01-17 16:16:42 -0800 | [diff] [blame] | 234 | fchmod(fd, mode); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 235 | } |
| 236 | |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 237 | while (true) { |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 238 | if (!ReadFdExactly(s, &msg.data, sizeof(msg.data))) goto fail; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 239 | |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 240 | if (msg.data.id != ID_DATA) { |
| 241 | if (msg.data.id == ID_DONE) { |
Elliott Hughes | 9e8e355 | 2015-08-24 14:27:03 -0700 | [diff] [blame] | 242 | timestamp = msg.data.size; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 243 | break; |
| 244 | } |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 245 | SendSyncFail(s, "invalid data message"); |
Josh Gao | 013a8eb | 2016-02-19 14:33:14 -0800 | [diff] [blame] | 246 | goto abort; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 247 | } |
Josh Gao | 013a8eb | 2016-02-19 14:33:14 -0800 | [diff] [blame] | 248 | |
| 249 | if (msg.data.size > buffer.size()) { // TODO: resize buffer? |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 250 | SendSyncFail(s, "oversize data message"); |
Josh Gao | 013a8eb | 2016-02-19 14:33:14 -0800 | [diff] [blame] | 251 | goto abort; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 252 | } |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 253 | |
Josh Gao | 013a8eb | 2016-02-19 14:33:14 -0800 | [diff] [blame] | 254 | if (!ReadFdExactly(s, &buffer[0], msg.data.size)) goto abort; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 255 | |
Josh Gao | 013a8eb | 2016-02-19 14:33:14 -0800 | [diff] [blame] | 256 | if (!WriteFdExactly(fd, &buffer[0], msg.data.size)) { |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 257 | SendSyncFailErrno(s, "write failed"); |
| 258 | goto fail; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 262 | adb_close(fd); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 263 | |
Jin Qian | 8833f14 | 2016-11-02 16:27:17 -0700 | [diff] [blame] | 264 | if (!update_capabilities(path, capabilities)) { |
| 265 | SendSyncFailErrno(s, "update_capabilities failed"); |
| 266 | goto fail; |
| 267 | } |
| 268 | |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 269 | utimbuf u; |
| 270 | u.actime = timestamp; |
| 271 | u.modtime = timestamp; |
| 272 | utime(path, &u); |
| 273 | |
| 274 | msg.status.id = ID_OKAY; |
| 275 | msg.status.msglen = 0; |
| 276 | return WriteFdExactly(s, &msg.status, sizeof(msg.status)); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 277 | |
| 278 | fail: |
Josh Gao | 013a8eb | 2016-02-19 14:33:14 -0800 | [diff] [blame] | 279 | // If there's a problem on the device, we'll send an ID_FAIL message and |
| 280 | // close the socket. Unfortunately the kernel will sometimes throw that |
| 281 | // data away if the other end keeps writing without reading (which is |
| 282 | // the case with old versions of adb). To maintain compatibility, keep |
| 283 | // reading and throwing away ID_DATA packets until the other side notices |
| 284 | // that we've reported an error. |
| 285 | while (true) { |
| 286 | if (!ReadFdExactly(s, &msg.data, sizeof(msg.data))) goto fail; |
| 287 | |
| 288 | if (msg.data.id == ID_DONE) { |
| 289 | goto abort; |
| 290 | } else if (msg.data.id != ID_DATA) { |
| 291 | char id[5]; |
| 292 | memcpy(id, &msg.data.id, sizeof(msg.data.id)); |
| 293 | id[4] = '\0'; |
| 294 | D("handle_send_fail received unexpected id '%s' during failure", id); |
| 295 | goto abort; |
| 296 | } |
| 297 | |
| 298 | if (msg.data.size > buffer.size()) { |
| 299 | D("handle_send_fail received oversized packet of length '%u' during failure", |
| 300 | msg.data.size); |
| 301 | goto abort; |
| 302 | } |
| 303 | |
| 304 | if (!ReadFdExactly(s, &buffer[0], msg.data.size)) goto abort; |
| 305 | } |
| 306 | |
| 307 | abort: |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 308 | if (fd >= 0) adb_close(fd); |
JP Abgrall | bb5f0d2 | 2014-03-07 17:31:25 -0800 | [diff] [blame] | 309 | if (do_unlink) adb_unlink(path); |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 310 | return false; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 311 | } |
| 312 | |
Elliott Hughes | 944e1d7 | 2015-01-12 14:26:36 -0800 | [diff] [blame] | 313 | #if defined(_WIN32) |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 314 | extern bool handle_send_link(int s, const std::string& path, std::vector<char>& buffer) __attribute__((error("no symlinks on Windows"))); |
Elliott Hughes | 944e1d7 | 2015-01-12 14:26:36 -0800 | [diff] [blame] | 315 | #else |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 316 | static bool handle_send_link(int s, const std::string& path, std::vector<char>& buffer) { |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 317 | syncmsg msg; |
| 318 | unsigned int len; |
| 319 | int ret; |
| 320 | |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 321 | if (!ReadFdExactly(s, &msg.data, sizeof(msg.data))) return false; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 322 | |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 323 | if (msg.data.id != ID_DATA) { |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 324 | SendSyncFail(s, "invalid data message: expected ID_DATA"); |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 325 | return false; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 326 | } |
| 327 | |
Elliott Hughes | 9e8e355 | 2015-08-24 14:27:03 -0700 | [diff] [blame] | 328 | len = msg.data.size; |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 329 | if (len > buffer.size()) { // TODO: resize buffer? |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 330 | SendSyncFail(s, "oversize data message"); |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 331 | return false; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 332 | } |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 333 | if (!ReadFdExactly(s, &buffer[0], len)) return false; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 334 | |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 335 | ret = symlink(&buffer[0], path.c_str()); |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 336 | if (ret && errno == ENOENT) { |
Colin Cross | e679407 | 2017-02-23 21:23:05 -0800 | [diff] [blame] | 337 | if (!secure_mkdirs(android::base::Dirname(path))) { |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 338 | SendSyncFailErrno(s, "secure_mkdirs failed"); |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 339 | return false; |
Liang Cheng | 155c49a | 2014-01-02 18:27:51 -0800 | [diff] [blame] | 340 | } |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 341 | ret = symlink(&buffer[0], path.c_str()); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 342 | } |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 343 | if (ret) { |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 344 | SendSyncFailErrno(s, "symlink failed"); |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 345 | return false; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 346 | } |
| 347 | |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 348 | if (!ReadFdExactly(s, &msg.data, sizeof(msg.data))) return false; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 349 | |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 350 | if (msg.data.id == ID_DONE) { |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 351 | msg.status.id = ID_OKAY; |
| 352 | msg.status.msglen = 0; |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 353 | if (!WriteFdExactly(s, &msg.status, sizeof(msg.status))) return false; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 354 | } else { |
Josh Gao | bd446be | 2016-01-28 16:21:12 -0800 | [diff] [blame] | 355 | SendSyncFail(s, "invalid data message: expected ID_DONE"); |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 356 | return false; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 357 | } |
| 358 | |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 359 | return true; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 360 | } |
Elliott Hughes | 944e1d7 | 2015-01-12 14:26:36 -0800 | [diff] [blame] | 361 | #endif |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 362 | |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 363 | static bool do_send(int s, const std::string& spec, std::vector<char>& buffer) { |
| 364 | // 'spec' is of the form "/some/path,0755". Break it up. |
| 365 | size_t comma = spec.find_last_of(','); |
| 366 | if (comma == std::string::npos) { |
Josh Gao | bd446be | 2016-01-28 16:21:12 -0800 | [diff] [blame] | 367 | SendSyncFail(s, "missing , in ID_SEND"); |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 368 | return false; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 369 | } |
| 370 | |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 371 | std::string path = spec.substr(0, comma); |
| 372 | |
| 373 | errno = 0; |
| 374 | mode_t mode = strtoul(spec.substr(comma + 1).c_str(), nullptr, 0); |
| 375 | if (errno != 0) { |
Josh Gao | bd446be | 2016-01-28 16:21:12 -0800 | [diff] [blame] | 376 | SendSyncFail(s, "bad mode"); |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 377 | return false; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 378 | } |
| 379 | |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 380 | // Don't delete files before copying if they are not "regular" or symlinks. |
| 381 | struct stat st; |
| 382 | bool do_unlink = (lstat(path.c_str(), &st) == -1) || S_ISREG(st.st_mode) || S_ISLNK(st.st_mode); |
| 383 | if (do_unlink) { |
| 384 | adb_unlink(path.c_str()); |
| 385 | } |
| 386 | |
| 387 | if (S_ISLNK(mode)) { |
| 388 | return handle_send_link(s, path.c_str(), buffer); |
| 389 | } |
| 390 | |
| 391 | // Copy user permission bits to "group" and "other" permissions. |
| 392 | mode &= 0777; |
| 393 | mode |= ((mode >> 3) & 0070); |
| 394 | mode |= ((mode >> 3) & 0007); |
| 395 | |
Elliott Hughes | 944e1d7 | 2015-01-12 14:26:36 -0800 | [diff] [blame] | 396 | uid_t uid = -1; |
| 397 | gid_t gid = -1; |
Elliott Hughes | 02c9474 | 2016-06-07 17:18:25 -0700 | [diff] [blame] | 398 | uint64_t capabilities = 0; |
Elliott Hughes | dedf767 | 2015-03-16 21:58:32 +0000 | [diff] [blame] | 399 | if (should_use_fs_config(path)) { |
Elliott Hughes | 3dcb3bf | 2015-08-25 11:09:04 -0700 | [diff] [blame] | 400 | unsigned int broken_api_hack = mode; |
Elliott Hughes | 02c9474 | 2016-06-07 17:18:25 -0700 | [diff] [blame] | 401 | fs_config(path.c_str(), 0, nullptr, &uid, &gid, &broken_api_hack, &capabilities); |
Elliott Hughes | 8979ed2 | 2015-08-25 11:01:39 -0700 | [diff] [blame] | 402 | mode = broken_api_hack; |
Elliott Hughes | 944e1d7 | 2015-01-12 14:26:36 -0800 | [diff] [blame] | 403 | } |
Elliott Hughes | 02c9474 | 2016-06-07 17:18:25 -0700 | [diff] [blame] | 404 | return handle_send_file(s, path.c_str(), uid, gid, capabilities, mode, buffer, do_unlink); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 405 | } |
| 406 | |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 407 | static bool do_recv(int s, const char* path, std::vector<char>& buffer) { |
Rubin Xu | 29a64f9 | 2016-01-11 10:23:47 +0000 | [diff] [blame] | 408 | __android_log_security_bswrite(SEC_TAG_ADB_RECV_FILE, path); |
| 409 | |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 410 | int fd = adb_open(path, O_RDONLY | O_CLOEXEC); |
| 411 | if (fd < 0) { |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 412 | SendSyncFailErrno(s, "open failed"); |
| 413 | return false; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 414 | } |
| 415 | |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 416 | syncmsg msg; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 417 | msg.data.id = ID_DATA; |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 418 | while (true) { |
| 419 | int r = adb_read(fd, &buffer[0], buffer.size()); |
| 420 | if (r <= 0) { |
| 421 | if (r == 0) break; |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 422 | SendSyncFailErrno(s, "read failed"); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 423 | adb_close(fd); |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 424 | return false; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 425 | } |
Elliott Hughes | 9e8e355 | 2015-08-24 14:27:03 -0700 | [diff] [blame] | 426 | msg.data.size = r; |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 427 | if (!WriteFdExactly(s, &msg.data, sizeof(msg.data)) || !WriteFdExactly(s, &buffer[0], r)) { |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 428 | adb_close(fd); |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 429 | return false; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 430 | } |
| 431 | } |
| 432 | |
| 433 | adb_close(fd); |
| 434 | |
| 435 | msg.data.id = ID_DONE; |
| 436 | msg.data.size = 0; |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 437 | return WriteFdExactly(s, &msg.data, sizeof(msg.data)); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 438 | } |
| 439 | |
Josh Gao | 14ed70a | 2016-11-22 14:33:08 -0800 | [diff] [blame] | 440 | static const char* sync_id_to_name(uint32_t id) { |
| 441 | switch (id) { |
| 442 | case ID_LSTAT_V1: |
| 443 | return "lstat_v1"; |
| 444 | case ID_LSTAT_V2: |
| 445 | return "lstat_v2"; |
| 446 | case ID_STAT_V2: |
| 447 | return "stat_v2"; |
| 448 | case ID_LIST: |
| 449 | return "list"; |
| 450 | case ID_SEND: |
| 451 | return "send"; |
| 452 | case ID_RECV: |
| 453 | return "recv"; |
| 454 | case ID_QUIT: |
| 455 | return "quit"; |
| 456 | default: |
| 457 | return "???"; |
| 458 | } |
| 459 | } |
| 460 | |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 461 | static bool handle_sync_command(int fd, std::vector<char>& buffer) { |
Yabin Cui | 815ad88 | 2015-09-02 17:44:28 -0700 | [diff] [blame] | 462 | D("sync: waiting for request"); |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 463 | |
Josh Gao | 14ed70a | 2016-11-22 14:33:08 -0800 | [diff] [blame] | 464 | ATRACE_CALL(); |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 465 | SyncRequest request; |
| 466 | if (!ReadFdExactly(fd, &request, sizeof(request))) { |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 467 | SendSyncFail(fd, "command read failure"); |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 468 | return false; |
| 469 | } |
Elliott Hughes | 9e8e355 | 2015-08-24 14:27:03 -0700 | [diff] [blame] | 470 | size_t path_length = request.path_length; |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 471 | if (path_length > 1024) { |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 472 | SendSyncFail(fd, "path too long"); |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 473 | return false; |
| 474 | } |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 475 | char name[1025]; |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 476 | if (!ReadFdExactly(fd, name, path_length)) { |
Elliott Hughes | d73ef20 | 2015-08-24 19:30:46 -0700 | [diff] [blame] | 477 | SendSyncFail(fd, "filename read failure"); |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 478 | return false; |
| 479 | } |
| 480 | name[path_length] = 0; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 481 | |
Josh Gao | 14ed70a | 2016-11-22 14:33:08 -0800 | [diff] [blame] | 482 | std::string id_name = sync_id_to_name(request.id); |
| 483 | std::string trace_name = StringPrintf("%s(%s)", id_name.c_str(), name); |
| 484 | ATRACE_NAME(trace_name.c_str()); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 485 | |
Josh Gao | 14ed70a | 2016-11-22 14:33:08 -0800 | [diff] [blame] | 486 | D("sync: %s('%s')", id_name.c_str(), name); |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 487 | switch (request.id) { |
Josh Gao | a2cf375 | 2016-12-05 17:11:34 -0800 | [diff] [blame] | 488 | case ID_LSTAT_V1: |
| 489 | if (!do_lstat_v1(fd, name)) return false; |
| 490 | break; |
| 491 | case ID_LSTAT_V2: |
| 492 | case ID_STAT_V2: |
| 493 | if (!do_stat_v2(fd, request.id, name)) return false; |
| 494 | break; |
| 495 | case ID_LIST: |
| 496 | if (!do_list(fd, name)) return false; |
| 497 | break; |
| 498 | case ID_SEND: |
| 499 | if (!do_send(fd, name, buffer)) return false; |
| 500 | break; |
| 501 | case ID_RECV: |
| 502 | if (!do_recv(fd, name, buffer)) return false; |
| 503 | break; |
| 504 | case ID_QUIT: |
| 505 | return false; |
| 506 | default: |
Josh Gao | 14ed70a | 2016-11-22 14:33:08 -0800 | [diff] [blame] | 507 | SendSyncFail(fd, StringPrintf("unknown command %08x", request.id)); |
Josh Gao | a2cf375 | 2016-12-05 17:11:34 -0800 | [diff] [blame] | 508 | return false; |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 509 | } |
| 510 | |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 511 | return true; |
| 512 | } |
| 513 | |
Josh Gao | a2cf375 | 2016-12-05 17:11:34 -0800 | [diff] [blame] | 514 | void file_sync_service(int fd, void*) { |
Elliott Hughes | b628cb1 | 2015-08-03 10:38:08 -0700 | [diff] [blame] | 515 | std::vector<char> buffer(SYNC_DATA_MAX); |
| 516 | |
| 517 | while (handle_sync_command(fd, buffer)) { |
| 518 | } |
| 519 | |
Yabin Cui | 815ad88 | 2015-09-02 17:44:28 -0700 | [diff] [blame] | 520 | D("sync: done"); |
The Android Open Source Project | 9ca14dc | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 521 | adb_close(fd); |
| 522 | } |