[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Solaris JNI code updated.
|
Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.solaris/ChangeLog,v
retrieving revision 1.2
diff -u -r1.2 ChangeLog
--- ChangeLog 15 Oct 2002 18:13:31 -0000 1.2
+++ ChangeLog 17 Oct 2002 15:50:48 -0000
@@ -1,3 +1,11 @@
+2002-10-16 Alain Magloire
+
+ * library/pfind.c: Reformat to be Unix format.
+ check with access() that the program is an executable.
+
+ * library/exec_unix.c: Reformat to be Unix format.
+ Check with pfind() that the program is an executable.
+
2002-10-15 Alain Magloire
* src/../internal/core/solaris/ProcessList.java:
Index: library/exec_unix.c
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.solaris/library/exec_unix.c,v
retrieving revision 1.2
diff -u -r1.2 exec_unix.c
--- library/exec_unix.c 26 Sep 2002 20:32:37 -0000 1.2
+++ library/exec_unix.c 17 Oct 2002 15:50:48 -0000
@@ -1,145 +1,135 @@
-#include "exec0.h"
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <libgen.h>
-#include <stdlib.h>
-
-/* from pfind.c */
-char *pfind( char *name );
-
-pid_t
-exec0(const char *path, char *const argv[], char *const envp[],
- const char *dirpath, int channels[3])
-{
- int pipe0[2], pipe1[2], pipe2[2];
- pid_t childpid;
- char *full_path;
-
- //
- // Handle this error case, we need the full path for execve() below.
- //
- if (path[0] != '/' && path[0] != '.') {
- full_path = pfind( path );
- //full_path = pathfind (getenv ("PATH"), path, "rx");
- if (full_path == NULL) {
- fprintf( stderr, "Unable to find full path for \"%s\"\n", path );
- return -1;
- }
- } else {
- full_path = strdup(path);
- }
-
- //
- // Make sure we can create our pipes before forking.
- //
- if( channels != NULL )
- {
- if (pipe(pipe0) < 0 || pipe(pipe1) < 0 || pipe(pipe2) < 0) {
- fprintf(stderr, "%s(%d): returning due to error.\n",
- __FUNCTION__, __LINE__);
- free(full_path);
- return -1;
- }
- }
-
- childpid = fork1();
-
- 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 */
- char *ptr;
-
- chdir(dirpath);
-
- if( channels != NULL )
- {
- /* Close the write end of pipe0 */
- if( close(pipe0[1]) == -1 )
- perror( "close(pipe0[1])" );
-
- /* Close the read end of pipe1 */
- if( close(pipe1[0]) == -1 )
- perror( "close(pipe1[0])" );
-
- /* Close the read end of pipe2 */
- if( close(pipe2[0]) == -1 )
- perror( "close(pipe2[0]))" );
-
- /* redirections */
- dup2(pipe0[0], STDIN_FILENO); /* dup stdin */
- dup2(pipe1[1], STDOUT_FILENO); /* dup stdout */
- dup2(pipe2[1], STDERR_FILENO); /* dup stderr */
- }
-
- /* 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 */
-
- char b;
-
- if( channels != NULL )
- {
- /* close the read end of pipe1 */
- if( close(pipe0[0]) == -1 )
- perror( "close(pipe0[0])" );
-
- /* close the write end of pipe2 */
- if( close(pipe1[1]) == -1 )
- perror( "close(pipe1[1])" );
-
- /* close the write end of pipe2 */
- if( close(pipe2[1]) == -1 )
- perror( "close(pipe2[1])" );
-
- channels[0] = pipe0[1]; /* Output Stream. */
- channels[1] = pipe1[0]; /* Input Stream. */
- channels[2] = pipe2[0]; /* Input Stream. */
- }
-
- free(full_path);
- return childpid;
- }
-
- free(full_path);
- return -1; /*NOT REACHED */
-}
-
-
-int wait0(pid_t pid)
-{
- int status;
- int val = -1;
-
- if (pid < 0 || waitpid(pid, &status, 0) < 0)
- return -1;
-
- if (WIFEXITED(status)) {
- val = WEXITSTATUS(status);
- }
-
- return val;
-}
+#include "exec0.h"
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <libgen.h>
+#include <stdlib.h>
+
+/* from pfind.c */
+extern char *pfind(const char *name);
+
+pid_t
+exec0(const char *path, char *const argv[], char *const envp[],
+ const char *dirpath, int channels[3])
+{
+ int pipe0[2], pipe1[2], 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.
+ */
+ full_path = pfind(path);
+ if (full_path == NULL) {
+ fprintf(stderr, "Unable to find full path for \"%s\"\n", path);
+ return -1;
+ }
+
+ /*
+ * Make sure we can create our pipes before forking.
+ */
+ if (channels != NULL) {
+ if (pipe(pipe0) < 0 || pipe(pipe1) < 0 || pipe(pipe2) < 0) {
+ fprintf(stderr, "%s(%d): returning due to error.\n",
+ __FUNCTION__, __LINE__);
+ free(full_path);
+ return -1;
+ }
+ }
+
+ childpid = fork1();
+
+ 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 */
+ char *ptr;
+
+ chdir(dirpath);
+
+ if (channels != NULL) {
+ /* Close the write end of pipe0 */
+ if (close(pipe0[1]) == -1)
+ perror("close(pipe0[1])");
+
+ /* Close the read end of pipe1 */
+ if (close(pipe1[0]) == -1)
+ perror("close(pipe1[0])");
+
+ /* Close the read end of pipe2 */
+ if (close(pipe2[0]) == -1)
+ perror("close(pipe2[0]))");
+
+ /* redirections */
+ dup2(pipe0[0], STDIN_FILENO); /* dup stdin */
+ dup2(pipe1[1], STDOUT_FILENO); /* dup stdout */
+ dup2(pipe2[1], STDERR_FILENO); /* dup stderr */
+ }
+
+ /* 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 */
+
+ char b;
+
+ if (channels != NULL) {
+ /* close the read end of pipe1 */
+ if (close(pipe0[0]) == -1)
+ perror("close(pipe0[0])");
+
+ /* close the write end of pipe2 */
+ if (close(pipe1[1]) == -1)
+ perror("close(pipe1[1])");
+
+ /* close the write end of pipe2 */
+ if (close(pipe2[1]) == -1)
+ perror("close(pipe2[1])");
+
+ channels[0] = pipe0[1]; /* Output Stream. */
+ channels[1] = pipe1[0]; /* Input Stream. */
+ channels[2] = pipe2[0]; /* Input Stream. */
+ }
+
+ free(full_path);
+ return childpid;
+ }
+
+ free(full_path);
+ return -1; /*NOT REACHED */
+}
+
+
+int wait0(pid_t pid)
+{
+ int status;
+ int val = -1;
+
+ if (pid < 0 || waitpid(pid, &status, 0) < 0)
+ return -1;
+
+ if (WIFEXITED(status)) {
+ val = WEXITSTATUS(status);
+ }
+
+ return val;
+}
Index: library/pfind.c
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.solaris/library/pfind.c,v
retrieving revision 1.1
diff -u -r1.1 pfind.c
--- library/pfind.c 3 Sep 2002 16:15:34 -0000 1.1
+++ library/pfind.c 17 Oct 2002 15:50:48 -0000
@@ -1,74 +1,76 @@
-/*
- * pfind.c - Search for a binary in $PATH.
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-
-#ifndef PATH_MAX
-#define PATH_MAX 1024
-#endif
-
-
-char *pfind( const char *name )
-{
- char *tok;
- char *sp;
- char *path = getenv( "PATH" );
- char FullPath[PATH_MAX+1];
-
- if( name == NULL )
- {
- fprintf( stderr, "pfind(): Null argument.\n" );
- return NULL;
- }
-
- if( path == NULL || strlen( path ) <= 0 )
- {
- fprintf( stderr, "Unable to get $PATH.\n" );
- return NULL;
- }
-
- // The value return by getenv() is readonly */
- path = strdup( path );
-
- tok = strtok_r( path, ":", &sp );
- while( tok != NULL )
- {
- //strcpy( FullPath, tok );
- //strcat( FullPath, "/" );
- //strcat( FullPath, name );
- snprintf(FullPath, sizeof(FullPath) - 1, "%s/%s", tok, name);
-
- if( access( FullPath, X_OK | R_OK ) == 0 )
- {
- free( path );
- return strdup(FullPath);
- }
-
- tok = strtok_r( NULL, ":", &sp );
- }
-
- free( path );
- return NULL;
-}
-
-#ifdef BUILD_WITH_MAIN
-int main( int argc, char **argv )
-{
- int i;
- char *fullpath;
-
- for( i=1; i<argc; i++ )
- {
- fullpath = pfind( argv[i] );
- if( fullpath == NULL )
- printf( "Unable to find %s in $PATH.\n", argv[i] );
- else
- printf( "Found %s @ %s.\n", argv[i], fullpath );
- }
-}
-#endif
+/*
+ * pfind.c - Search for a binary in $PATH.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+
+#ifndef PATH_MAX
+#define PATH_MAX 1024
+#endif
+
+
+char *pfind(const char *name)
+{
+ char *tok;
+ char *sp;
+ char *path;
+ char fullpath[PATH_MAX+1];
+
+ if (name == NULL) {
+ fprintf(stderr, "pfind(): Null argument.\n");
+ return NULL;
+ }
+
+ /* For absolute namer or name with a path, check if it is an executable. */
+ if (name[0] == '/' || name[0] == '.') {
+ if (access(name, X_OK | R_OK) == 0) {
+ return strdup(name);
+ }
+ return NULL;
+ }
+
+ /* Search in the PATH environment. */
+ path = getenv("PATH");
+ if (path == NULL || strlen(path) <= 0) {
+ fprintf(stderr, "Unable to get $PATH.\n");
+ return NULL;
+ }
+
+ // The value return by getenv() is readonly */
+ path = strdup(path);
+
+ tok = strtok_r(path, ":", &sp);
+ while (tok != NULL) {
+ snprintf(fullpath, sizeof(fullpath) - 1, "%s/%s", tok, name);
+
+ if (access(fullpath, X_OK | R_OK) == 0) {
+ free(path);
+ return strdup(fullpath);
+ }
+
+ tok = strtok_r(NULL, ":", &sp);
+ }
+
+ free(path);
+ return NULL;
+}
+
+#ifdef BUILD_WITH_MAIN
+int main(int argc, char **argv)
+{
+ int i;
+ char *fullpath;
+
+ for (i = 1; i<argc; i++) {
+ fullpath = pfind(argv[i]);
+ if (fullpath == NULL)
+ printf("Unable to find %s in $PATH.\n", argv[i]);
+ else
+ printf( "Found %s @ %s.\n", argv[i], fullpath );
+ }
+}
+#endif
Index: os/solaris/sparc/libspawner.so
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.solaris/os/solaris/sparc/libspawner.so,v
retrieving revision 1.3
diff -u -r1.3 libspawner.so
Binary files /tmp/cvs0GurO0 and libspawner.so differ