OSDN Git Service
(root)
/
android-x86
/
dalvik.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
am beeeb788: am 05fa5fd5: Merge "Simplify merges of the annotation code."
[android-x86/dalvik.git]
/
vm
/
StdioConverter.cpp
diff --git
a/vm/StdioConverter.cpp
b/vm/StdioConverter.cpp
index
a98d473
..
f420c4d
100644
(file)
--- a/
vm/StdioConverter.cpp
+++ b/
vm/StdioConverter.cpp
@@
-27,14
+27,6
@@
#define kFilenoStdout 1
#define kFilenoStderr 2
#define kFilenoStdout 1
#define kFilenoStderr 2
-/*
- * Hold our replacement stdout/stderr.
- */
-struct StdPipes {
- int stdoutPipe[2];
- int stderrPipe[2];
-};
-
#define kMaxLine 512
/*
#define kMaxLine 512
/*
@@
-57,41
+49,35
@@
static bool readAndLog(int fd, BufferedData* data, const char* tag);
*/
bool dvmStdioConverterStartup()
{
*/
bool dvmStdioConverterStartup()
{
- StdPipes* pipeStorage;
-
gDvm.haltStdioConverter = false;
dvmInitMutex(&gDvm.stdioConverterLock);
pthread_cond_init(&gDvm.stdioConverterCond, NULL);
gDvm.haltStdioConverter = false;
dvmInitMutex(&gDvm.stdioConverterLock);
pthread_cond_init(&gDvm.stdioConverterCond, NULL);
- pipeStorage = (StdPipes*) malloc(sizeof(StdPipes));
- if (pipeStorage == NULL)
- return false;
-
- if (pipe(pipeStorage->stdoutPipe) != 0) {
- LOGW("pipe failed: %s\n", strerror(errno));
+ if (pipe(gDvm.stdoutPipe) != 0) {
+ ALOGW("pipe failed: %s", strerror(errno));
return false;
}
return false;
}
- if (pipe(
pipeStorage->
stderrPipe) != 0) {
-
LOGW("pipe failed: %s\n
", strerror(errno));
+ if (pipe(
gDvm.
stderrPipe) != 0) {
+
ALOGW("pipe failed: %s
", strerror(errno));
return false;
}
return false;
}
- if (dup2(
pipeStorage->
stdoutPipe[1], kFilenoStdout) != kFilenoStdout) {
-
LOGW("dup2(1) failed: %s\n
", strerror(errno));
+ if (dup2(
gDvm.
stdoutPipe[1], kFilenoStdout) != kFilenoStdout) {
+
ALOGW("dup2(1) failed: %s
", strerror(errno));
return false;
}
return false;
}
- close(
pipeStorage->
stdoutPipe[1]);
-
pipeStorage->
stdoutPipe[1] = -1;
+ close(
gDvm.
stdoutPipe[1]);
+
gDvm.
stdoutPipe[1] = -1;
#ifdef HAVE_ANDROID_OS
/* don't redirect stderr on sim -- logs get written there! */
/* (don't need this on the sim anyway) */
#ifdef HAVE_ANDROID_OS
/* don't redirect stderr on sim -- logs get written there! */
/* (don't need this on the sim anyway) */
- if (dup2(
pipeStorage->
stderrPipe[1], kFilenoStderr) != kFilenoStderr) {
-
LOGW("dup2(2) failed: %d %s\n
", errno, strerror(errno));
+ if (dup2(
gDvm.
stderrPipe[1], kFilenoStderr) != kFilenoStderr) {
+
ALOGW("dup2(2) failed: %d %s
", errno, strerror(errno));
return false;
}
return false;
}
- close(
pipeStorage->
stderrPipe[1]);
-
pipeStorage->
stderrPipe[1] = -1;
+ close(
gDvm.
stderrPipe[1]);
+
gDvm.
stderrPipe[1] = -1;
#endif
#endif
@@
-101,12
+87,11
@@
bool dvmStdioConverterStartup()
dvmLockMutex(&gDvm.stdioConverterLock);
if (!dvmCreateInternalThread(&gDvm.stdioConverterHandle,
dvmLockMutex(&gDvm.stdioConverterLock);
if (!dvmCreateInternalThread(&gDvm.stdioConverterHandle,
- "Stdio Converter", stdioConverterThreadStart, pipeStorage))
- {
- free(pipeStorage);
+ "Stdio Converter",
+ stdioConverterThreadStart,
+ NULL)) {
return false;
}
return false;
}
- /* new thread owns pipeStorage */
while (!gDvm.stdioConverterReady) {
dvmWaitCond(&gDvm.stdioConverterCond, &gDvm.stdioConverterLock);
while (!gDvm.stdioConverterReady) {
dvmWaitCond(&gDvm.stdioConverterCond, &gDvm.stdioConverterLock);
@@
-132,7
+117,7
@@
void dvmStdioConverterShutdown()
printf("Shutting down\n");
fflush(stdout);
printf("Shutting down\n");
fflush(stdout);
-
LOGD("Joining stdio converter...\n
");
+
ALOGD("Joining stdio converter...
");
pthread_join(gDvm.stdioConverterHandle, NULL);
}
pthread_join(gDvm.stdioConverterHandle, NULL);
}
@@
-143,9
+128,6
@@
void dvmStdioConverterShutdown()
*/
static void* stdioConverterThreadStart(void* arg)
{
*/
static void* stdioConverterThreadStart(void* arg)
{
- StdPipes* pipeStorage = (StdPipes*) arg;
- BufferedData* stdoutData;
- BufferedData* stderrData;
int cc;
/* tell the main thread that we're ready */
int cc;
/* tell the main thread that we're ready */
@@
-161,8
+143,8
@@
static void* stdioConverterThreadStart(void* arg)
/*
* Allocate read buffers.
*/
/*
* Allocate read buffers.
*/
-
stdoutData = (BufferedData*) malloc(sizeof(*stdoutData))
;
-
stderrData = (BufferedData*) malloc(sizeof(*stderrData))
;
+
BufferedData* stdoutData = new BufferedData
;
+
BufferedData* stderrData = new BufferedData
;
stdoutData->count = stderrData->count = 0;
/*
stdoutData->count = stderrData->count = 0;
/*
@@
-173,45
+155,44
@@
static void* stdioConverterThreadStart(void* arg)
int maxFd, fdCount;
FD_ZERO(&readfds);
int maxFd, fdCount;
FD_ZERO(&readfds);
- FD_SET(
pipeStorage->
stdoutPipe[0], &readfds);
- FD_SET(
pipeStorage->
stderrPipe[0], &readfds);
- maxFd = MAX(
pipeStorage->stdoutPipe[0], pipeStorage->
stderrPipe[0]);
+ FD_SET(
gDvm.
stdoutPipe[0], &readfds);
+ FD_SET(
gDvm.
stderrPipe[0], &readfds);
+ maxFd = MAX(
gDvm.stdoutPipe[0], gDvm.
stderrPipe[0]);
fdCount = select(maxFd+1, &readfds, NULL, NULL, NULL);
if (fdCount < 0) {
if (errno != EINTR) {
fdCount = select(maxFd+1, &readfds, NULL, NULL, NULL);
if (fdCount < 0) {
if (errno != EINTR) {
-
LOGE("select on stdout/stderr failed\n
");
+
ALOGE("select on stdout/stderr failed
");
break;
}
break;
}
-
LOGD("Got EINTR, ignoring\n
");
+
ALOGD("Got EINTR, ignoring
");
} else if (fdCount == 0) {
} else if (fdCount == 0) {
-
LOGD("WEIRD: select returned zero\n
");
+
ALOGD("WEIRD: select returned zero
");
} else {
bool err = false;
} else {
bool err = false;
- if (FD_ISSET(
pipeStorage->
stdoutPipe[0], &readfds)) {
- err |= !readAndLog(
pipeStorage->
stdoutPipe[0], stdoutData,
+ if (FD_ISSET(
gDvm.
stdoutPipe[0], &readfds)) {
+ err |= !readAndLog(
gDvm.
stdoutPipe[0], stdoutData,
"stdout");
}
"stdout");
}
- if (FD_ISSET(
pipeStorage->
stderrPipe[0], &readfds)) {
- err |= !readAndLog(
pipeStorage->
stderrPipe[0], stderrData,
+ if (FD_ISSET(
gDvm.
stderrPipe[0], &readfds)) {
+ err |= !readAndLog(
gDvm.
stderrPipe[0], stderrData,
"stderr");
}
/* probably EOF; give up */
if (err) {
"stderr");
}
/* probably EOF; give up */
if (err) {
-
LOGW("stdio converter got read error; shutting it down\
n");
+
ALOGW("stdio converter got read error; shutting it dow
n");
break;
}
}
}
break;
}
}
}
- close(
pipeStorage->
stdoutPipe[0]);
- close(
pipeStorage->
stderrPipe[0]);
+ close(
gDvm.
stdoutPipe[0]);
+ close(
gDvm.
stderrPipe[0]);
- free(pipeStorage);
- free(stdoutData);
- free(stderrData);
+ delete stdoutData;
+ delete stderrData;
/* change back for shutdown sequence */
dvmChangeStatus(NULL, THREAD_RUNNING);
/* change back for shutdown sequence */
dvmChangeStatus(NULL, THREAD_RUNNING);
@@
-232,11
+213,11
@@
static bool readAndLog(int fd, BufferedData* data, const char* tag)
want = kMaxLine - data->count;
actual = read(fd, data->buf + data->count, want);
if (actual <= 0) {
want = kMaxLine - data->count;
actual = read(fd, data->buf + data->count, want);
if (actual <= 0) {
-
LOGW("read %s: (%d,%d) failed (%d): %s\n
",
+
ALOGW("read %s: (%d,%d) failed (%d): %s
",
tag, fd, want, (int)actual, strerror(errno));
return false;
} else {
tag, fd, want, (int)actual, strerror(errno));
return false;
} else {
- //
LOGI("read %s: %d at %d\n
", tag, actual, data->count);
+ //
ALOGI("read %s: %d at %d
", tag, actual, data->count);
}
data->count += actual;
}
data->count += actual;
@@
-250,8
+231,8
@@
static bool readAndLog(int fd, BufferedData* data, const char* tag)
for (i = data->count; i > 0; i--, cp++) {
if (*cp == '\n' || (*cp == '\r' && i != 0 && *(cp+1) != '\n')) {
*cp = '\0';
for (i = data->count; i > 0; i--, cp++) {
if (*cp == '\n' || (*cp == '\r' && i != 0 && *(cp+1) != '\n')) {
*cp = '\0';
- //
LOGW("GOT %d at %d '%s'\n
", cp - start, start - data->buf, start);
- LOG(LOG_INFO, tag, "%s", start);
+ //
ALOGW("GOT %d at %d '%s'
", cp - start, start - data->buf, start);
+
A
LOG(LOG_INFO, tag, "%s", start);
start = cp+1;
}
}
start = cp+1;
}
}
@@
-261,7
+242,7
@@
static bool readAndLog(int fd, BufferedData* data, const char* tag)
*/
if (start == data->buf && data->count == kMaxLine) {
data->buf[kMaxLine] = '\0';
*/
if (start == data->buf && data->count == kMaxLine) {
data->buf[kMaxLine] = '\0';
- LOG(LOG_INFO, tag, "%s!", start);
+
A
LOG(LOG_INFO, tag, "%s!", start);
start = cp + kMaxLine;
}
start = cp + kMaxLine;
}