[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Spawner to throw an exception.
|
Runtime.getRuntime().exec(..) would throw an exception
if the program does not exist or is not an executabe.
Spawner should do the same. pfind() will check for
access() and throw an IOException if file does not
exists or is not an executable.
Index: ChangeLog
===================================================================
RCS file: ChangeLog
diff -N ChangeLog
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ChangeLog 16 Oct 2002 00:54:50 -0000
@@ -0,0 +1,15 @@
+2002-10-15 Alain Magloire
+
+ Runtime.getRuntime().exec(..) would throw an exception
+ if the program does not exist or is not an executabe.
+ Spawner should do the same.
+
+ library/pfind.c (pfind): Check also for fullpath
+ with access() system call.
+
+ library/exec_unix.c (exec0): Always call pfind()
+ to check if the program exists.
+
+ os/linux/x86/libspawner.so: Rebuild.
+
+
\ No newline at end of file
Index: library/exec_unix.c
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.linux/library/exec_unix.c,v
retrieving revision 1.2
diff -u -r1.2 exec_unix.c
--- library/exec_unix.c 26 Sep 2002 19:52:12 -0000 1.2
+++ library/exec_unix.c 16 Oct 2002 00:54:52 -0000
@@ -8,7 +8,7 @@
#include <stdlib.h>
/* from pfind.c */
-char *pfind( char *name );
+extern char *pfind(const char *name);
pid_t
exec0(const char *path, char *const argv[], char *const envp[],
@@ -19,17 +19,13 @@
char *full_path;
/*
- * Handle this error case, we need the full path for execve() below.
+ * 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 (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);
+ full_path = pfind(path);
+ if (full_path == NULL) {
+ fprintf(stderr, "Unable to find full path for \"%s\"\n", (path) ? path : "");
+ return -1;
}
/*
Index: library/pfind.c
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.linux/library/pfind.c,v
retrieving revision 1.2
diff -u -r1.2 pfind.c
--- library/pfind.c 26 Sep 2002 19:52:44 -0000 1.2
+++ library/pfind.c 16 Oct 2002 00:54:52 -0000
@@ -1,69 +1,78 @@
-/*
- * 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];
+
+ /* Sanity check. */
+ if (name == NULL) {
+ fprintf(stderr, "pfind(): Null argument.\n");
+ return NULL;
+ }
+
+ /* For absolute name 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/linux/x86/libspawner.so
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.linux/os/linux/x86/libspawner.so,v
retrieving revision 1.3
diff -u -r1.3 libspawner.so
Binary files /tmp/cvsFmYLE4 and libspawner.so differ