diff options
author | Alain Magloire | 2004-11-18 17:07:29 +0000 |
---|---|---|
committer | Alain Magloire | 2004-11-18 17:07:29 +0000 |
commit | 3051c780f3ac531231958293ac86d9832ba3d81a (patch) | |
tree | efc500fa24557dc6c2638efb2d6be4111aa12aec /core/org.eclipse.cdt.core.aix | |
parent | 74f0cc0f87b392fd6f9adc0c3b57b1cab9574d07 (diff) | |
download | org.eclipse.cdt-3051c780f3ac531231958293ac86d9832ba3d81a.tar.gz org.eclipse.cdt-3051c780f3ac531231958293ac86d9832ba3d81a.tar.xz org.eclipse.cdt-3051c780f3ac531231958293ac86d9832ba3d81a.zip |
Updated to reflect the changes in Spawner.java and PTY.java
Diffstat (limited to 'core/org.eclipse.cdt.core.aix')
-rw-r--r-- | core/org.eclipse.cdt.core.aix/library/Makefile | 2 | ||||
-rw-r--r-- | core/org.eclipse.cdt.core.aix/library/PTY.h | 7 | ||||
-rw-r--r-- | core/org.eclipse.cdt.core.aix/library/Spawner.h | 98 | ||||
-rw-r--r-- | core/org.eclipse.cdt.core.aix/library/exec_pty.c | 152 | ||||
-rw-r--r-- | core/org.eclipse.cdt.core.aix/library/openpty.c | 22 | ||||
-rw-r--r-- | core/org.eclipse.cdt.core.aix/library/openpty.h | 1 | ||||
-rw-r--r-- | core/org.eclipse.cdt.core.aix/library/pty.c | 5 | ||||
-rw-r--r-- | core/org.eclipse.cdt.core.aix/library/spawner.c | 57 |
8 files changed, 294 insertions, 50 deletions
diff --git a/core/org.eclipse.cdt.core.aix/library/Makefile b/core/org.eclipse.cdt.core.aix/library/Makefile index cd384722c65..a1e7ea038ab 100644 --- a/core/org.eclipse.cdt.core.aix/library/Makefile +++ b/core/org.eclipse.cdt.core.aix/library/Makefile @@ -9,7 +9,7 @@ CFLAGS = -I. -I$(JDK_INCLUDES) LIB_NAME_SPAWNER = libspawner.so LIB_NAME_FULL_SPAWNER = ../os/aix/ppc/libspawner.so -OBJS_SPAWNER=spawner.o io.o exec_unix.o pfind.o +OBJS_SPAWNER=spawner.o io.o exec_unix.o exec_pty.o openpty.o pfind.o LIB_NAME_PTY = libpty.so LIB_NAME_FULL_PTY = ../os/aix/ppc/libpty.so diff --git a/core/org.eclipse.cdt.core.aix/library/PTY.h b/core/org.eclipse.cdt.core.aix/library/PTY.h index fabf58152d0..46a8dd9b622 100644 --- a/core/org.eclipse.cdt.core.aix/library/PTY.h +++ b/core/org.eclipse.cdt.core.aix/library/PTY.h @@ -7,12 +7,13 @@ #ifdef __cplusplus extern "C" { #endif +/* Inaccessible static: hasPTY */ /* * Class: org_eclipse_cdt_utils_pty_PTY - * Method: forkpty - * Signature: ()I + * Method: openMaster + * Signature: ()Ljava/lang/String; */ -JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_pty_PTY_forkpty +JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_pty_PTY_openMaster (JNIEnv *, jobject); #ifdef __cplusplus diff --git a/core/org.eclipse.cdt.core.aix/library/Spawner.h b/core/org.eclipse.cdt.core.aix/library/Spawner.h index 01ffb3cc1b2..272366bad75 100644 --- a/core/org.eclipse.cdt.core.aix/library/Spawner.h +++ b/core/org.eclipse.cdt.core.aix/library/Spawner.h @@ -1,45 +1,53 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */
-#include <jni.h>
-/* Header for class com_qnx_tools_utils_spawner_Spawner */
-
-#ifndef _Included_com_qnx_tools_utils_spawner_Spawner
-#define _Included_com_qnx_tools_utils_spawner_Spawner
-#ifdef __cplusplus
-extern "C" {
-#endif
-/*
- * Class: org_eclipse_cdt_utils_spawner_Spawner
- * Method: exec0
- * Signature: ([Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;[I)I
- */
-JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec0
- (JNIEnv *, jobject, jobjectArray, jobjectArray, jstring, jintArray);
-
-/*
- * Class: org_eclipse_cdt_utils_spawner_Spawner
- * Method: exec0
- * Signature: ([Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;[I)I
- */
-JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec1
- (JNIEnv *, jobject, jobjectArray, jobjectArray, jstring);
-
-/*
- * Class: org_eclipse_cdt_utils_spawner_Spawner
- * Method: raise
- * Signature: (II)I
- */
-JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_raise
- (JNIEnv *, jobject, jint, jint);
-
-/*
- * Class: org_eclipse_cdt_utils_spawner_Spawner
- * Method: waitFor
- * Signature: (I)I
- */
-JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_waitFor
- (JNIEnv *, jobject, jint);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
+/* DO NOT EDIT THIS FILE - it is machine generated */ +#include <jni.h> +/* Header for class org_eclipse_cdt_utils_spawner_Spawner */ + +#ifndef _Included_org_eclipse_cdt_utils_spawner_Spawner +#define _Included_org_eclipse_cdt_utils_spawner_Spawner +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_eclipse_cdt_utils_spawner_Spawner + * Method: exec0 + * Signature: ([Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;[I)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec0 + (JNIEnv *, jobject, jobjectArray, jobjectArray, jstring, jintArray); + +/* + * Class: org_eclipse_cdt_utils_spawner_Spawner + * Method: exec1 + * Signature: ([Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec1 + (JNIEnv *, jobject, jobjectArray, jobjectArray, jstring); + +/* + * Class: org_eclipse_cdt_utils_spawner_Spawner + * Method: exec2 + * Signature: ([Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;[ILjava/lang/String;I)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec2 + (JNIEnv *, jobject, jobjectArray, jobjectArray, jstring, jintArray, jstring, jint); + +/* + * Class: org_eclipse_cdt_utils_spawner_Spawner + * Method: raise + * Signature: (II)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_raise + (JNIEnv *, jobject, jint, jint); + +/* + * Class: org_eclipse_cdt_utils_spawner_Spawner + * Method: waitFor + * Signature: (I)I + */ +JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_waitFor + (JNIEnv *, jobject, jint); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/core/org.eclipse.cdt.core.aix/library/exec_pty.c b/core/org.eclipse.cdt.core.aix/library/exec_pty.c new file mode 100644 index 00000000000..d012cfb051c --- /dev/null +++ b/core/org.eclipse.cdt.core.aix/library/exec_pty.c @@ -0,0 +1,152 @@ +#include "exec0.h"
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <libgen.h>
+#include <stdlib.h>
+#include <termios.h>
+
+/* from pfind.c */
+extern char *pfind(const char *name);
+
+pid_t
+exec_pty(const char *path, char *const argv[], char *const envp[],
+ const char *dirpath, int channels[3], const char *pts_name, int fdm)
+{
+ int pipe2[2];
+ pid_t childpid;
+ char *full_path;
+
+ /*
+ * We use pfind() to check that the program exists and is an executable.
+ * If not pass the error up. Also execve() wants a full path.
+ */
+ full_path = pfind(path);
+ if (full_path == NULL) {
+ fprintf(stderr, "Unable to find full path for \"%s\"\n", (path) ? path : "");
+ return -1;
+ }
+
+ /*
+ * Make sure we can create our pipes before forking.
+ */
+ if (channels != NULL) {
+ if (pipe(pipe2) < 0) {
+ fprintf(stderr, "%s(%d): returning due to error: %s\n", __FUNCTION__, __LINE__, strerror(errno));
+ free(full_path);
+ return -1;
+ }
+ }
+
+ childpid = fork();
+
+ if (childpid < 0) {
+ fprintf(stderr, "%s(%d): returning due to error: %s\n", __FUNCTION__, __LINE__, strerror(errno));
+ free(full_path);
+ return -1;
+ } else if (childpid == 0) { /* child */
+
+ chdir(dirpath);
+
+ if (channels != NULL) {
+ int fds;
+
+ fds = ptys_open(fdm, pts_name);
+ if (fds < 0) {
+ fprintf(stderr, "%s(%d): returning due to error: %s\n", __FUNCTION__, __LINE__, strerror(errno));
+ return -1;
+ }
+
+ /* Close the read end of pipe2 */
+ if (close(pipe2[0]) == -1)
+ perror("close(pipe2[0]))");
+
+ /* close the master, no need in the child */
+ close(fdm);
+
+ set_noecho(fds);
+ /* redirections */
+ dup2(fds, STDIN_FILENO); /* dup stdin */
+ dup2(fds, STDOUT_FILENO); /* dup stdout */
+ dup2(pipe2[1], STDERR_FILENO); /* dup stderr */
+ close(fds); /* done with fds. */
+ }
+
+ /* Close all the fd's in the child */
+ {
+ int fdlimit = sysconf(_SC_OPEN_MAX);
+ int fd = 3;
+
+ while (fd < fdlimit)
+ close(fd++);
+ }
+
+ if (envp[0] == NULL) {
+ execv(full_path, argv);
+ } else {
+ execve(full_path, argv, envp);
+ }
+
+ _exit(127);
+
+ } else if (childpid != 0) { /* parent */
+
+ set_noecho(fdm);
+ if (channels != NULL) {
+ /* close the write end of pipe1 */
+ if (close(pipe2[1]) == -1)
+ perror("close(pipe2[1])");
+
+ channels[0] = fdm; /* Input Stream. */
+ channels[1] = fdm; /* Output Stream. */
+ channels[2] = pipe2[0]; /* stderr Stream. */
+ //channels[2] = fdm; /* Input Stream. */
+ }
+
+ free(full_path);
+ return childpid;
+ }
+
+ free(full_path);
+ return -1; /*NOT REACHED */
+}
+#ifdef __STAND_ALONE__
+int main(int argc, char **argv, char **envp) {
+ const char *path = "./bufferring_test";
+ int channels[3] = { -1, -1, -1};
+ int status;
+ FILE *app_stdin;
+ FILE *app_stdout;
+ FILE *app_stderr;
+ char pts_name[32];
+ int fdm;
+ char buffer[32];
+
+ fdm = ptym_open(pts_name);
+ status = exec_pty(path, argv, envp, ".", channels, pts_name, fdm);
+ if (status >= 0) {
+ app_stdin = fdopen(channels[0], "w");
+ app_stdout = fdopen(channels[1], "r");
+ app_stderr = fdopen(channels[2], "r");
+ if (app_stdout == NULL || app_stderr == NULL || app_stdin == NULL) {
+ fprintf(stderr, "PROBLEMS\n");
+ } else {
+ fputs("foo\n", app_stdin);
+ fputs("bar\n", app_stdin);
+ while(fgets(buffer, sizeof buffer, app_stdout) != NULL) {
+ fprintf(stdout, "STDOUT: %s\n", buffer);
+ }
+ while(fgets(buffer, sizeof buffer, app_stderr) != NULL) {
+ fprintf(stdout, "STDERR: %s\n", buffer);
+ }
+ }
+ }
+ fputs("bye\n", stdout);
+ close(channels[0]);
+ close(channels[1]);
+ close(channels[2]);
+ return 0;
+}
+#endif
diff --git a/core/org.eclipse.cdt.core.aix/library/openpty.c b/core/org.eclipse.cdt.core.aix/library/openpty.c index 28f5363cf1d..21c1ccfef09 100644 --- a/core/org.eclipse.cdt.core.aix/library/openpty.c +++ b/core/org.eclipse.cdt.core.aix/library/openpty.c @@ -24,6 +24,7 @@ int ptym_open (char *pts_name); int ptys_open (int fdm, char * pts_name); +void set_noecho(int fd); int openpty(int *amaster, int *aslave, char *name, struct termios *termp, struct winsize *winp) @@ -38,6 +39,7 @@ openpty(int *amaster, int *aslave, char *name, struct termios *termp, struct win close(*amaster); return -1; } + if (name) strcpy(name, line); #ifndef TCSAFLUSH @@ -52,6 +54,24 @@ openpty(int *amaster, int *aslave, char *name, struct termios *termp, struct win return 0; } +void +set_noecho(int fd) +{ + struct termios stermios; + if (tcgetattr(fd, &stermios) < 0) { + return ; + } + + /* turn off echo */ + stermios.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); + /* Turn off the NL to CR/NL mapping ou output. */ + /*stermios.c_oflag &= ~(ONLCR);*/ + + stermios.c_iflag |= (IGNCR); + + tcsetattr(fd, TCSANOW, &stermios); +} + int ptym_open(char * pts_name) { @@ -89,6 +109,7 @@ ptys_open(int fdm, char * pts_name) close(fdm); return -5; } +/* if (ioctl(fds, I_PUSH, "ptem") < 0) { printf("pterm:%s\n", strerror(errno)); close(fdm); @@ -101,5 +122,6 @@ ptys_open(int fdm, char * pts_name) close(fds); return -7; } +*/ return fds; } diff --git a/core/org.eclipse.cdt.core.aix/library/openpty.h b/core/org.eclipse.cdt.core.aix/library/openpty.h index fd7b7be1b2f..36cd52fd294 100644 --- a/core/org.eclipse.cdt.core.aix/library/openpty.h +++ b/core/org.eclipse.cdt.core.aix/library/openpty.h @@ -7,4 +7,5 @@ #define _OPENPTY_H int ptym_open (char *pts_name); int ptys_open (int fdm, char * pts_name); +void set_noecho(int fd); #endif diff --git a/core/org.eclipse.cdt.core.aix/library/pty.c b/core/org.eclipse.cdt.core.aix/library/pty.c index 4b9e682c3ee..245578632f3 100644 --- a/core/org.eclipse.cdt.core.aix/library/pty.c +++ b/core/org.eclipse.cdt.core.aix/library/pty.c @@ -7,7 +7,7 @@ * Signature: ()I */ JNIEXPORT jstring JNICALL -Java_org_eclipse_cdt_utils_pty_PTY_forkpty (JNIEnv *env, jobject jobj) { +Java_org_eclipse_cdt_utils_pty_PTY_openMaster (JNIEnv *env, jobject jobj) { jfieldID fid; /* Store the field ID */ jstring jstr = NULL; int master = -1; @@ -18,6 +18,9 @@ Java_org_eclipse_cdt_utils_pty_PTY_forkpty (JNIEnv *env, jobject jobj) { master = ptym_open(line); if (master >= 0) { + // turn off echo + set_noecho(master); + /* Get a reference to the obj's class */ cls = (*env)->GetObjectClass(env, jobj); diff --git a/core/org.eclipse.cdt.core.aix/library/spawner.c b/core/org.eclipse.cdt.core.aix/library/spawner.c index 58bf85a74ed..fcb111a81f0 100644 --- a/core/org.eclipse.cdt.core.aix/library/spawner.c +++ b/core/org.eclipse.cdt.core.aix/library/spawner.c @@ -71,6 +71,63 @@ static void free_c_array(char **c_array) }
+/*
+ * Class: org_eclipse_cdt_utils_spawner_Spawner
+ * Method: exec2
+ * Signature: ([Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;[ILorg/eclipse/cdt/utils/pty/PTY;)I
+ */
+JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec2
+ (JNIEnv *env, jobject jobj, jobjectArray jcmd, jobjectArray jenv, jstring jdir, jintArray jchannels,
+ jstring jslaveName, jint masterFD)
+{
+ jint *channels = (*env)->GetIntArrayElements(env, jchannels, 0);
+ const char *dirpath = (*env)->GetStringUTFChars(env, jdir, NULL);
+ const char *pts_name = (*env)->GetStringUTFChars(env, jslaveName, NULL);
+ char **cmd;
+ char **envp;
+ int fd[3];
+ pid_t pid = -1;
+
+ if (channels == NULL)
+ goto bail_out;
+
+ cmd = alloc_c_array(env, jcmd);
+ if (cmd == NULL)
+ goto bail_out;
+
+ envp = alloc_c_array(env, jenv);
+ if (envp == NULL)
+ goto bail_out;
+
+#if DEBUGIT
+ fprintf(stderr, "command:");
+ print_array(cmd);
+ fprintf(stderr, "Envp:");
+ print_array(envp);
+ fprintf(stderr, "dirpath: %s\n", dirpath);
+ fprintf(stderr, "pts_name: %s\n", pts_name);
+#endif
+
+ pid = exec_pty(cmd[0], cmd, envp, dirpath, fd, pts_name, masterFD);
+ if (pid < 0)
+ goto bail_out;
+
+ channels[0] = fd[0];
+ channels[1] = fd[1];
+ channels[2] = fd[2];
+
+ bail_out:
+ (*env)->ReleaseIntArrayElements(env, jchannels, channels, 0);
+ (*env)->ReleaseStringUTFChars(env, jdir, dirpath);
+ (*env)->ReleaseStringUTFChars(env, jslaveName, pts_name);
+ if (cmd)
+ free_c_array(cmd);
+ if (envp)
+ free_c_array(envp);
+ return pid;
+}
+
+
JNIEXPORT jint JNICALL
Java_org_eclipse_cdt_utils_spawner_Spawner_exec1(JNIEnv * env, jobject jobj,
jobjectArray jcmd,
|