summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-12-03 15:15:33 -0800
committerElliott Hughes <enh@google.com>2014-12-04 16:27:02 -0800
commitffbad51da16422bab578c6616a714ad05ae20d73 (patch)
tree1ad7dd16de3dea7a131efbc20d445d3cd9300a3c
parent1a161f759167dc8824ea40d3f661a69799b59e3b (diff)
downloadandroid_packages_apps_Terminal-ffbad51da16422bab578c6616a714ad05ae20d73.tar.gz
android_packages_apps_Terminal-ffbad51da16422bab578c6616a714ad05ae20d73.tar.bz2
android_packages_apps_Terminal-ffbad51da16422bab578c6616a714ad05ae20d73.zip
Update and fix Terminal.
As of today, bionic has <pty.h>, so there's no need to have another here. Also fix bugs introduced in attempts to make this code 64-bit clean. Change-Id: I40746920764e84a829a3d1df5a900a419589b84a
-rw-r--r--jni/Android.mk4
-rw-r--r--jni/com_android_terminal_Terminal.cpp24
-rw-r--r--jni/forkpty.cpp83
-rw-r--r--jni/forkpty.h21
4 files changed, 15 insertions, 117 deletions
diff --git a/jni/Android.mk b/jni/Android.mk
index 1be6426..fe5a474 100644
--- a/jni/Android.mk
+++ b/jni/Android.mk
@@ -5,7 +5,6 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
jni_init.cpp \
com_android_terminal_Terminal.cpp \
- forkpty.cpp
LOCAL_C_INCLUDES += \
external/libvterm/include \
@@ -22,6 +21,9 @@ LOCAL_SHARED_LIBRARIES := \
LOCAL_STATIC_LIBRARIES := \
libvterm
+LOCAL_CFLAGS := \
+ -Wno-unused-parameter \
+
LOCAL_MODULE := libjni_terminal
LOCAL_MODULE_TAGS := optional
diff --git a/jni/com_android_terminal_Terminal.cpp b/jni/com_android_terminal_Terminal.cpp
index 9dc9139..03f27b1 100644
--- a/jni/com_android_terminal_Terminal.cpp
+++ b/jni/com_android_terminal_Terminal.cpp
@@ -20,13 +20,13 @@
#include <utils/Mutex.h>
#include "android_runtime/AndroidRuntime.h"
-#include "forkpty.h"
#include "jni.h"
#include "JNIHelp.h"
#include "ScopedLocalRef.h"
#include "ScopedPrimitiveArray.h"
#include <fcntl.h>
+#include <pty.h>
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
@@ -201,8 +201,8 @@ static int term_settermprop(VTermProp prop, VTermValue *val, void *user) {
JNIEnv* env = AndroidRuntime::getJNIEnv();
switch (vterm_get_prop_type(prop)) {
case VTERM_VALUETYPE_BOOL:
- return env->CallIntMethod(term->getCallbacks(), setTermPropBooleanMethod,
- static_cast<jboolean>(val->boolean));
+ return env->CallIntMethod(term->getCallbacks(), setTermPropBooleanMethod, prop,
+ val->boolean ? JNI_TRUE : JNI_FALSE);
case VTERM_VALUETYPE_INT:
return env->CallIntMethod(term->getCallbacks(), setTermPropIntMethod, prop, val->number);
case VTERM_VALUETYPE_STRING:
@@ -300,13 +300,12 @@ Terminal::~Terminal() {
}
status_t Terminal::run() {
- struct termios termios = {
- .c_iflag = ICRNL|IXON|IUTF8,
- .c_oflag = OPOST|ONLCR|NL0|CR0|TAB0|BS0|VT0|FF0,
- .c_cflag = CS8|CREAD,
- .c_lflag = ISIG|ICANON|IEXTEN|ECHO|ECHOE|ECHOK,
- /* c_cc later */
- };
+ struct termios termios;
+ memset(&termios, 0, sizeof(termios));
+ termios.c_iflag = ICRNL|IXON|IUTF8;
+ termios.c_oflag = OPOST|ONLCR|NL0|CR0|TAB0|BS0|VT0|FF0;
+ termios.c_cflag = CS8|CREAD;
+ termios.c_lflag = ISIG|ICANON|IEXTEN|ECHO|ECHOE|ECHOK;
cfsetispeed(&termios, B38400);
cfsetospeed(&termios, B38400);
@@ -346,7 +345,8 @@ status_t Terminal::run() {
ALOGE("failed to open stderr - %s", strerror(errno));
}
- char *shell = "/system/bin/sh"; //getenv("SHELL");
+ // We know execvp(2) won't actually try to modify this.
+ char *shell = const_cast<char*>("/system/bin/sh");
#if USE_TEST_SHELL
char *args[4] = {shell, "-c", "x=1; c=0; while true; do echo -e \"stop \e[00;3${c}mechoing\e[00m yourself! ($x)\"; x=$(( $x + 1 )); c=$((($c+1)%7)); if [ $x -gt 110 ]; then sleep 0.5; fi; done", NULL};
#else
@@ -681,7 +681,7 @@ static jboolean com_android_terminal_Terminal_nativeDispatchKey(JNIEnv *env, jcl
}
static JNINativeMethod gMethods[] = {
- { "nativeInit", "(Lcom/android/terminal/TerminalCallbacks;II)L", (void*)com_android_terminal_Terminal_nativeInit },
+ { "nativeInit", "(Lcom/android/terminal/TerminalCallbacks;II)J", (void*)com_android_terminal_Terminal_nativeInit },
{ "nativeDestroy", "(J)I", (void*)com_android_terminal_Terminal_nativeDestroy },
{ "nativeRun", "(J)I", (void*)com_android_terminal_Terminal_nativeRun },
{ "nativeResize", "(JIII)I", (void*)com_android_terminal_Terminal_nativeResize },
diff --git a/jni/forkpty.cpp b/jni/forkpty.cpp
deleted file mode 100644
index 7feb307..0000000
--- a/jni/forkpty.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2013 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.
- */
-
-#define LOG_TAG "forkpty"
-
-#include <utils/Log.h>
-
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/ioctl.h>
-#include <termios.h>
-#include <unistd.h>
-
-#include "forkpty.h"
-
-pid_t forkpty(int *master, int *slave, const struct termios *termp,
- const struct winsize *winp) {
- int ptm = open("/dev/ptmx", O_RDWR);
- if (ptm < 0) {
- ALOGE("cannot open /dev/ptmx - %s", strerror(errno));
- return -1;
- }
- fcntl(ptm, F_SETFD, FD_CLOEXEC);
-
- char *devname;
- if (grantpt(ptm) || unlockpt(ptm) || ((devname = (char *) ptsname(ptm)) == 0)) {
- ALOGE("error opening pty - %s", strerror(errno));
- return -1;
- }
-
- int pts = open(devname, O_RDWR);
- if (pts < 0) {
- ALOGE("unable to open slave pty - %s", strerror(errno));
- return -1;
- }
-
- if (termp) {
- tcsetattr(pts, TCSAFLUSH, termp);
- }
-
- if (winp) {
- ioctl(pts, TIOCSWINSZ, winp);
- }
-
- pid_t pid = fork();
-
- if (pid < 0) {
- ALOGE("fork failed - %s", strerror(errno));
- return -1;
- }
-
- if (pid == 0) {
- setsid();
- if (ioctl(pts, TIOCSCTTY, (char *)NULL) == -1) exit(-1);
- dup2(pts, STDIN_FILENO);
- dup2(pts, STDOUT_FILENO);
- dup2(pts, STDERR_FILENO);
- if (pts > 2) {
- close(pts);
- }
- } else {
- *master = ptm;
- if (slave) {
- *slave = pts;
- }
- }
- return pid;
-}
-
diff --git a/jni/forkpty.h b/jni/forkpty.h
deleted file mode 100644
index 6b4da38..0000000
--- a/jni/forkpty.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (C) 2013 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.
- */
-
-#include <termios.h>
-#include <unistd.h>
-
-pid_t forkpty(int *master, int *slave, const struct termios *termp,
- const struct winsize *winp);