-
-
Notifications
You must be signed in to change notification settings - Fork 208
Expand file tree
/
Copy pathtermExec.cpp
More file actions
89 lines (72 loc) · 2.79 KB
/
Copy pathtermExec.cpp
File metadata and controls
89 lines (72 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* Copyright (C) 2007, 2008 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 "common.h"
#define LOG_TAG "Exec"
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>
#include <signal.h>
#include "termExec.h"
static void android_os_Exec_setPtyWindowSize(JNIEnv *env, jobject clazz,
jint fd, jint row, jint col, jint xpixel,
jint ypixel) {
struct winsize sz;
sz.ws_row = row;
sz.ws_col = col;
sz.ws_xpixel = xpixel;
sz.ws_ypixel = ypixel;
// TODO: handle the situation, when the file descriptor is incompatible with TIOCSWINSZ (e.g. not from /dev/ptmx)
if (ioctl(fd, TIOCSWINSZ, &sz) == -1)
env->ThrowNew(env->FindClass("java/io/IOException"), "Failed to issue TIOCSWINSZ ioctl");
}
// tcgetattr /tcsetattr are not part of Bionic at API level 4. Here's a compatible version.
static __inline__ int my_tcgetattr(int fd, struct termios *s) {
return ioctl(fd, TCGETS, s);
}
static __inline__ int my_tcsetattr(int fd, const struct termios *s) {
return ioctl(fd, TCSETS, (void *) s);
}
static void android_os_Exec_setPtyUTF8Mode(JNIEnv *env, jobject clazz, jint fd, jboolean utf8Mode) {
struct termios tios;
if (my_tcgetattr(fd, &tios) != 0)
env->ThrowNew(env->FindClass("java/io/IOException"), "Failed to get terminal attributes");
if (utf8Mode) {
tios.c_iflag |= IUTF8;
} else {
tios.c_iflag &= ~IUTF8;
}
if (my_tcsetattr(fd, &tios) != 0)
env->ThrowNew(env->FindClass("java/io/IOException"), "Failed to set terminal UTF-8 mode");
}
static const char *classPathName = "org/qpython/qpy/console/Exec";
static JNINativeMethod method_table[] = {
{"setPtyWindowSizeInternal", "(IIIII)V",
(void *) android_os_Exec_setPtyWindowSize},
{"setPtyUTF8ModeInternal", "(IZ)V",
(void *) android_os_Exec_setPtyUTF8Mode}
};
int init_Exec(JNIEnv *env) {
if (!registerNativeMethods(env, classPathName, method_table,
sizeof(method_table) / sizeof(method_table[0]))) {
return JNI_FALSE;
}
return JNI_TRUE;
}