[EMAIL PROTECTED] wrote:
> 
> >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).
> 
> Well, I can give you one guess: the isaexec(1) utility was created
> before the isaexec(3C) library interface.
> 
> One change that would be required to this code is that you call
> basename() and not create a secondary copy "my_basename()".

Fixed. The code now uses |strrchr()| as you suggested.

> (basename lives in libc and not libgen)

Fixed (header usage has been cleaned up).

> And the code would need to be C-style clean...

Fixed. Even fits within the 80 character limit (well, the code now shows
early symptoms of the "squished-into-right-border"-disease... ;-( ) ...
:-)

I also added "-xstrconst" to the Makefile.

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) [EMAIL PROTECTED]
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 7950090
 (;O/ \/ \O;)
Index: src/cmd/isaexec/isaexec.c
===================================================================
--- src/cmd/isaexec/isaexec.c   (revision 176)
+++ src/cmd/isaexec/isaexec.c   (working copy)
@@ -24,16 +24,14 @@
  * Use is subject to license terms.
  */
 
-#pragma ident  "@(#)isaexec.c  1.3     05/06/08 SMI"
+#pragma ident "@(#)isaexec.c 1.4 06/04/01 gisburn"
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <string.h>
-#include <limits.h>
-#include <locale.h>
-#include <sys/types.h>
-#include <sys/systeminfo.h>
+#include <errno.h>
+#include <libintl.h>
+#include <unistd.h>
 
 /*ARGSUSED*/
 int
@@ -41,91 +39,40 @@
 {
        const char *execname;
        const char *fname;
-       char *isalist;
-       ssize_t isalen;
-       char *pathname;
-       ssize_t len;
-       char scratch[1];
-       char *str;
 
-#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);
 
        /*
-        * 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 (1);
+                               gettext("%s: getexecname() failed\n"),
+                               argv[0]);
+               return (EXIT_FAILURE);
        }
 
        /*
-        * Allocate a path name buffer.  The sum of the lengths of the
-        * execname and isalist strings is guaranteed to be big enough.
+        * Get the base name of the executable
         */
-       len = strlen(execname) + isalen;
-       if ((pathname = malloc(len)) == NULL) {
-               (void) fprintf(stderr,
-                   gettext("%s: malloc(%d) failed\n"),
-                   argv[0], (int)len);
-               return (1);
-       }
+       fname = strrchr(execname, '/');
+       fname = (fname != NULL) ? (fname+1) : execname;
 
-       /*
-        * 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);
+       if (isaexec(execname, argv, envp) == -1) {
+               if (errno == ENOENT) {
                        (void) fprintf(stderr,
-                           gettext("%s: execve(\"%s\") failed\n"),
-                           argv[0], pathname);
+                                       gettext("%s: cannot find/execute \"%s\""
+                                               " in ISA subdirectories\n"),
+                                       argv[0], fname);
+                       return (EXIT_FAILURE);
                }
-       } while ((str = strtok(NULL, " ")) != NULL);
+       }
 
        (void) fprintf(stderr,
-           gettext("%s: cannot find/execute \"%s\" in ISA subdirectories\n"),
-           argv[0], fname);
-
-       return (1);
+                       gettext("%s: execve(\"%s\") failed\n"),
+                       argv[0], fname);
+       return (EXIT_FAILURE);
 }
Index: src/cmd/isaexec/Makefile
===================================================================
--- src/cmd/isaexec/Makefile    (revision 176)
+++ src/cmd/isaexec/Makefile    (working copy)
@@ -23,13 +23,15 @@
 # Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
-#ident "@(#)Makefile   1.3     05/06/08 SMI"
+#ident "@(#)Makefile   1.4     06/04/01 gisburn"
 #
 
 PROG= isaexec
 
 include ../Makefile.cmd
 
+CFLAGS += -xstrconst
+
 CFLAGS += $(CCVERBOSE)
 
 .KEEP_STATE:
_______________________________________________
opensolaris-discuss mailing list
opensolaris-discuss@opensolaris.org

Reply via email to