1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 09:46:02 +02:00

fix binary properties

This commit is contained in:
Chris Recoskie 2010-11-17 14:46:44 +00:00
parent 7e01bb61eb
commit 8462736684
12 changed files with 846 additions and 846 deletions

View file

@ -1,32 +1,32 @@
/* DO NOT EDIT THIS FILE - it is machine generated */ /* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h> #include <jni.h>
/* Header for class com_qnx_tools_utils_spawner_SpawnerInputStream */ /* Header for class com_qnx_tools_utils_spawner_SpawnerInputStream */
#ifndef _Included_com_qnx_tools_utils_spawner_SpawnerInputStream #ifndef _Included_com_qnx_tools_utils_spawner_SpawnerInputStream
#define _Included_com_qnx_tools_utils_spawner_SpawnerInputStream #define _Included_com_qnx_tools_utils_spawner_SpawnerInputStream
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#undef com_qnx_tools_utils_spawner_SpawnerInputStream_SKIP_BUFFER_SIZE #undef com_qnx_tools_utils_spawner_SpawnerInputStream_SKIP_BUFFER_SIZE
#define com_qnx_tools_utils_spawner_SpawnerInputStream_SKIP_BUFFER_SIZE 2048L #define com_qnx_tools_utils_spawner_SpawnerInputStream_SKIP_BUFFER_SIZE 2048L
/* Inaccessible static: skipBuffer */ /* Inaccessible static: skipBuffer */
/* /*
* Class: org_elipse_cdt_utils_spawner_SpawnerInputStream * Class: org_elipse_cdt_utils_spawner_SpawnerInputStream
* Method: read0 * Method: read0
* Signature: (I[BI)I * Signature: (I[BI)I
*/ */
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_SpawnerInputStream_read0 JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_SpawnerInputStream_read0
(JNIEnv *, jobject, jint, jbyteArray, jint); (JNIEnv *, jobject, jint, jbyteArray, jint);
/* /*
* Class: org_eclipse_cdt_utils_spawner_SpawnerInputStream * Class: org_eclipse_cdt_utils_spawner_SpawnerInputStream
* Method: close0 * Method: close0
* Signature: (I)I * Signature: (I)I
*/ */
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_SpawnerInputStream_close0 JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_SpawnerInputStream_close0
(JNIEnv *, jobject, jint); (JNIEnv *, jobject, jint);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif #endif

View file

@ -1,29 +1,29 @@
/* DO NOT EDIT THIS FILE - it is machine generated */ /* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h> #include <jni.h>
/* Header for class com_qnx_tools_utils_spawner_SpawnerOutputStream */ /* Header for class com_qnx_tools_utils_spawner_SpawnerOutputStream */
#ifndef _Included_com_qnx_tools_utils_spawner_SpawnerOutputStream #ifndef _Included_com_qnx_tools_utils_spawner_SpawnerOutputStream
#define _Included_com_qnx_tools_utils_spawner_SpawnerOutputStream #define _Included_com_qnx_tools_utils_spawner_SpawnerOutputStream
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/* /*
* Class: org_eclipse_cdt_utils_spawner_SpawnerOutputStream * Class: org_eclipse_cdt_utils_spawner_SpawnerOutputStream
* Method: write0 * Method: write0
* Signature: (I[BI)I * Signature: (I[BI)I
*/ */
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_SpawnerOutputStream_write0 JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_SpawnerOutputStream_write0
(JNIEnv *, jobject, jint, jbyteArray, jint); (JNIEnv *, jobject, jint, jbyteArray, jint);
/* /*
* Class: org_eclipse_cdt_utils_spawner_SpawnerOutputStream * Class: org_eclipse_cdt_utils_spawner_SpawnerOutputStream
* Method: close0 * Method: close0
* Signature: (I)I * Signature: (I)I
*/ */
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_SpawnerOutputStream_close0 JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_SpawnerOutputStream_close0
(JNIEnv *, jobject, jint); (JNIEnv *, jobject, jint);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif #endif

View file

@ -1,22 +1,22 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2003, 2008 IBM Corporation and others. * Copyright (c) 2003, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
*******************************************************************************/ *******************************************************************************/
#include <unistd.h> #include <unistd.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/types.h> #include <sys/types.h>
#include <signal.h> #include <signal.h>
#include <errno.h> #include <errno.h>
extern pid_t exec0(const char *path, char *const argv[], extern pid_t exec0(const char *path, char *const argv[],
char *const envp[], const char *dirpath, char *const envp[], const char *dirpath,
int channels[3] ); int channels[3] );
extern int wait0(pid_t pid); extern int wait0(pid_t pid);

View file

@ -1,163 +1,163 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004 QNX Software Systems and others. * Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* QNX Software Systems - initial API and implementation * QNX Software Systems - initial API and implementation
*******************************************************************************/ *******************************************************************************/
#include "exec0.h" #include "exec0.h"
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <libgen.h> #include <libgen.h>
#include <stdlib.h> #include <stdlib.h>
#include <termios.h> #include <termios.h>
/* from pfind.c */ /* from pfind.c */
extern char *pfind(const char *name); extern char *pfind(const char *name);
pid_t pid_t
exec_pty(const char *path, char *const argv[], char *const envp[], exec_pty(const char *path, char *const argv[], char *const envp[],
const char *dirpath, int channels[3], const char *pts_name, int fdm) const char *dirpath, int channels[3], const char *pts_name, int fdm)
{ {
int pipe2[2]; int pipe2[2];
pid_t childpid; pid_t childpid;
char *full_path; char *full_path;
/* /*
* We use pfind() to check that the program exists and is an executable. * 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. * If not pass the error up. Also execve() wants a full path.
*/ */
full_path = pfind(path); full_path = pfind(path);
if (full_path == NULL) { if (full_path == NULL) {
fprintf(stderr, "Unable to find full path for \"%s\"\n", (path) ? path : ""); fprintf(stderr, "Unable to find full path for \"%s\"\n", (path) ? path : "");
return -1; return -1;
} }
/* /*
* Make sure we can create our pipes before forking. * Make sure we can create our pipes before forking.
*/ */
if (channels != NULL) { if (channels != NULL) {
if (pipe(pipe2) < 0) { if (pipe(pipe2) < 0) {
fprintf(stderr, "%s(%d): returning due to error: %s\n", __FUNCTION__, __LINE__, strerror(errno)); fprintf(stderr, "%s(%d): returning due to error: %s\n", __FUNCTION__, __LINE__, strerror(errno));
free(full_path); free(full_path);
return -1; return -1;
} }
} }
childpid = fork(); childpid = fork();
if (childpid < 0) { if (childpid < 0) {
fprintf(stderr, "%s(%d): returning due to error: %s\n", __FUNCTION__, __LINE__, strerror(errno)); fprintf(stderr, "%s(%d): returning due to error: %s\n", __FUNCTION__, __LINE__, strerror(errno));
free(full_path); free(full_path);
return -1; return -1;
} else if (childpid == 0) { /* child */ } else if (childpid == 0) { /* child */
chdir(dirpath); chdir(dirpath);
if (channels != NULL) { if (channels != NULL) {
int fds; int fds;
fds = ptys_open(fdm, pts_name); fds = ptys_open(fdm, pts_name);
if (fds < 0) { if (fds < 0) {
fprintf(stderr, "%s(%d): returning due to error: %s\n", __FUNCTION__, __LINE__, strerror(errno)); fprintf(stderr, "%s(%d): returning due to error: %s\n", __FUNCTION__, __LINE__, strerror(errno));
return -1; return -1;
} }
/* Close the read end of pipe2 */ /* Close the read end of pipe2 */
if (close(pipe2[0]) == -1) if (close(pipe2[0]) == -1)
perror("close(pipe2[0]))"); perror("close(pipe2[0]))");
/* close the master, no need in the child */ /* close the master, no need in the child */
close(fdm); close(fdm);
set_noecho(fds); set_noecho(fds);
/* redirections */ /* redirections */
dup2(fds, STDIN_FILENO); /* dup stdin */ dup2(fds, STDIN_FILENO); /* dup stdin */
dup2(fds, STDOUT_FILENO); /* dup stdout */ dup2(fds, STDOUT_FILENO); /* dup stdout */
dup2(pipe2[1], STDERR_FILENO); /* dup stderr */ dup2(pipe2[1], STDERR_FILENO); /* dup stderr */
close(fds); /* done with fds. */ close(fds); /* done with fds. */
} }
/* Close all the fd's in the child */ /* Close all the fd's in the child */
{ {
int fdlimit = sysconf(_SC_OPEN_MAX); int fdlimit = sysconf(_SC_OPEN_MAX);
int fd = 3; int fd = 3;
while (fd < fdlimit) while (fd < fdlimit)
close(fd++); close(fd++);
} }
if (envp[0] == NULL) { if (envp[0] == NULL) {
execv(full_path, argv); execv(full_path, argv);
} else { } else {
execve(full_path, argv, envp); execve(full_path, argv, envp);
} }
_exit(127); _exit(127);
} else if (childpid != 0) { /* parent */ } else if (childpid != 0) { /* parent */
set_noecho(fdm); set_noecho(fdm);
if (channels != NULL) { if (channels != NULL) {
/* close the write end of pipe1 */ /* close the write end of pipe1 */
if (close(pipe2[1]) == -1) if (close(pipe2[1]) == -1)
perror("close(pipe2[1])"); perror("close(pipe2[1])");
channels[0] = fdm; /* Input Stream. */ channels[0] = fdm; /* Input Stream. */
channels[1] = fdm; /* Output Stream. */ channels[1] = fdm; /* Output Stream. */
channels[2] = pipe2[0]; /* stderr Stream. */ channels[2] = pipe2[0]; /* stderr Stream. */
/*channels[2] = fdm; Input Stream. */ /*channels[2] = fdm; Input Stream. */
} }
free(full_path); free(full_path);
return childpid; return childpid;
} }
free(full_path); free(full_path);
return -1; /*NOT REACHED */ return -1; /*NOT REACHED */
} }
#ifdef __STAND_ALONE__ #ifdef __STAND_ALONE__
int main(int argc, char **argv, char **envp) { int main(int argc, char **argv, char **envp) {
const char *path = "./bufferring_test"; const char *path = "./bufferring_test";
int channels[3] = { -1, -1, -1}; int channels[3] = { -1, -1, -1};
int status; int status;
FILE *app_stdin; FILE *app_stdin;
FILE *app_stdout; FILE *app_stdout;
FILE *app_stderr; FILE *app_stderr;
char pts_name[32]; char pts_name[32];
int fdm; int fdm;
char buffer[32]; char buffer[32];
fdm = ptym_open(pts_name); fdm = ptym_open(pts_name);
status = exec_pty(path, argv, envp, ".", channels, pts_name, fdm); status = exec_pty(path, argv, envp, ".", channels, pts_name, fdm);
if (status >= 0) { if (status >= 0) {
app_stdin = fdopen(channels[0], "w"); app_stdin = fdopen(channels[0], "w");
app_stdout = fdopen(channels[1], "r"); app_stdout = fdopen(channels[1], "r");
app_stderr = fdopen(channels[2], "r"); app_stderr = fdopen(channels[2], "r");
if (app_stdout == NULL || app_stderr == NULL || app_stdin == NULL) { if (app_stdout == NULL || app_stderr == NULL || app_stdin == NULL) {
fprintf(stderr, "PROBLEMS\n"); fprintf(stderr, "PROBLEMS\n");
} else { } else {
fputs("foo\n", app_stdin); fputs("foo\n", app_stdin);
fputs("bar\n", app_stdin); fputs("bar\n", app_stdin);
while(fgets(buffer, sizeof buffer, app_stdout) != NULL) { while(fgets(buffer, sizeof buffer, app_stdout) != NULL) {
fprintf(stdout, "STDOUT: %s\n", buffer); fprintf(stdout, "STDOUT: %s\n", buffer);
} }
while(fgets(buffer, sizeof buffer, app_stderr) != NULL) { while(fgets(buffer, sizeof buffer, app_stderr) != NULL) {
fprintf(stdout, "STDERR: %s\n", buffer); fprintf(stdout, "STDERR: %s\n", buffer);
} }
} }
} }
fputs("bye\n", stdout); fputs("bye\n", stdout);
close(channels[0]); close(channels[0]);
close(channels[1]); close(channels[1]);
close(channels[2]); close(channels[2]);
return 0; return 0;
} }
#endif #endif

View file

@ -1,146 +1,146 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2003, 2008 IBM Corporation and others. * Copyright (c) 2003, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
*******************************************************************************/ *******************************************************************************/
#include "exec0.h" #include "exec0.h"
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <libgen.h> #include <libgen.h>
#include <stdlib.h> #include <stdlib.h>
/* from pfind.c */ /* from pfind.c */
extern char *pfind(const char *name); extern char *pfind(const char *name);
pid_t pid_t
exec0(const char *path, char *const argv[], char *const envp[], exec0(const char *path, char *const argv[], char *const envp[],
const char *dirpath, int channels[3]) const char *dirpath, int channels[3])
{ {
int pipe0[2], pipe1[2], pipe2[2]; int pipe0[2], pipe1[2], pipe2[2];
pid_t childpid; pid_t childpid;
char *full_path; char *full_path;
/* /*
* We use pfind() to check that the program exists and is an executable. * 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. * If not pass the error up. Also execve() wants a full path.
*/ */
full_path = pfind(path); full_path = pfind(path);
if (full_path == NULL) { if (full_path == NULL) {
fprintf(stderr, "Unable to find full path for \"%s\"\n", (path) ? path : ""); fprintf(stderr, "Unable to find full path for \"%s\"\n", (path) ? path : "");
return -1; return -1;
} }
/* /*
* Make sure we can create our pipes before forking. * Make sure we can create our pipes before forking.
*/ */
if (channels != NULL) { if (channels != NULL) {
if (pipe(pipe0) < 0 || pipe(pipe1) < 0 || pipe(pipe2) < 0) { if (pipe(pipe0) < 0 || pipe(pipe1) < 0 || pipe(pipe2) < 0) {
fprintf(stderr, "%s(%d): returning due to error.\n", fprintf(stderr, "%s(%d): returning due to error.\n",
__FUNCTION__, __LINE__); __FUNCTION__, __LINE__);
free(full_path); free(full_path);
return -1; return -1;
} }
} }
childpid = fork(); childpid = fork();
if (childpid < 0) { if (childpid < 0) {
fprintf(stderr, "%s(%d): returning due to error: %s\n", fprintf(stderr, "%s(%d): returning due to error: %s\n",
__FUNCTION__, __LINE__, strerror(errno)); __FUNCTION__, __LINE__, strerror(errno));
free(full_path); free(full_path);
return -1; return -1;
} else if (childpid == 0) { /* child */ } else if (childpid == 0) { /* child */
char *ptr; char *ptr;
chdir(dirpath); chdir(dirpath);
if (channels != NULL) { if (channels != NULL) {
/* Close the write end of pipe0 */ /* Close the write end of pipe0 */
if (close(pipe0[1]) == -1) if (close(pipe0[1]) == -1)
perror("close(pipe0[1])"); perror("close(pipe0[1])");
/* Close the read end of pipe1 */ /* Close the read end of pipe1 */
if (close(pipe1[0]) == -1) if (close(pipe1[0]) == -1)
perror("close(pipe1[0])"); perror("close(pipe1[0])");
/* Close the read end of pipe2 */ /* Close the read end of pipe2 */
if (close(pipe2[0]) == -1) if (close(pipe2[0]) == -1)
perror("close(pipe2[0]))"); perror("close(pipe2[0]))");
/* redirections */ /* redirections */
dup2(pipe0[0], STDIN_FILENO); /* dup stdin */ dup2(pipe0[0], STDIN_FILENO); /* dup stdin */
dup2(pipe1[1], STDOUT_FILENO); /* dup stdout */ dup2(pipe1[1], STDOUT_FILENO); /* dup stdout */
dup2(pipe2[1], STDERR_FILENO); /* dup stderr */ dup2(pipe2[1], STDERR_FILENO); /* dup stderr */
} }
/* Close all the fd's in the child */ /* Close all the fd's in the child */
{ {
int fdlimit = sysconf(_SC_OPEN_MAX); int fdlimit = sysconf(_SC_OPEN_MAX);
int fd = 3; int fd = 3;
while (fd < fdlimit) while (fd < fdlimit)
close(fd++); close(fd++);
} }
if (envp[0] == NULL) { if (envp[0] == NULL) {
execv(full_path, argv); execv(full_path, argv);
} else { } else {
execve(full_path, argv, envp); execve(full_path, argv, envp);
} }
_exit(127); _exit(127);
} else if (childpid != 0) { /* parent */ } else if (childpid != 0) { /* parent */
char b; char b;
if (channels != NULL) { if (channels != NULL) {
/* close the read end of pipe1 */ /* close the read end of pipe1 */
if (close(pipe0[0]) == -1) if (close(pipe0[0]) == -1)
perror("close(pipe0[0])"); perror("close(pipe0[0])");
/* close the write end of pipe2 */ /* close the write end of pipe2 */
if (close(pipe1[1]) == -1) if (close(pipe1[1]) == -1)
perror("close(pipe1[1])"); perror("close(pipe1[1])");
/* close the write end of pipe2 */ /* close the write end of pipe2 */
if (close(pipe2[1]) == -1) if (close(pipe2[1]) == -1)
perror("close(pipe2[1])"); perror("close(pipe2[1])");
channels[0] = pipe0[1]; /* Output Stream. */ channels[0] = pipe0[1]; /* Output Stream. */
channels[1] = pipe1[0]; /* Input Stream. */ channels[1] = pipe1[0]; /* Input Stream. */
channels[2] = pipe2[0]; /* Input Stream. */ channels[2] = pipe2[0]; /* Input Stream. */
} }
free(full_path); free(full_path);
return childpid; return childpid;
} }
free(full_path); free(full_path);
return -1; /*NOT REACHED */ return -1; /*NOT REACHED */
} }
int wait0(pid_t pid) int wait0(pid_t pid)
{ {
int status; int status;
int val = -1; int val = -1;
if (pid < 0 || waitpid(pid, &status, 0) < 0) if (pid < 0 || waitpid(pid, &status, 0) < 0)
return -1; return -1;
if (WIFEXITED(status)) { if (WIFEXITED(status)) {
val = WEXITSTATUS(status); val = WEXITSTATUS(status);
} }
return val; return val;
} }

View file

@ -1,114 +1,114 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2003, 2008 IBM Corporation and others. * Copyright (c) 2003, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
*******************************************************************************/ *******************************************************************************/
#include <jni.h> #include <jni.h>
#include <stdio.h> #include <stdio.h>
#include <SpawnerInputStream.h> #include <SpawnerInputStream.h>
#include <SpawnerOutputStream.h> #include <SpawnerOutputStream.h>
#include <unistd.h> #include <unistd.h>
/* Header for class _org_eclipse_cdt_utils_spawner_SpawnerInputStream */ /* Header for class _org_eclipse_cdt_utils_spawner_SpawnerInputStream */
/* Header for class _org_eclipse_cdt_utils_spawner_SpawnerOutputStream */ /* Header for class _org_eclipse_cdt_utils_spawner_SpawnerOutputStream */
/* /*
* Class: org_eclipse_cdt_utils_spawner_SpawnerInputStream * Class: org_eclipse_cdt_utils_spawner_SpawnerInputStream
* Method: read0 * Method: read0
* Signature: (I)I * Signature: (I)I
*/ */
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_org_eclipse_cdt_utils_spawner_SpawnerInputStream_read0(JNIEnv * env, Java_org_eclipse_cdt_utils_spawner_SpawnerInputStream_read0(JNIEnv * env,
jobject jobj, jobject jobj,
jint jfd, jint jfd,
jbyteArray buf, jbyteArray buf,
jint buf_len) jint buf_len)
{ {
int fd; int fd;
int status; int status;
jbyte *data; jbyte *data;
int data_len; int data_len;
data = (*env)->GetByteArrayElements(env, buf, 0); data = (*env)->GetByteArrayElements(env, buf, 0);
data_len = buf_len; data_len = buf_len;
fd = jfd; fd = jfd;
status = read( fd, data, data_len ); status = read( fd, data, data_len );
(*env)->ReleaseByteArrayElements(env, buf, data, 0); (*env)->ReleaseByteArrayElements(env, buf, data, 0);
if (status == 0) { if (status == 0) {
/* EOF. */ /* EOF. */
status = -1; status = -1;
} else if (status == -1) { } else if (status == -1) {
/* Error, toss an exception */ /* Error, toss an exception */
jclass exception = (*env)->FindClass(env, "java/io/IOException"); jclass exception = (*env)->FindClass(env, "java/io/IOException");
if (exception == NULL) { if (exception == NULL) {
/* Give up. */ /* Give up. */
return -1; return -1;
} }
(*env)->ThrowNew(env, exception, "read error"); (*env)->ThrowNew(env, exception, "read error");
} }
return status; return status;
} }
/* /*
* Class: org_eclipse_cdt_utils_spawner_SpawnerInputStream * Class: org_eclipse_cdt_utils_spawner_SpawnerInputStream
* Method: close0 * Method: close0
* Signature: (I)I * Signature: (I)I
*/ */
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_org_eclipse_cdt_utils_spawner_SpawnerInputStream_close0(JNIEnv * env, Java_org_eclipse_cdt_utils_spawner_SpawnerInputStream_close0(JNIEnv * env,
jobject jobj, jobject jobj,
jint fd) jint fd)
{ {
return close(fd); return close(fd);
} }
/* /*
* Class: org_eclipse_cdt_utils_spawner_SpawnerOutputStream * Class: org_eclipse_cdt_utils_spawner_SpawnerOutputStream
* Method: write0 * Method: write0
* Signature: (II)I * Signature: (II)I
*/ */
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_org_eclipse_cdt_utils_spawner_SpawnerOutputStream_write0(JNIEnv * env, Java_org_eclipse_cdt_utils_spawner_SpawnerOutputStream_write0(JNIEnv * env,
jobject jobj, jobject jobj,
jint jfd, jint jfd,
jbyteArray buf, jbyteArray buf,
jint buf_len) jint buf_len)
{ {
int status; int status;
int fd; int fd;
jbyte *data; jbyte *data;
int data_len; int data_len;
data = (*env)->GetByteArrayElements(env, buf, 0); data = (*env)->GetByteArrayElements(env, buf, 0);
data_len = buf_len; data_len = buf_len;
fd = jfd; fd = jfd;
status = write(fd, data, data_len); status = write(fd, data, data_len);
(*env)->ReleaseByteArrayElements(env, buf, data, 0); (*env)->ReleaseByteArrayElements(env, buf, data, 0);
return status; return status;
} }
/* /*
* Class: org_eclipse_cdt_utils_spawner_SpawnerOutputStream * Class: org_eclipse_cdt_utils_spawner_SpawnerOutputStream
* Method: close0 * Method: close0
* Signature: (I)I * Signature: (I)I
*/ */
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_org_eclipse_cdt_utils_spawner_SpawnerOutputStream_close0(JNIEnv * env, Java_org_eclipse_cdt_utils_spawner_SpawnerOutputStream_close0(JNIEnv * env,
jobject jobj, jobject jobj,
jint fd) jint fd)
{ {
return close(fd); return close(fd);
} }

View file

@ -1,14 +1,14 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2003, 2008 IBM Corporation and others. * Copyright (c) 2003, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* QNX Software Systems * QNX Software Systems
*******************************************************************************/ *******************************************************************************/
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>

View file

@ -1,14 +1,14 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2003, 2008 IBM Corporation and others. * Copyright (c) 2003, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* QNX Software Systems * QNX Software Systems
*******************************************************************************/ *******************************************************************************/
#ifndef _OPENPTY_H #ifndef _OPENPTY_H
#define _OPENPTY_H #define _OPENPTY_H

View file

@ -1,13 +1,13 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2003, 2008 IBM Corporation and others. * Copyright (c) 2003, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
*******************************************************************************/ *******************************************************************************/
/* /*
* pfind.c - Search for a binary in $PATH. * pfind.c - Search for a binary in $PATH.

View file

@ -1,14 +1,14 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2003, 2008 IBM Corporation and others. * Copyright (c) 2003, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* QNX Software Systems * QNX Software Systems
*******************************************************************************/ *******************************************************************************/
#include "PTY.h" #include "PTY.h"
#include "openpty.h" #include "openpty.h"

View file

@ -1,13 +1,13 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2003, 2008 IBM Corporation and others. * Copyright (c) 2003, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
*******************************************************************************/ *******************************************************************************/
#include <jni.h> #include <jni.h>
#include <stdio.h> #include <stdio.h>

View file

@ -1,287 +1,287 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2003, 2008 IBM Corporation and others. * Copyright (c) 2003, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* QNX Software Systems * QNX Software Systems
*******************************************************************************/ *******************************************************************************/
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <signal.h> #include <signal.h>
#include <string.h> #include <string.h>
#include <jni.h> #include <jni.h>
#include "exec0.h" #include "exec0.h"
#include <Spawner.h> #include <Spawner.h>
#define DEBUGIT 0 #define DEBUGIT 0
/* /*
* Header for class org_eclipse_cdt_utils_spawner_Spawner * Header for class org_eclipse_cdt_utils_spawner_Spawner
*/ */
#if DEBUGIT #if DEBUGIT
static void print_array(char **c_array) static void print_array(char **c_array)
{ {
if (c_array) { if (c_array) {
char **p = c_array; char **p = c_array;
for (; *p; p++) { for (; *p; p++) {
if (*p) { if (*p) {
fprintf(stderr, " %s", *p); fprintf(stderr, " %s", *p);
} }
} }
} else { } else {
fprintf(stderr, "null"); fprintf(stderr, "null");
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
#endif #endif
static char **alloc_c_array(JNIEnv * env, jobjectArray j_array) static char **alloc_c_array(JNIEnv * env, jobjectArray j_array)
{ {
int i; int i;
jint c_array_size = (*env)->GetArrayLength(env, j_array); jint c_array_size = (*env)->GetArrayLength(env, j_array);
char **c_array = calloc(c_array_size + 1, sizeof(*c_array)); char **c_array = calloc(c_array_size + 1, sizeof(*c_array));
if (c_array == NULL) if (c_array == NULL)
return NULL; return NULL;
for (i = 0; i < c_array_size; i++) { for (i = 0; i < c_array_size; i++) {
jstring j_str = jstring j_str =
(jstring) (*env)->GetObjectArrayElement(env, j_array, i); (jstring) (*env)->GetObjectArrayElement(env, j_array, i);
const char *c_str = (*env)->GetStringUTFChars(env, j_str, NULL); const char *c_str = (*env)->GetStringUTFChars(env, j_str, NULL);
c_array[i] = (char *) strdup(c_str); c_array[i] = (char *) strdup(c_str);
(*env)->ReleaseStringUTFChars(env, j_str, c_str); (*env)->ReleaseStringUTFChars(env, j_str, c_str);
(*env)->DeleteLocalRef(env, j_str); (*env)->DeleteLocalRef(env, j_str);
} }
return c_array; return c_array;
} }
static void free_c_array(char **c_array) static void free_c_array(char **c_array)
{ {
if (c_array) { if (c_array) {
char **p = c_array; char **p = c_array;
for (; *p; p++) { for (; *p; p++) {
if (*p) { if (*p) {
free(*p); free(*p);
} }
} }
free(c_array); free(c_array);
} }
} }
/* /*
* Class: org_eclipse_cdt_utils_spawner_Spawner * Class: org_eclipse_cdt_utils_spawner_Spawner
* Method: exec2 * Method: exec2
* Signature: ([Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;[ILorg/eclipse/cdt/utils/pty/PTY;)I * 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 JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec2
(JNIEnv *env, jobject jobj, jobjectArray jcmd, jobjectArray jenv, jstring jdir, jintArray jchannels, (JNIEnv *env, jobject jobj, jobjectArray jcmd, jobjectArray jenv, jstring jdir, jintArray jchannels,
jstring jslaveName, jint masterFD) jstring jslaveName, jint masterFD)
{ {
jint *channels = (*env)->GetIntArrayElements(env, jchannels, 0); jint *channels = (*env)->GetIntArrayElements(env, jchannels, 0);
const char *dirpath = (*env)->GetStringUTFChars(env, jdir, NULL); const char *dirpath = (*env)->GetStringUTFChars(env, jdir, NULL);
const char *pts_name = (*env)->GetStringUTFChars(env, jslaveName, NULL); const char *pts_name = (*env)->GetStringUTFChars(env, jslaveName, NULL);
char **cmd; char **cmd;
char **envp; char **envp;
int fd[3]; int fd[3];
pid_t pid = -1; pid_t pid = -1;
if (channels == NULL) if (channels == NULL)
goto bail_out; goto bail_out;
cmd = alloc_c_array(env, jcmd); cmd = alloc_c_array(env, jcmd);
if (cmd == NULL) if (cmd == NULL)
goto bail_out; goto bail_out;
envp = alloc_c_array(env, jenv); envp = alloc_c_array(env, jenv);
if (envp == NULL) if (envp == NULL)
goto bail_out; goto bail_out;
#if DEBUGIT #if DEBUGIT
fprintf(stderr, "command:"); fprintf(stderr, "command:");
print_array(cmd); print_array(cmd);
fprintf(stderr, "Envp:"); fprintf(stderr, "Envp:");
print_array(envp); print_array(envp);
fprintf(stderr, "dirpath: %s\n", dirpath); fprintf(stderr, "dirpath: %s\n", dirpath);
fprintf(stderr, "pts_name: %s\n", pts_name); fprintf(stderr, "pts_name: %s\n", pts_name);
#endif #endif
pid = exec_pty(cmd[0], cmd, envp, dirpath, fd, pts_name, masterFD); pid = exec_pty(cmd[0], cmd, envp, dirpath, fd, pts_name, masterFD);
if (pid < 0) if (pid < 0)
goto bail_out; goto bail_out;
channels[0] = fd[0]; channels[0] = fd[0];
channels[1] = fd[1]; channels[1] = fd[1];
channels[2] = fd[2]; channels[2] = fd[2];
bail_out: bail_out:
(*env)->ReleaseIntArrayElements(env, jchannels, channels, 0); (*env)->ReleaseIntArrayElements(env, jchannels, channels, 0);
(*env)->ReleaseStringUTFChars(env, jdir, dirpath); (*env)->ReleaseStringUTFChars(env, jdir, dirpath);
(*env)->ReleaseStringUTFChars(env, jslaveName, pts_name); (*env)->ReleaseStringUTFChars(env, jslaveName, pts_name);
if (cmd) if (cmd)
free_c_array(cmd); free_c_array(cmd);
if (envp) if (envp)
free_c_array(envp); free_c_array(envp);
return pid; return pid;
} }
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_org_eclipse_cdt_utils_spawner_Spawner_exec1(JNIEnv * env, jobject jobj, Java_org_eclipse_cdt_utils_spawner_Spawner_exec1(JNIEnv * env, jobject jobj,
jobjectArray jcmd, jobjectArray jcmd,
jobjectArray jenv, jobjectArray jenv,
jstring jdir) jstring jdir)
{ {
const char *dirpath = (*env)->GetStringUTFChars(env, jdir, NULL); const char *dirpath = (*env)->GetStringUTFChars(env, jdir, NULL);
char **cmd; char **cmd;
char **envp; char **envp;
pid_t pid = -1; pid_t pid = -1;
cmd = alloc_c_array(env, jcmd); cmd = alloc_c_array(env, jcmd);
if (cmd == NULL) if (cmd == NULL)
goto bail_out; goto bail_out;
envp = alloc_c_array(env, jenv); envp = alloc_c_array(env, jenv);
if (envp == NULL) if (envp == NULL)
goto bail_out; goto bail_out;
#if DEBUGIT #if DEBUGIT
fprintf(stderr, "command:"); fprintf(stderr, "command:");
print_array(cmd); print_array(cmd);
fprintf(stderr, "Envp:"); fprintf(stderr, "Envp:");
print_array(envp); print_array(envp);
fprintf(stderr, "dirpath: %s\n", dirpath); fprintf(stderr, "dirpath: %s\n", dirpath);
#endif #endif
pid = exec0(cmd[0], cmd, envp, dirpath, NULL); pid = exec0(cmd[0], cmd, envp, dirpath, NULL);
if (pid < 0) if (pid < 0)
goto bail_out; goto bail_out;
bail_out: bail_out:
(*env)->ReleaseStringUTFChars(env, jdir, dirpath); (*env)->ReleaseStringUTFChars(env, jdir, dirpath);
if (cmd) if (cmd)
free_c_array(cmd); free_c_array(cmd);
if (envp) if (envp)
free_c_array(envp); free_c_array(envp);
return pid; return pid;
} }
/* /*
* Class: org_eclipse_cdt_utils_spawner_Spawner * Class: org_eclipse_cdt_utils_spawner_Spawner
* Method: exec0 * Method: exec0
* Signature: ([Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;[I)I * Signature: ([Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;[I)I
*/ */
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_org_eclipse_cdt_utils_spawner_Spawner_exec0(JNIEnv * env, jobject jobj, Java_org_eclipse_cdt_utils_spawner_Spawner_exec0(JNIEnv * env, jobject jobj,
jobjectArray jcmd, jobjectArray jcmd,
jobjectArray jenv, jobjectArray jenv,
jstring jdir, jstring jdir,
jintArray jchannels) jintArray jchannels)
{ {
jint *channels = (*env)->GetIntArrayElements(env, jchannels, 0); jint *channels = (*env)->GetIntArrayElements(env, jchannels, 0);
const char *dirpath = (*env)->GetStringUTFChars(env, jdir, NULL); const char *dirpath = (*env)->GetStringUTFChars(env, jdir, NULL);
char **cmd; char **cmd;
char **envp; char **envp;
int fd[3]; int fd[3];
pid_t pid = -1; pid_t pid = -1;
if (channels == NULL) if (channels == NULL)
goto bail_out; goto bail_out;
cmd = alloc_c_array(env, jcmd); cmd = alloc_c_array(env, jcmd);
if (cmd == NULL) if (cmd == NULL)
goto bail_out; goto bail_out;
envp = alloc_c_array(env, jenv); envp = alloc_c_array(env, jenv);
if (envp == NULL) if (envp == NULL)
goto bail_out; goto bail_out;
#if DEBUGIT #if DEBUGIT
fprintf(stderr, "command:"); fprintf(stderr, "command:");
print_array(cmd); print_array(cmd);
fprintf(stderr, "Envp:"); fprintf(stderr, "Envp:");
print_array(envp); print_array(envp);
fprintf(stderr, "dirpath: %s\n", dirpath); fprintf(stderr, "dirpath: %s\n", dirpath);
#endif #endif
pid = exec0(cmd[0], cmd, envp, dirpath, fd); pid = exec0(cmd[0], cmd, envp, dirpath, fd);
if (pid < 0) if (pid < 0)
goto bail_out; goto bail_out;
channels[0] = fd[0]; channels[0] = fd[0];
channels[1] = fd[1]; channels[1] = fd[1];
channels[2] = fd[2]; channels[2] = fd[2];
bail_out: bail_out:
(*env)->ReleaseIntArrayElements(env, jchannels, channels, 0); (*env)->ReleaseIntArrayElements(env, jchannels, channels, 0);
(*env)->ReleaseStringUTFChars(env, jdir, dirpath); (*env)->ReleaseStringUTFChars(env, jdir, dirpath);
if (cmd) if (cmd)
free_c_array(cmd); free_c_array(cmd);
if (envp) if (envp)
free_c_array(envp); free_c_array(envp);
return pid; return pid;
} }
/* /*
* Class: org_eclipse_cdt_utils_spawner_Spawner * Class: org_eclipse_cdt_utils_spawner_Spawner
* Method: raise * Method: raise
* Signature: (II)I * Signature: (II)I
*/ */
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_org_eclipse_cdt_utils_spawner_Spawner_raise(JNIEnv * env, jobject jobj, Java_org_eclipse_cdt_utils_spawner_Spawner_raise(JNIEnv * env, jobject jobj,
jint pid, jint sig) jint pid, jint sig)
{ {
int status = -1; int status = -1;
switch (sig) { switch (sig) {
case 0: /* NOOP */ case 0: /* NOOP */
status = kill(pid, 0); status = kill(pid, 0);
break; break;
case 2: /* INTERRUPT */ case 2: /* INTERRUPT */
status = kill(pid, SIGINT); status = kill(pid, SIGINT);
break; break;
case 9: /* KILL */ case 9: /* KILL */
status = kill(pid, SIGKILL); status = kill(pid, SIGKILL);
break; break;
case 15: /* TERM */ case 15: /* TERM */
status = kill(pid, SIGTERM); status = kill(pid, SIGTERM);
break; break;
default: default:
status = kill(pid, sig); /* WHAT ?? */ status = kill(pid, sig); /* WHAT ?? */
break; break;
} }
return status; return status;
} }
/* /*
* Class: org_eclipse_cdt_utils_spawner_Spawner * Class: org_eclipse_cdt_utils_spawner_Spawner
* Method: waitFor * Method: waitFor
* Signature: (I)I * Signature: (I)I
*/ */
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_org_eclipse_cdt_utils_spawner_Spawner_waitFor(JNIEnv * env, Java_org_eclipse_cdt_utils_spawner_Spawner_waitFor(JNIEnv * env,
jobject jobj, jint pid) jobject jobj, jint pid)
{ {
return wait0(pid); return wait0(pid);
} }