This commit fixes two somewhat related issues in shell_service.
- The fd returned by StartSubprocess is owned by a unique_fd
contained in the Subprocess object, but also gets closed by the
caller. Resolve this by duping the returned file descriptor.
- A Subprocess object can be destroyed immediately after its initial
construction in StartSubprocess if we're sufficiently unlucky.
Split up the fork/exec and "start management thread" steps, so that
we can safely do everything we need to do on the Subprocess before
handing it over to the thread that'll eventually destroy it.
Also includes squashed patches from AOSP master that allow for use of
unique_fd inside adb.
Bug: http://b/29254462
Change-Id: Id9cf0b7e7a7293bee7176919edc758597691c636
(cherry picked from commit c0e6e40cc9)
(cherry picked from commit 54c72aaccc)
(cherry picked from commit 2c5d1d7cd9)
(cherry picked from commit 2a7b86337f)
(cherry picked from commit 13ea01db45)
(cherry picked from commit 344778da41)
87 lines
2.9 KiB
C++
Executable file
87 lines
2.9 KiB
C++
Executable file
/*
|
|
* Copyright (C) 2015 The Android Open Source Project
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#ifndef ANDROID_BASE_UTF8_H
|
|
#define ANDROID_BASE_UTF8_H
|
|
|
|
#ifdef _WIN32
|
|
#include <string>
|
|
#else
|
|
// Bring in prototypes for standard APIs so that we can import them into the utf8 namespace.
|
|
#include <fcntl.h> // open
|
|
#include <unistd.h> // unlink
|
|
#endif
|
|
|
|
namespace android {
|
|
namespace base {
|
|
|
|
// Only available on Windows because this is only needed on Windows.
|
|
#ifdef _WIN32
|
|
// Convert size number of UTF-16 wchar_t's to UTF-8. Returns whether the
|
|
// conversion was done successfully.
|
|
bool WideToUTF8(const wchar_t* utf16, const size_t size, std::string* utf8);
|
|
|
|
// Convert a NULL-terminated string of UTF-16 characters to UTF-8. Returns
|
|
// whether the conversion was done successfully.
|
|
bool WideToUTF8(const wchar_t* utf16, std::string* utf8);
|
|
|
|
// Convert a UTF-16 std::wstring (including any embedded NULL characters) to
|
|
// UTF-8. Returns whether the conversion was done successfully.
|
|
bool WideToUTF8(const std::wstring& utf16, std::string* utf8);
|
|
|
|
// Convert size number of UTF-8 char's to UTF-16. Returns whether the conversion
|
|
// was done successfully.
|
|
bool UTF8ToWide(const char* utf8, const size_t size, std::wstring* utf16);
|
|
|
|
// Convert a NULL-terminated string of UTF-8 characters to UTF-16. Returns
|
|
// whether the conversion was done successfully.
|
|
bool UTF8ToWide(const char* utf8, std::wstring* utf16);
|
|
|
|
// Convert a UTF-8 std::string (including any embedded NULL characters) to
|
|
// UTF-16. Returns whether the conversion was done successfully.
|
|
bool UTF8ToWide(const std::string& utf8, std::wstring* utf16);
|
|
#endif
|
|
|
|
// The functions in the utf8 namespace take UTF-8 strings. For Windows, these
|
|
// are wrappers, for non-Windows these just expose existing APIs. To call these
|
|
// functions, use:
|
|
//
|
|
// // anonymous namespace to avoid conflict with existing open(), unlink(), etc.
|
|
// namespace {
|
|
// // Import functions into anonymous namespace.
|
|
// using namespace android::base::utf8;
|
|
//
|
|
// void SomeFunction(const char* name) {
|
|
// int fd = open(name, ...); // Calls android::base::utf8::open().
|
|
// ...
|
|
// unlink(name); // Calls android::base::utf8::unlink().
|
|
// }
|
|
// }
|
|
namespace utf8 {
|
|
|
|
#ifdef _WIN32
|
|
int open(const char* name, int flags, ...);
|
|
int unlink(const char* name);
|
|
#else
|
|
using ::open;
|
|
using ::unlink;
|
|
#endif
|
|
|
|
} // namespace utf8
|
|
} // namespace base
|
|
} // namespace android
|
|
|
|
#endif // ANDROID_BASE_UTF8_H
|