adb: clean up debug tracing a little.
Always use LOG() for debug tracing.
Remove useless D_lock. I believe it is useless to lock just before and after fprintf.
I verified the log output both on host and on device. The output looks fine to me.
Change-Id: I96ccfe408ff56864361551afe9ad464d197ae104
diff --git a/adb/sockets.cpp b/adb/sockets.cpp
index 9c13936..f8c22cc 100644
--- a/adb/sockets.cpp
+++ b/adb/sockets.cpp
@@ -133,7 +133,7 @@
static int local_socket_enqueue(asocket *s, apacket *p)
{
- D("LS(%d): enqueue %d\n", s->id, p->len);
+ D("LS(%d): enqueue %d", s->id, p->len);
p->ptr = p->data;
@@ -156,7 +156,7 @@
continue;
}
if((r == 0) || (errno != EAGAIN)) {
- D( "LS(%d): not ready, errno=%d: %s\n", s->id, errno, strerror(errno) );
+ D( "LS(%d): not ready, errno=%d: %s", s->id, errno, strerror(errno) );
s->close(s);
return 1; /* not ready (error) */
} else {
@@ -204,7 +204,7 @@
apacket *p, *n;
int exit_on_close = s->exit_on_close;
- D("LS(%d): destroying fde.fd=%d\n", s->id, s->fde.fd);
+ D("LS(%d): destroying fde.fd=%d", s->id, s->fde.fd);
/* IMPORTANT: the remove closes the fd
** that belongs to this socket
@@ -213,7 +213,7 @@
/* dispose of any unwritten data */
for(p = s->pkt_first; p; p = n) {
- D("LS(%d): discarding %d bytes\n", s->id, p->len);
+ D("LS(%d): discarding %d bytes", s->id, p->len);
n = p->next;
put_apacket(p);
}
@@ -221,7 +221,7 @@
free(s);
if (exit_on_close) {
- D("local_socket_destroy: exiting\n");
+ D("local_socket_destroy: exiting");
exit(1);
}
}
@@ -229,9 +229,9 @@
static void local_socket_close_locked(asocket *s)
{
- D("entered local_socket_close_locked. LS(%d) fd=%d\n", s->id, s->fd);
+ D("entered local_socket_close_locked. LS(%d) fd=%d", s->id, s->fd);
if(s->peer) {
- D("LS(%d): closing peer. peer->id=%d peer->fd=%d\n",
+ D("LS(%d): closing peer. peer->id=%d peer->fd=%d",
s->id, s->peer->id, s->peer->fd);
/* Note: it's important to call shutdown before disconnecting from
* the peer, this ensures that remote sockets can still get the id
@@ -255,24 +255,24 @@
if (s->closing || s->pkt_first == NULL) {
int id = s->id;
local_socket_destroy(s);
- D("LS(%d): closed\n", id);
+ D("LS(%d): closed", id);
return;
}
/* otherwise, put on the closing list
*/
- D("LS(%d): closing\n", s->id);
+ D("LS(%d): closing", s->id);
s->closing = 1;
fdevent_del(&s->fde, FDE_READ);
remove_socket(s);
- D("LS(%d): put on socket_closing_list fd=%d\n", s->id, s->fd);
+ D("LS(%d): put on socket_closing_list fd=%d", s->id, s->fd);
insert_local_socket(s, &local_socket_closing_list);
}
static void local_socket_event_func(int fd, unsigned ev, void* _s)
{
asocket* s = reinterpret_cast<asocket*>(_s);
- D("LS(%d): event_func(fd=%d(==%d), ev=%04x)\n", s->id, s->fd, fd, ev);
+ D("LS(%d): event_func(fd=%d(==%d), ev=%04x)", s->id, s->fd, fd, ev);
/* put the FDE_WRITE processing before the FDE_READ
** in order to simplify the code.
@@ -295,7 +295,7 @@
continue;
}
- D(" closing after write because r=%d and errno is %d\n", r, errno);
+ D(" closing after write because r=%d and errno is %d", r, errno);
s->close(s);
return;
}
@@ -313,7 +313,7 @@
** we can now destroy it.
*/
if (s->closing) {
- D(" closing because 'closing' is set after write\n");
+ D(" closing because 'closing' is set after write");
s->close(s);
return;
}
@@ -337,7 +337,7 @@
while (avail > 0) {
r = adb_read(fd, x, avail);
- D("LS(%d): post adb_read(fd=%d,...) r=%d (errno=%d) avail=%zu\n",
+ D("LS(%d): post adb_read(fd=%d,...) r=%d (errno=%d) avail=%zu",
s->id, s->fd, r, r < 0 ? errno : 0, avail);
if (r == -1) {
if (errno == EAGAIN) {
@@ -353,7 +353,7 @@
is_eof = 1;
break;
}
- D("LS(%d): fd=%d post avail loop. r=%d is_eof=%d forced_eof=%d\n",
+ D("LS(%d): fd=%d post avail loop. r=%d is_eof=%d forced_eof=%d",
s->id, s->fd, r, is_eof, s->fde.force_eof);
if ((avail == max_payload) || (s->peer == 0)) {
put_apacket(p);
@@ -365,7 +365,7 @@
unsigned saved_id = s->id;
int saved_fd = s->fd;
r = s->peer->enqueue(s->peer, p);
- D("LS(%u): fd=%d post peer->enqueue(). r=%d\n", saved_id, saved_fd, r);
+ D("LS(%u): fd=%d post peer->enqueue(). r=%d", saved_id, saved_fd, r);
if (r < 0) {
/* error return means they closed us as a side-effect
@@ -389,7 +389,7 @@
}
/* Don't allow a forced eof if data is still there */
if ((s->fde.force_eof && !r) || is_eof) {
- D(" closing because is_eof=%d r=%d s->fde.force_eof=%d\n",
+ D(" closing because is_eof=%d r=%d s->fde.force_eof=%d",
is_eof, r, s->fde.force_eof);
s->close(s);
}
@@ -400,7 +400,7 @@
** catching it here means we may skip the last few
** bytes of readable data.
*/
- D("LS(%d): FDE_ERROR (fd=%d)\n", s->id, s->fd);
+ D("LS(%d): FDE_ERROR (fd=%d)", s->id, s->fd);
return;
}
@@ -418,7 +418,7 @@
install_local_socket(s);
fdevent_install(&s->fde, fd, local_socket_event_func, s);
- D("LS(%d): created (fd=%d)\n", s->id, s->fd);
+ D("LS(%d): created (fd=%d)", s->id, s->fd);
return s;
}
@@ -436,7 +436,7 @@
if(fd < 0) return 0;
asocket* s = create_local_socket(fd);
- D("LS(%d): bound to '%s' via %d\n", s->id, name, fd);
+ D("LS(%d): bound to '%s' via %d", s->id, name, fd);
#if !ADB_HOST
char debug[PROPERTY_VALUE_MAX];
@@ -447,7 +447,7 @@
|| (!strncmp(name, "unroot:", 7) && getuid() == 0)
|| !strncmp(name, "usb:", 4)
|| !strncmp(name, "tcpip:", 6)) {
- D("LS(%d): enabling exit_on_close\n", s->id);
+ D("LS(%d): enabling exit_on_close", s->id);
s->exit_on_close = 1;
}
#endif
@@ -463,7 +463,7 @@
s = host_service_to_socket(name, serial);
if (s != NULL) {
- D("LS(%d) bound to '%s'\n", s->id, name);
+ D("LS(%d) bound to '%s'", s->id, name);
return s;
}
@@ -473,7 +473,7 @@
static int remote_socket_enqueue(asocket *s, apacket *p)
{
- D("entered remote_socket_enqueue RS(%d) WRITE fd=%d peer.fd=%d\n",
+ D("entered remote_socket_enqueue RS(%d) WRITE fd=%d peer.fd=%d",
s->id, s->fd, s->peer->fd);
p->msg.command = A_WRTE;
p->msg.arg0 = s->peer->id;
@@ -485,7 +485,7 @@
static void remote_socket_ready(asocket *s)
{
- D("entered remote_socket_ready RS(%d) OKAY fd=%d peer.fd=%d\n",
+ D("entered remote_socket_ready RS(%d) OKAY fd=%d peer.fd=%d",
s->id, s->fd, s->peer->fd);
apacket *p = get_apacket();
p->msg.command = A_OKAY;
@@ -496,7 +496,7 @@
static void remote_socket_shutdown(asocket *s)
{
- D("entered remote_socket_shutdown RS(%d) CLOSE fd=%d peer->fd=%d\n",
+ D("entered remote_socket_shutdown RS(%d) CLOSE fd=%d peer->fd=%d",
s->id, s->fd, s->peer?s->peer->fd:-1);
apacket *p = get_apacket();
p->msg.command = A_CLSE;
@@ -511,13 +511,13 @@
{
if (s->peer) {
s->peer->peer = 0;
- D("RS(%d) peer->close()ing peer->id=%d peer->fd=%d\n",
+ D("RS(%d) peer->close()ing peer->id=%d peer->fd=%d",
s->id, s->peer->id, s->peer->fd);
s->peer->close(s->peer);
}
- D("entered remote_socket_close RS(%d) CLOSE fd=%d peer->fd=%d\n",
+ D("entered remote_socket_close RS(%d) CLOSE fd=%d peer->fd=%d",
s->id, s->fd, s->peer?s->peer->fd:-1);
- D("RS(%d): closed\n", s->id);
+ D("RS(%d): closed", s->id);
free(s);
}
@@ -538,13 +538,13 @@
s->close = remote_socket_close;
s->transport = t;
- D("RS(%d): created\n", s->id);
+ D("RS(%d): created", s->id);
return s;
}
void connect_to_remote(asocket *s, const char *destination)
{
- D("Connect_to_remote call RS(%d) fd=%d\n", s->id, s->fd);
+ D("Connect_to_remote call RS(%d) fd=%d", s->id, s->fd);
apacket *p = get_apacket();
size_t len = strlen(destination) + 1;
@@ -552,7 +552,7 @@
fatal("destination oversized");
}
- D("LS(%d): connect('%s')\n", s->id, destination);
+ D("LS(%d): connect('%s')", s->id, destination);
p->msg.command = A_OPEN;
p->msg.arg0 = s->id;
p->msg.data_length = len;
@@ -671,14 +671,14 @@
TransportType type = kTransportAny;
#endif
- D("SS(%d): enqueue %d\n", s->id, p->len);
+ D("SS(%d): enqueue %d", s->id, p->len);
if(s->pkt_first == 0) {
s->pkt_first = p;
s->pkt_last = p;
} else {
if((s->pkt_first->len + p->len) > s->get_max_payload()) {
- D("SS(%d): overflow\n", s->id);
+ D("SS(%d): overflow", s->id);
put_apacket(p);
goto fail;
}
@@ -696,20 +696,20 @@
len = unhex(p->data, 4);
if((len < 1) || (len > 1024)) {
- D("SS(%d): bad size (%d)\n", s->id, len);
+ D("SS(%d): bad size (%d)", s->id, len);
goto fail;
}
- D("SS(%d): len is %d\n", s->id, len );
+ D("SS(%d): len is %d", s->id, len );
/* can't do anything until we have the full header */
if((len + 4) > p->len) {
- D("SS(%d): waiting for %d more bytes\n", s->id, len+4 - p->len);
+ D("SS(%d): waiting for %d more bytes", s->id, len+4 - p->len);
return 0;
}
p->data[len + 4] = 0;
- D("SS(%d): '%s'\n", s->id, (char*) (p->data + 4));
+ D("SS(%d): '%s'", s->id, (char*) (p->data + 4));
#if ADB_HOST
service = (char *)p->data + 4;
@@ -747,11 +747,11 @@
*/
if(handle_host_request(service, type, serial, s->peer->fd, s) == 0) {
/* XXX fail message? */
- D( "SS(%d): handled host service '%s'\n", s->id, service );
+ D( "SS(%d): handled host service '%s'", s->id, service );
goto fail;
}
if (!strncmp(service, "transport", strlen("transport"))) {
- D( "SS(%d): okay transport\n", s->id );
+ D( "SS(%d): okay transport", s->id );
p->len = 0;
return 0;
}
@@ -762,7 +762,7 @@
*/
s2 = create_host_service_socket(service, serial);
if(s2 == 0) {
- D( "SS(%d): couldn't create host service '%s'\n", s->id, service );
+ D( "SS(%d): couldn't create host service '%s'", s->id, service );
SendFail(s->peer->fd, "unknown host service");
goto fail;
}
@@ -782,7 +782,7 @@
s->peer->peer = s2;
s2->peer = s->peer;
s->peer = 0;
- D( "SS(%d): okay\n", s->id );
+ D( "SS(%d): okay", s->id );
s->close(s);
/* initial state is "ready" */
@@ -839,12 +839,12 @@
static void smart_socket_ready(asocket *s)
{
- D("SS(%d): ready\n", s->id);
+ D("SS(%d): ready", s->id);
}
static void smart_socket_close(asocket *s)
{
- D("SS(%d): closed\n", s->id);
+ D("SS(%d): closed", s->id);
if(s->pkt_first){
put_apacket(s->pkt_first);
}
@@ -858,7 +858,7 @@
static asocket *create_smart_socket(void)
{
- D("Creating smart socket \n");
+ D("Creating smart socket");
asocket *s = reinterpret_cast<asocket*>(calloc(1, sizeof(asocket)));
if (s == NULL) fatal("cannot allocate socket");
s->enqueue = smart_socket_enqueue;
@@ -866,13 +866,13 @@
s->shutdown = NULL;
s->close = smart_socket_close;
- D("SS(%d)\n", s->id);
+ D("SS(%d)", s->id);
return s;
}
void connect_to_smartsocket(asocket *s)
{
- D("Connecting to smart socket \n");
+ D("Connecting to smart socket");
asocket *ss = create_smart_socket();
s->peer = ss;
ss->peer = s;