1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-12 18:55:38 +02:00

change library layout

This commit is contained in:
David Inglis 2002-11-04 20:57:06 +00:00
parent c7f9164d44
commit 985995cb0f
17 changed files with 531 additions and 495 deletions

View file

@ -1 +1,3 @@
*.o *.o
*.so
*.a

View file

@ -1,4 +1,4 @@
LIST=CPU LIST=ALL
ifndef QRECURSE ifndef QRECURSE
QRECURSE=recurse.mk QRECURSE=recurse.mk
ifdef QCONFIG ifdef QCONFIG

View file

@ -0,0 +1,8 @@
LIST=CPU
ifndef QRECURSE
QRECURSE=recurse.mk
ifdef QCONFIG
QRDIR=$(dir $(QCONFIG))
endif
endif
include $(QRDIR)$(QRECURSE)

View file

@ -1,16 +1,14 @@
ifndef QCONFIG ifndef QCONFIG
QCONFIG=qconfig.mk QCONFIG=qconfig.mk
endif endif
include $(QCONFIG) include $(QCONFIG)
NAME=spawner include $(MKFILES_ROOT)/qtargets.mk
include $(MKFILES_ROOT)/qtargets.mk ifeq ($(OS),nto)
ifeq ($(IVEHOME),)
ifeq ($(OS),nto) IVEHOME:=/opt/vame/ive/bin
ifeq ($(IVEHOME),) endif
IVEHOME:=/opt/vame/ive/bin EXTRA_INCVPATH+=$(IVEHOME)/include
endif endif
EXTRA_INCVPATH+=$(IVEHOME)/include
endif

View file

@ -55,7 +55,8 @@ int
ptym_open(char * pts_name) ptym_open(char * pts_name)
{ {
char *ptr1, *ptr2; char *ptr1, *ptr2;
int fdm;
strcpy(pts_name, "/dev/ptyXY"); strcpy(pts_name, "/dev/ptyXY");
/* array index: 012345689 (for references in following code) */ /* array index: 012345689 (for references in following code) */
for (ptr1 = "pqrstuvwxyzPQRST"; *ptr1 != 0; ptr1++) { for (ptr1 = "pqrstuvwxyzPQRST"; *ptr1 != 0; ptr1++) {
@ -81,7 +82,7 @@ ptym_open(char * pts_name)
int int
ptys_open(int fdm, char * pts_name) ptys_open(int fdm, char * pts_name)
{ {
int gid; int gid, fds;
struct group *grptr; struct group *grptr;
grptr = getgrnam("tty"); grptr = getgrnam("tty");

View file

@ -0,0 +1,8 @@
LIST=CPU
ifndef QRECURSE
QRECURSE=recurse.mk
ifdef QCONFIG
QRDIR=$(dir $(QCONFIG))
endif
endif
include $(QRDIR)$(QRECURSE)

View file

@ -1,45 +1,45 @@
/* 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_Spawner */ /* Header for class com_qnx_tools_utils_spawner_Spawner */
#ifndef _Included_com_qnx_tools_utils_spawner_Spawner #ifndef _Included_com_qnx_tools_utils_spawner_Spawner
#define _Included_com_qnx_tools_utils_spawner_Spawner #define _Included_com_qnx_tools_utils_spawner_Spawner
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/* /*
* 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 Java_org_eclipse_cdt_utils_spawner_Spawner_exec0 JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec0
(JNIEnv *, jobject, jobjectArray, jobjectArray, jstring, jintArray); (JNIEnv *, jobject, jobjectArray, jobjectArray, jstring, jintArray);
/* /*
* 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 Java_org_eclipse_cdt_utils_spawner_Spawner_exec1 JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec1
(JNIEnv *, jobject, jobjectArray, jobjectArray, jstring); (JNIEnv *, jobject, jobjectArray, jobjectArray, jstring);
/* /*
* 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 Java_org_eclipse_cdt_utils_spawner_Spawner_raise JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_raise
(JNIEnv *, jobject, jint, jint); (JNIEnv *, jobject, jint, jint);
/* /*
* 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 Java_org_eclipse_cdt_utils_spawner_Spawner_waitFor JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_waitFor
(JNIEnv *, jobject, jint); (JNIEnv *, jobject, jint);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif #endif

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

@ -0,0 +1,14 @@
ifndef QCONFIG
QCONFIG=qconfig.mk
endif
include $(QCONFIG)
include $(MKFILES_ROOT)/qtargets.mk
ifeq ($(OS),nto)
ifeq ($(IVEHOME),)
IVEHOME:=/opt/vame/ive/bin
endif
EXTRA_INCVPATH+=$(IVEHOME)/include
endif

View file

@ -1,109 +1,109 @@
/* Copyright, 2002, QNX Software Systems Ltd. All Rights Reserved /* Copyright, 2002, QNX Software Systems Ltd. All Rights Reserved
* This source code has been published by QNX Software Systems * This source code has been published by QNX Software Systems
* Ltd. (QSSL). However, any use, reproduction, modification, distribution * Ltd. (QSSL). However, any use, reproduction, modification, distribution
* or transfer of this software, or any software which includes or is based * or transfer of this software, or any software which includes or is based
* upon any of this code, is only permitted if expressly authorized by a * upon any of this code, is only permitted if expressly authorized by a
* written license agreement from QSSL. Contact the QNX Developer's Network * written license agreement from QSSL. Contact the QNX Developer's Network
* or contact QSSL's legal department for more information. * or contact QSSL's legal department for more information.
* *
* *
* iostream.c * iostream.c
* *
* This is a JNI implementation of access to standard i/o streams * This is a JNI implementation of access to standard i/o streams
*/ */
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <sys/uio.h> #include <sys/uio.h>
#include <errno.h> #include <errno.h>
#include "SpawnerInputStream.h" #include "SpawnerInputStream.h"
#include "SpawnerOutputStream.h" #include "SpawnerOutputStream.h"
#include "jni.h" #include "jni.h"
void ThrowByName(JNIEnv *env, const char *name, const char *msg); void ThrowByName(JNIEnv *env, const char *name, const char *msg);
#define BUFF_SIZE (1024) #define BUFF_SIZE (1024)
/* Inaccessible static: skipBuffer */ /* Inaccessible static: skipBuffer */
/* /*
* Class: SpawnerInputStream * Class: SpawnerInputStream
* Method: read0 * Method: read0
* Signature: (I)I * Signature: (I)I
*/ */
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_SpawnerInputStream_read0 JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_SpawnerInputStream_read0
(JNIEnv * env, jobject proc, jint fd, jbyteArray buf, jint len) (JNIEnv * env, jobject proc, jint fd, jbyteArray buf, jint len)
{ {
unsigned char tmpBuf[BUFF_SIZE]; unsigned char tmpBuf[BUFF_SIZE];
int nBuffOffset = 0; int nBuffOffset = 0;
// printf("Come to read0\n"); // printf("Come to read0\n");
while(len > nBuffOffset) while(len > nBuffOffset)
{ {
int nReadLen = min(len - nBuffOffset, BUFF_SIZE); int nReadLen = min(len - nBuffOffset, BUFF_SIZE);
int nread; int nread;
nread = read(fd, tmpBuf, nReadLen); nread = read(fd, tmpBuf, nReadLen);
if(nread > 0) if(nread > 0)
(*env) -> SetByteArrayRegion(env, buf, nBuffOffset, nReadLen, tmpBuf); (*env) -> SetByteArrayRegion(env, buf, nBuffOffset, nReadLen, tmpBuf);
else else
break; break;
nBuffOffset += nread; nBuffOffset += nread;
if(nread != nReadLen) if(nread != nReadLen)
break; break;
} }
// printf("Leave read with %i bytes read\n", nBuffOffset); // printf("Leave read with %i bytes read\n", nBuffOffset);
return nBuffOffset; // This is a real full readed length return nBuffOffset; // This is a real full readed length
} }
/* /*
* Class: SpawnerInputStream * Class: 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 * env, jobject proc, jint fd) (JNIEnv * env, jobject proc, jint fd)
{ {
return close(fd); return close(fd);
} }
/* /*
* Class: SpawnerOutputStream * Class: 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 * env, jobject proc, jint fd, jbyteArray buf, jint len) (JNIEnv * env, jobject proc, jint fd, jbyteArray buf, jint len)
{ {
unsigned char tmpBuf[BUFF_SIZE]; unsigned char tmpBuf[BUFF_SIZE];
int nBuffOffset = 0; int nBuffOffset = 0;
// int rc = 0; // int rc = 0;
// printf("Come to write0, len = %i\n", len); // printf("Come to write0, len = %i\n", len);
while(len > nBuffOffset) while(len > nBuffOffset)
{ {
int nWriteLen = min(len - nBuffOffset, BUFF_SIZE); int nWriteLen = min(len - nBuffOffset, BUFF_SIZE);
(*env) -> GetByteArrayRegion(env, buf, nBuffOffset, nWriteLen, tmpBuf); (*env) -> GetByteArrayRegion(env, buf, nBuffOffset, nWriteLen, tmpBuf);
// printf("Write %i bytes; last byte = %#x\n", nWriteLen, (int)tmpBuf[nWriteLen - 1]); // printf("Write %i bytes; last byte = %#x\n", nWriteLen, (int)tmpBuf[nWriteLen - 1]);
if(nWriteLen != write(fd, tmpBuf, nWriteLen)) if(nWriteLen != write(fd, tmpBuf, nWriteLen))
{ {
// printf("Error: written %i bytes; errno = %i, fd = %i, len = %i ", nWriteLen, errno, fd, rc); // printf("Error: written %i bytes; errno = %i, fd = %i, len = %i ", nWriteLen, errno, fd, rc);
ThrowByName(env, "java/io/IOException", strerror(errno)); ThrowByName(env, "java/io/IOException", strerror(errno));
} }
nBuffOffset += nWriteLen; nBuffOffset += nWriteLen;
} }
return 0; return 0;
} }
/* /*
* Class: SpawnerOutputStream * Class: 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 * env, jobject proc, jint fd) (JNIEnv * env, jobject proc, jint fd)
{ {
return close(fd); return close(fd);
} }

View file

@ -1,257 +1,257 @@
#include <unistd.h> #include <unistd.h>
#include <malloc.h> #include <malloc.h>
#include <spawn.h> #include <spawn.h>
#include <signal.h> #include <signal.h>
#include <dlfcn.h> #include <dlfcn.h>
#include <limits.h> #include <limits.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include "Spawner.h" #include "Spawner.h"
typedef JNIEXPORT void * (JNICALL * JVM_GetThreadInterruptEvent)(); typedef JNIEXPORT void * (JNICALL * JVM_GetThreadInterruptEvent)();
typedef JNIEXPORT char * (JNICALL * JVM_NativePath)(const char *); typedef JNIEXPORT char * (JNICALL * JVM_NativePath)(const char *);
void ThrowByName(JNIEnv *env, const char *name, const char *msg); void ThrowByName(JNIEnv *env, const char *name, const char *msg);
void * GetJVMProc(char * vmlib, char * procName); void * GetJVMProc(char * vmlib, char * procName);
static void * hVM = NULL; /* Java Virtual Machine handler. */ static void * hVM = NULL; /* Java Virtual Machine handler. */
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec0 JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec0
(JNIEnv * env, jobject proc, jobjectArray cmdArray, jobjectArray envp, jstring dir, jintArray channels) (JNIEnv * env, jobject proc, jobjectArray cmdArray, jobjectArray envp, jstring dir, jintArray channels)
{ {
int fd_map[3]; /* File descriptors. */ int fd_map[3]; /* File descriptors. */
int fd_ret[3]; /* File descriptors that we return to Java. */ int fd_ret[3]; /* File descriptors that we return to Java. */
int fd[2]; /* Pipe open structure. */ int fd[2]; /* Pipe open structure. */
int i; int i;
int nParms = 0;/* Number of parameters. */ int nParms = 0;/* Number of parameters. */
int nEnvs = 0;/* Number of environment variables. */ int nEnvs = 0;/* Number of environment variables. */
char ** pParms = NULL; /* Parameters. */ char ** pParms = NULL; /* Parameters. */
char ** pEnvs = NULL; /* Environment variables. */ char ** pEnvs = NULL; /* Environment variables. */
char * pCommand = NULL; /* Command to execute. */ char * pCommand = NULL; /* Command to execute. */
char cwd[PATH_MAX + 1]; /* Current working directory. */ char cwd[PATH_MAX + 1]; /* Current working directory. */
pid_t pid; /* Process ID. */ pid_t pid; /* Process ID. */
struct inheritance inherit; struct inheritance inherit;
if ((cmdArray == NULL) || ((nParms = (*env)->GetArrayLength(env, cmdArray)) == 0)) if ((cmdArray == NULL) || ((nParms = (*env)->GetArrayLength(env, cmdArray)) == 0))
ThrowByName(env, "java/lang/IOException", "No command line specified"); ThrowByName(env, "java/lang/IOException", "No command line specified");
for (i = 0; i < 3; ++i) { for (i = 0; i < 3; ++i) {
if (EOK != pipe(fd)) if (EOK != pipe(fd))
ThrowByName(env, "java/io/IOException", "Cannot create pipe for spawner"); ThrowByName(env, "java/io/IOException", "Cannot create pipe for spawner");
if (0 == i) { if (0 == i) {
fd_map[i] = fd[0]; fd_map[i] = fd[0];
fd_ret[i] = fd[1]; fd_ret[i] = fd[1];
} else { } else {
fd_map[i] = fd[1]; fd_map[i] = fd[1];
fd_ret[i] = fd[0]; fd_ret[i] = fd[0];
} }
} }
if (nParms > 0) { if (nParms > 0) {
pParms = malloc(sizeof(char *) * (nParms + 1)); pParms = malloc(sizeof(char *) * (nParms + 1));
for (i = 0; i < nParms; ++i) { for (i = 0; i < nParms; ++i) {
jobject item = (*env)->GetObjectArrayElement(env, cmdArray, i); jobject item = (*env)->GetObjectArrayElement(env, cmdArray, i);
const char *str = (*env)->GetStringUTFChars(env, item, 0); const char *str = (*env)->GetStringUTFChars(env, item, 0);
if (i == 0) if (i == 0)
pCommand = strdup(str); pCommand = strdup(str);
pParms[i] = strdup(str); pParms[i] = strdup(str);
(*env)->ReleaseStringUTFChars(env, item, str); (*env)->ReleaseStringUTFChars(env, item, str);
} }
pParms[i] = NULL; pParms[i] = NULL;
} }
nEnvs = (*env) -> GetArrayLength(env, envp); nEnvs = (*env) -> GetArrayLength(env, envp);
if (nEnvs > 0) { if (nEnvs > 0) {
pEnvs = malloc(sizeof(char *) * (nEnvs + 1)); pEnvs = malloc(sizeof(char *) * (nEnvs + 1));
for (i = 0; i < nEnvs; ++i) { for (i = 0; i < nEnvs; ++i) {
jobject item = (*env)->GetObjectArrayElement(env, envp, i); jobject item = (*env)->GetObjectArrayElement(env, envp, i);
const char *str = (*env)->GetStringUTFChars(env, item, 0); const char *str = (*env)->GetStringUTFChars(env, item, 0);
pEnvs[i] = strdup(str); pEnvs[i] = strdup(str);
(*env)->ReleaseStringUTFChars(env, item, str); (*env)->ReleaseStringUTFChars(env, item, str);
} }
pEnvs[i] = NULL; pEnvs[i] = NULL;
} }
if (dir != 0) { if (dir != 0) {
char *item = (char *)(*env)->GetStringUTFChars(env, dir, 0); char *item = (char *)(*env)->GetStringUTFChars(env, dir, 0);
getcwd(cwd, sizeof(cwd)); getcwd(cwd, sizeof(cwd));
chdir(item); chdir(item);
(*env)->ReleaseStringUTFChars(env, dir, item); (*env)->ReleaseStringUTFChars(env, dir, item);
} }
/* Nothing for now. */ /* Nothing for now. */
memset(&inherit, 0, sizeof(inherit)); memset(&inherit, 0, sizeof(inherit));
inherit.flags = SPAWN_SETGROUP; inherit.flags = SPAWN_SETGROUP;
inherit.pgroup = SPAWN_NEWPGROUP; inherit.pgroup = SPAWN_NEWPGROUP;
pid = spawnp(pCommand, 3, fd_map, &inherit, pParms, pEnvs); pid = spawnp(pCommand, 3, fd_map, &inherit, pParms, pEnvs);
if (dir != 0) /* Restore working directory. */ if (dir != 0) /* Restore working directory. */
chdir(cwd); chdir(cwd);
for (i = 0; i < 3; ++i) { for (i = 0; i < 3; ++i) {
close(fd_map[i]); close(fd_map[i]);
} }
if (-1 == pid) { /* Failed - close pipes. */ if (-1 == pid) { /* Failed - close pipes. */
for (i = 0; i < 3; ++i) { for (i = 0; i < 3; ++i) {
close(fd_ret[i]); close(fd_ret[i]);
} }
} else { /* Success - return pipes to Java. */ } else { /* Success - return pipes to Java. */
(*env) -> SetIntArrayRegion(env, channels, 0, 3, fd_ret); (*env) -> SetIntArrayRegion(env, channels, 0, 3, fd_ret);
} }
/* Free Parameters. */ /* Free Parameters. */
if (pParms != NULL) { if (pParms != NULL) {
int j; int j;
for (j = 0; pParms[j] != NULL; j++) { for (j = 0; pParms[j] != NULL; j++) {
if (pParms[j] != NULL) { if (pParms[j] != NULL) {
free(pParms[j]); free(pParms[j]);
} }
} }
free(pParms); free(pParms);
} }
/* Free Environment variables. */ /* Free Environment variables. */
if (pEnvs != NULL) { if (pEnvs != NULL) {
int j; int j;
for (j = 0; pEnvs[j] != NULL; j++) { for (j = 0; pEnvs[j] != NULL; j++) {
if (pEnvs[j] != NULL) { if (pEnvs[j] != NULL) {
free(pEnvs[j]); free(pEnvs[j]);
} }
} }
free(pEnvs); free(pEnvs);
} }
/* Free Command to execute. */ /* Free Command to execute. */
if (pCommand != NULL) { if (pCommand != NULL) {
free(pCommand); free(pCommand);
} }
return pid; return pid;
} }
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec1 JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec1
(JNIEnv * env, jobject proc, jobjectArray cmdArray, jobjectArray envp, jstring dir) (JNIEnv * env, jobject proc, jobjectArray cmdArray, jobjectArray envp, jstring dir)
{ {
int i; int i;
int nParms = 0;// Number of parameters int nParms = 0;// Number of parameters
int nEnvs = 0;// Number of environment variables int nEnvs = 0;// Number of environment variables
char ** pParms = NULL; // Parameters char ** pParms = NULL; // Parameters
char ** pEnvs = NULL; // Environment variables char ** pEnvs = NULL; // Environment variables
char * pCommand = NULL; // Command to execute char * pCommand = NULL; // Command to execute
char * pwd = 0; // Process working directory char * pwd = 0; // Process working directory
char cwd[PATH_MAX + 1]; // Current working directory char cwd[PATH_MAX + 1]; // Current working directory
pid_t pid; // Process ID pid_t pid; // Process ID
struct inheritance inherit; struct inheritance inherit;
if ((cmdArray == 0) || ((nParms = (*env) -> GetArrayLength(env, cmdArray)) == 0)) if ((cmdArray == 0) || ((nParms = (*env) -> GetArrayLength(env, cmdArray)) == 0))
ThrowByName(env, "java/lang/NullPointerException", "No command line specified"); ThrowByName(env, "java/lang/NullPointerException", "No command line specified");
if(nParms > 0) if(nParms > 0)
{ {
pParms = malloc(sizeof(char *) * (nParms + 1)); pParms = malloc(sizeof(char *) * (nParms + 1));
for(i = 0; i < nParms; ++i) for(i = 0; i < nParms; ++i)
{ {
jobject item = (*env) -> GetObjectArrayElement(env, cmdArray, i); jobject item = (*env) -> GetObjectArrayElement(env, cmdArray, i);
const char * str = (*env) -> GetStringUTFChars(env, item, 0); const char * str = (*env) -> GetStringUTFChars(env, item, 0);
if(i == 0) if(i == 0)
pCommand = strdup(str); pCommand = strdup(str);
pParms[i] = strdup(str); pParms[i] = strdup(str);
(*env) -> ReleaseStringUTFChars(env, item, str); (*env) -> ReleaseStringUTFChars(env, item, str);
} }
pParms[i] = NULL; pParms[i] = NULL;
} }
nEnvs = (*env) -> GetArrayLength(env, envp); nEnvs = (*env) -> GetArrayLength(env, envp);
if(nEnvs > 0) if(nEnvs > 0)
{ {
pEnvs = malloc(sizeof(char *) * (nEnvs + 1)); pEnvs = malloc(sizeof(char *) * (nEnvs + 1));
for(i = 0; i < nEnvs; ++i) for(i = 0; i < nEnvs; ++i)
{ {
jobject item = (*env) -> GetObjectArrayElement(env, envp, i); jobject item = (*env) -> GetObjectArrayElement(env, envp, i);
const char * str = (*env) -> GetStringUTFChars(env, item, 0); const char * str = (*env) -> GetStringUTFChars(env, item, 0);
pEnvs[i] = strdup(str); pEnvs[i] = strdup(str);
(*env) -> ReleaseStringUTFChars(env, item, str); (*env) -> ReleaseStringUTFChars(env, item, str);
} }
pEnvs[i] = NULL; pEnvs[i] = NULL;
} }
if (dir != 0) if (dir != 0)
{ {
char * item; char * item;
pwd = strdup(item = (char *)(*env) -> GetStringUTFChars(env, dir, 0)); pwd = strdup(item = (char *)(*env) -> GetStringUTFChars(env, dir, 0));
getcwd(cwd, sizeof(cwd)); getcwd(cwd, sizeof(cwd));
chdir(pwd); chdir(pwd);
(*env) -> ReleaseStringUTFChars(env, dir, item); (*env) -> ReleaseStringUTFChars(env, dir, item);
} }
// Nothing for now // Nothing for now
memset(&inherit, 0, sizeof(inherit)); memset(&inherit, 0, sizeof(inherit));
inherit.flags = SPAWN_SETGROUP; inherit.flags = SPAWN_SETGROUP;
inherit.pgroup = SPAWN_NEWPGROUP; inherit.pgroup = SPAWN_NEWPGROUP;
pid = spawnp(pCommand, 0, NULL, &inherit, pParms, pEnvs); pid = spawnp(pCommand, 0, NULL, &inherit, pParms, pEnvs);
if(dir != 0) // Restore working directory if(dir != 0) // Restore working directory
chdir(cwd); chdir(cwd);
return pid; return pid;
} }
/* /*
* Class: com_qnx_tools_utils_spawner_Spawner * Class: com_qnx_tools_utils_spawner_Spawner
* Method: raise * Method: raise
* Signature: (II)I * Signature: (II)I
*/ */
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_raise JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_raise
(JNIEnv * env, jobject proc, jint pid, jint sig) (JNIEnv * env, jobject proc, jint pid, jint sig)
{ {
return kill(pid, sig); return kill(pid, sig);
} }
/* /*
* Class: com_qnx_tools_utils_spawner_Spawner * Class: com_qnx_tools_utils_spawner_Spawner
* Method: waitFor * Method: waitFor
* Signature: (I)I * Signature: (I)I
*/ */
JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_waitFor JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_waitFor
(JNIEnv * env, jobject proc, jint pid) (JNIEnv * env, jobject proc, jint pid)
{ {
int stat_loc; int stat_loc;
return (waitpid(pid, &stat_loc, WEXITED)); return (waitpid(pid, &stat_loc, WEXITED));
} }
// Utilities // Utilities
void ThrowByName(JNIEnv *env, const char *name, const char *msg) void ThrowByName(JNIEnv *env, const char *name, const char *msg)
{ {
jclass cls = (*env)->FindClass(env, name); jclass cls = (*env)->FindClass(env, name);
if (cls != 0) /* Otherwise an exception has already been thrown */ if (cls != 0) /* Otherwise an exception has already been thrown */
(*env)->ThrowNew(env, cls, msg); (*env)->ThrowNew(env, cls, msg);
/* It's a good practice to clean up the local references. */ /* It's a good practice to clean up the local references. */
(*env)->DeleteLocalRef(env, cls); (*env)->DeleteLocalRef(env, cls);
} }
void * GetJVMProc(char * vmlib, char * procName) void * GetJVMProc(char * vmlib, char * procName)
{ {
if(NULL == vmlib) if(NULL == vmlib)
vmlib = "libj9vm14.so"; vmlib = "libj9vm14.so";
if((NULL == hVM) || (NULL == procName)) if((NULL == hVM) || (NULL == procName))
{ {
if(NULL == (hVM = dlopen(vmlib, 0))) if(NULL == (hVM = dlopen(vmlib, 0)))
return NULL; return NULL;
} }
return dlsym(hVM, procName); return dlsym(hVM, procName);
} }

View file

@ -0,0 +1,8 @@
LIST=VARIANT
ifndef QRECURSE
QRECURSE=recurse.mk
ifdef QCONFIG
QRDIR=$(dir $(QCONFIG))
endif
endif
include $(QRDIR)$(QRECURSE)

View file

@ -0,0 +1 @@
include ../../common.mk

View file

@ -1,4 +0,0 @@
iostream.o
libspawner.so
libspawnerS.a
spawner.o