Hi!

----

Few minutes ago the issue came up in irc://irc.freenode.org/#opensolaris
why isaexec(1) does not use the isaexec(3C) function.
Attached is a patch
("solaris_usr_lib_isaexec_uses_isaexec_3c_function.diff.txt") which
fixes the problem.

* Benefits of the patch:
- /usr/lib/isaexec will be smaller and slightly faster
- Replacing isaexec(3C) using LD_PRELOAD&co. will now affect
/usr/lib/isaexec , too (=consistency) ...

* Known problems:
- Patch is more or less untested
- isaexec(1) is slightly more verbose (one additional error message) -
the question is what's better: Reduction in binary size or more verbose
error messages. If the second option is selected then I propose to add a
comment to the isaexec(1) source code why it is kept seperate from
isaexec(3C).

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) [EMAIL PROTECTED]
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 7950090
 (;O/ \/ \O;)
Index: isaexec.c
===================================================================
--- isaexec.c   (revision 168)
+++ isaexec.c   (working copy)
@@ -24,10 +24,12 @@
  * Use is subject to license terms.
  */
 
-#pragma ident  "@(#)isaexec.c  1.3     05/06/08 SMI"
+#pragma ident        "@(#)isaexec.c        1.3        05/06/08 SMI"
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <libgen.h>
+#include <errno.h>
 #include <unistd.h>
 #include <string.h>
 #include <limits.h>
@@ -35,97 +37,67 @@
 #include <sys/types.h>
 #include <sys/systeminfo.h>
 
+
+/* Stolen from on/usr/src/lib/libc/port/gen/basename.c
+ * and modified to avoid skipping trailing '/'s (which is useless here
+ * since they will never occur)
+ */
+static
+const char *my_basename(const char *s)
+{
+        const char *p;
+
+        if (!s || !*s)                       /* zero or empty argument */
+                return (".");
+
+        p = s + strlen(s);
+
+        if (p == s && *p == '\0')            /* all slashes */
+                return ("/");
+
+        while (p != s)
+                if (*--p == '/')
+                        return (++p);
+
+        return (p);
+}
+
 /*ARGSUSED*/
 int
 main(int argc, char **argv, char **envp)
 {
-       const char *execname;
-       const char *fname;
-       char *isalist;
-       ssize_t isalen;
-       char *pathname;
-       ssize_t len;
-       char scratch[1];
-       char *str;
+        const char *execname;
+        const char *fname;
 
-#if !defined(TEXT_DOMAIN)              /* Should be defined by cc -D */
-#define        TEXT_DOMAIN     "SYS_TEST"      /* Use this only if it wasn't */
+#if !defined(TEXT_DOMAIN)          /* Should be defined by cc -D */
+#error ERR_TEXT_DOMAIN_NOT_DEFINED_KOMODO_DRAGONS_WILL_BITE_YOU
 #endif
-       (void) setlocale(LC_ALL, "");
-       (void) textdomain(TEXT_DOMAIN);
+        (void) textdomain(TEXT_DOMAIN);
 
-       /*
-        * Get the isa list.
-        */
-       if ((isalen = sysinfo(SI_ISALIST, scratch, 1)) == -1 ||
-           (isalist = malloc(isalen)) == NULL ||
-           sysinfo(SI_ISALIST, isalist, isalen) == -1) {
-               (void) fprintf(stderr,
-                   gettext("%s: cannot find the ISA list\n"),
-                   argv[0]);
-               return (1);
-       }
+        /*
+         * Get the exec name.
+         */
+        if ((execname = getexecname()) == NULL) {
+                (void) fprintf(stderr,
+                               gettext("%s: getexecname() failed\n"),
+                               argv[0]);
+                return EXIT_FAILURE;
+        }
 
-       /*
-        * Get the exec name.
-        */
-       if ((execname = getexecname()) == NULL) {
-               (void) fprintf(stderr,
-                   gettext("%s: getexecname() failed\n"),
-                   argv[0]);
-               return (1);
-       }
+        fname = my_basename(execname);
 
-       /*
-        * Allocate a path name buffer.  The sum of the lengths of the
-        * execname and isalist strings is guaranteed to be big enough.
-        */
-       len = strlen(execname) + isalen;
-       if ((pathname = malloc(len)) == NULL) {
-               (void) fprintf(stderr,
-                   gettext("%s: malloc(%d) failed\n"),
-                   argv[0], (int)len);
-               return (1);
-       }
+        if (isaexec(execname, argv, envp) == -1) {
+                if(errno == ENOENT) {
+                        (void) fprintf(stderr,
+                                       gettext("%s: cannot find/execute \"%s\" 
in ISA subdirectories\n"),
+                                       argv[0], fname);
+                        return EXIT_FAILURE;
+                }
+        }
 
-       /*
-        * Break the exec name into directory and file name components.
-        */
-       (void) strcpy(pathname, execname);
-       if ((str = strrchr(pathname, '/')) != NULL) {
-               *++str = '\0';
-               fname = execname + (str - pathname);
-       } else {
-               fname = execname;
-               *pathname = '\0';
-       }
-       len = strlen(pathname);
-
-       /*
-        * For each name in the isa list, look for an executable file
-        * with the given file name in the corresponding subdirectory.
-        */
-       str = strtok(isalist, " ");
-       do {
-               (void) strcpy(pathname+len, str);
-               (void) strcat(pathname+len, "/");
-               (void) strcat(pathname+len, fname);
-               if (access(pathname, X_OK) == 0) {
-                       /*
-                        * File exists and is marked executable.  Attempt
-                        * to execute the file from the subdirectory,
-                        * using the user-supplied argv and envp.
-                        */
-                       (void) execve(pathname, argv, envp);
-                       (void) fprintf(stderr,
-                           gettext("%s: execve(\"%s\") failed\n"),
-                           argv[0], pathname);
-               }
-       } while ((str = strtok(NULL, " ")) != NULL);
-
-       (void) fprintf(stderr,
-           gettext("%s: cannot find/execute \"%s\" in ISA subdirectories\n"),
-           argv[0], fname);
-
-       return (1);
+        (void) fprintf(stderr,
+                       gettext("%s: execve(\"%s\") failed\n"),
+                       argv[0], fname);
+        return EXIT_FAILURE;
 }
+
_______________________________________________
opensolaris-discuss mailing list
opensolaris-discuss@opensolaris.org

Reply via email to