adb: delete vestigial SHELL_EXIT_NOTIFY_FD.
There exists no path through which a value other than -1 can be written
to the SHELL_EXIT_NOTIFY_FD.
Bug: http://b/74616284
Test: adb_test
Test: adbd_test
Test: python test_device.py
Change-Id: I0630c302ba06bc76917f0445aea75d2dbe1dc865
(cherry picked from commit dcc055af64
)
This commit is contained in:
parent
7c87b0739a
commit
cc9414eda4
5 changed files with 0 additions and 121 deletions
|
@ -196,10 +196,6 @@ ConnectionState connection_state(atransport* t);
|
|||
|
||||
extern const char* adb_device_banner;
|
||||
|
||||
#if !ADB_HOST
|
||||
extern int SHELL_EXIT_NOTIFY_FD;
|
||||
#endif // !ADB_HOST
|
||||
|
||||
#define CHUNK_SIZE (64 * 1024)
|
||||
|
||||
#if !ADB_HOST
|
||||
|
|
|
@ -42,13 +42,6 @@
|
|||
#include "adb_unique_fd.h"
|
||||
#include "adb_utils.h"
|
||||
|
||||
#if !ADB_HOST
|
||||
// This socket is used when a subproc shell service exists.
|
||||
// It wakes up the fdevent_loop() and cause the correct handling
|
||||
// of the shell's pseudo-tty master. I.e. force close it.
|
||||
int SHELL_EXIT_NOTIFY_FD = -1;
|
||||
#endif // !ADB_HOST
|
||||
|
||||
#define FDE_EVENTMASK 0x00ff
|
||||
#define FDE_STATEMASK 0xff00
|
||||
|
||||
|
@ -294,72 +287,6 @@ static void fdevent_call_fdfunc(fdevent* fde) {
|
|||
fde->func(fde->fd, events, fde->arg);
|
||||
}
|
||||
|
||||
#if !ADB_HOST
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
static void fdevent_subproc_event_func(int fd, unsigned ev, void* /* userdata */) {
|
||||
D("subproc handling on fd = %d, ev = %x", fd, ev);
|
||||
|
||||
CHECK_GE(fd, 0);
|
||||
|
||||
if (ev & FDE_READ) {
|
||||
int subproc_fd;
|
||||
|
||||
if(!ReadFdExactly(fd, &subproc_fd, sizeof(subproc_fd))) {
|
||||
LOG(FATAL) << "Failed to read the subproc's fd from " << fd;
|
||||
}
|
||||
auto it = g_poll_node_map.find(subproc_fd);
|
||||
if (it == g_poll_node_map.end()) {
|
||||
D("subproc_fd %d cleared from fd_table", subproc_fd);
|
||||
adb_close(subproc_fd);
|
||||
return;
|
||||
}
|
||||
fdevent* subproc_fde = it->second.fde;
|
||||
if(subproc_fde->fd != subproc_fd) {
|
||||
// Already reallocated?
|
||||
LOG(FATAL) << "subproc_fd(" << subproc_fd << ") != subproc_fde->fd(" << subproc_fde->fd
|
||||
<< ")";
|
||||
return;
|
||||
}
|
||||
|
||||
subproc_fde->force_eof = 1;
|
||||
|
||||
int rcount = 0;
|
||||
ioctl(subproc_fd, FIONREAD, &rcount);
|
||||
D("subproc with fd %d has rcount=%d, err=%d", subproc_fd, rcount, errno);
|
||||
if (rcount != 0) {
|
||||
// If there is data left, it will show up in the select().
|
||||
// This works because there is no other thread reading that
|
||||
// data when in this fd_func().
|
||||
return;
|
||||
}
|
||||
|
||||
D("subproc_fde %s", dump_fde(subproc_fde).c_str());
|
||||
subproc_fde->events |= FDE_READ;
|
||||
if(subproc_fde->state & FDE_PENDING) {
|
||||
return;
|
||||
}
|
||||
subproc_fde->state |= FDE_PENDING;
|
||||
fdevent_call_fdfunc(subproc_fde);
|
||||
}
|
||||
}
|
||||
|
||||
static void fdevent_subproc_setup() {
|
||||
int s[2];
|
||||
|
||||
if(adb_socketpair(s)) {
|
||||
PLOG(FATAL) << "cannot create shell-exit socket-pair";
|
||||
}
|
||||
D("fdevent_subproc: socket pair (%d, %d)", s[0], s[1]);
|
||||
|
||||
SHELL_EXIT_NOTIFY_FD = s[0];
|
||||
fdevent *fde = fdevent_create(s[1], fdevent_subproc_event_func, NULL);
|
||||
CHECK(fde != nullptr) << "cannot create fdevent for shell-exit handler";
|
||||
fdevent_add(fde, FDE_READ);
|
||||
}
|
||||
#endif // !ADB_HOST
|
||||
|
||||
static void fdevent_run_flush() EXCLUDES(run_queue_mutex) {
|
||||
// We need to be careful around reentrancy here, since a function we call can queue up another
|
||||
// function.
|
||||
|
@ -433,9 +360,6 @@ void fdevent_run_on_main_thread(std::function<void()> fn) {
|
|||
|
||||
void fdevent_loop() {
|
||||
set_main_thread();
|
||||
#if !ADB_HOST
|
||||
fdevent_subproc_setup();
|
||||
#endif // !ADB_HOST
|
||||
fdevent_run_setup();
|
||||
|
||||
while (true) {
|
||||
|
|
|
@ -52,13 +52,8 @@ class FdeventTest : public ::testing::Test {
|
|||
}
|
||||
|
||||
size_t GetAdditionalLocalSocketCount() {
|
||||
#if ADB_HOST
|
||||
// dummy socket installed in PrepareThread() + fdevent_run_on_main_thread socket
|
||||
return 2;
|
||||
#else
|
||||
// dummy socket + fdevent_run_on_main_thread + fdevent_subproc_setup() sockets
|
||||
return 3;
|
||||
#endif
|
||||
}
|
||||
|
||||
void TerminateThread(std::thread& thread) {
|
||||
|
|
|
@ -681,22 +681,6 @@ void Subprocess::WaitForExit() {
|
|||
}
|
||||
protocol_sfd_.reset(-1);
|
||||
}
|
||||
|
||||
// Pass the local socket FD to the shell cleanup fdevent.
|
||||
if (SHELL_EXIT_NOTIFY_FD >= 0) {
|
||||
int fd = local_socket_sfd_;
|
||||
if (WriteFdExactly(SHELL_EXIT_NOTIFY_FD, &fd, sizeof(fd))) {
|
||||
D("passed fd %d to SHELL_EXIT_NOTIFY_FD (%d) for pid %d",
|
||||
fd, SHELL_EXIT_NOTIFY_FD, pid_);
|
||||
// The shell exit fdevent now owns the FD and will close it once
|
||||
// the last bit of data flushes through.
|
||||
static_cast<void>(local_socket_sfd_.release());
|
||||
} else {
|
||||
PLOG(ERROR) << "failed to write fd " << fd
|
||||
<< " to SHELL_EXIT_NOTIFY_FD (" << SHELL_EXIT_NOTIFY_FD
|
||||
<< ") for pid " << pid_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -55,40 +55,20 @@ class ShellServiceTest : public ::testing::Test {
|
|||
static sighandler_t saved_sigpipe_handler_;
|
||||
|
||||
int subprocess_fd_ = -1;
|
||||
int shell_exit_receiver_fd_ = -1, saved_shell_exit_fd_;
|
||||
};
|
||||
|
||||
sighandler_t ShellServiceTest::saved_sigpipe_handler_ = nullptr;
|
||||
|
||||
void ShellServiceTest::StartTestSubprocess(
|
||||
const char* command, SubprocessType type, SubprocessProtocol protocol) {
|
||||
// We want to intercept the shell exit message to make sure it's sent.
|
||||
saved_shell_exit_fd_ = SHELL_EXIT_NOTIFY_FD;
|
||||
int fd[2];
|
||||
ASSERT_TRUE(adb_socketpair(fd) >= 0);
|
||||
SHELL_EXIT_NOTIFY_FD = fd[0];
|
||||
shell_exit_receiver_fd_ = fd[1];
|
||||
|
||||
subprocess_fd_ = StartSubprocess(command, nullptr, type, protocol);
|
||||
ASSERT_TRUE(subprocess_fd_ >= 0);
|
||||
}
|
||||
|
||||
void ShellServiceTest::CleanupTestSubprocess() {
|
||||
if (subprocess_fd_ >= 0) {
|
||||
// Subprocess should send its FD to SHELL_EXIT_NOTIFY_FD for cleanup.
|
||||
int notified_fd = -1;
|
||||
ASSERT_TRUE(ReadFdExactly(shell_exit_receiver_fd_, ¬ified_fd,
|
||||
sizeof(notified_fd)));
|
||||
ASSERT_EQ(notified_fd, subprocess_fd_);
|
||||
|
||||
adb_close(subprocess_fd_);
|
||||
subprocess_fd_ = -1;
|
||||
|
||||
// Restore SHELL_EXIT_NOTIFY_FD.
|
||||
adb_close(SHELL_EXIT_NOTIFY_FD);
|
||||
adb_close(shell_exit_receiver_fd_);
|
||||
shell_exit_receiver_fd_ = -1;
|
||||
SHELL_EXIT_NOTIFY_FD = saved_shell_exit_fd_;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue