Re: [AD] [PATCH] Solaris Fixes and dev notes

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On 6/5/05, Evert Glebbeek <eglebbk@xxxxxxxxxx> wrote:
> On Sunday 05 June 2005 19:26, Shawn Walker wrote:
> > A further note I forgot: the data member allegro was trying to access is
> > definitely a valid part of the struct, it was just NULL in this
> particular
> > case. Why, I can't say. Maybe under another set of circumstances the
> struct
> > works just fine. However, I'm going to bet that getexecname() will be far
> > more reliable and appears to have been in Solaris for a long time now
> (since
> > 1997).
> 
> Proposed patch attached. Please check if it works as it should. The
> configure check works by checking if getexecname() is present in libc.
> Allegro already has a function for finding an executable, either in the
> current directory or in the path if the path is relative, so I ended up
> using that one instead.

There were a few small problems in the patch, I've corrected them, and
made one more change to make this even more robust. See attached
patch.

Thanks,
-- 
Shawn Walker, Software and Systems Analyst
binarycrusader@xxxxxxxxxx - http://binarycrusader.blogspot.com/
Index: aclocal.m4
===================================================================
RCS file: /cvsroot/alleg/allegro/aclocal.m4,v
retrieving revision 1.77
diff -u -u -r1.77 aclocal.m4
--- aclocal.m4	24 May 2005 14:58:27 -0000	1.77
+++ aclocal.m4	6 Jun 2005 02:27:15 -0000
@@ -218,6 +218,19 @@
 AC_MSG_RESULT($allegro_procfs_argcv)
 
 dnl
+dnl Test for getexecname() on Solaris
+dnl
+dnl Variables:
+dnl  allegro_sys_getexecname=(yes|no)
+dnl
+AC_MSG_CHECKING(for getexecname)
+AC_DEFUN(ALLEGRO_SYS_GETEXECNAME,
+   [AC_CHECK_LIB(c, getexecname,
+      [allegro_sys_getexecname=yes], [allegro_sys_getexecname=no])]
+)
+AC_MSG_RESULT($allegro_sys_getexecname)
+
+dnl
 dnl Test for X-Windows support.
 dnl
 dnl Variables:
Index: configure.in
===================================================================
RCS file: /cvsroot/alleg/allegro/configure.in,v
retrieving revision 1.90
diff -u -u -r1.90 configure.in
--- configure.in	24 May 2005 14:58:27 -0000	1.90
+++ configure.in	6 Jun 2005 02:27:15 -0000
@@ -448,6 +448,14 @@
    fi
 fi
 
+dnl Test for Solaris like getexecname().
+ALLEGRO_SYS_GETEXECNAME
+if test "$allegro_sys_getexecname" = yes; then
+   AC_DEFINE(ALLEGRO_HAVE_GETEXECNAME,1,
+      [Define to 1 if you have getexecname])
+fi
+
+
 dnl Test for X-Windows support.
 ALLEGRO_ACTEST_SUPPORT_XWINDOWS
 if test "$allegro_support_xwindows" = yes; then
Index: src/unix/usystem.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/unix/usystem.c,v
retrieving revision 1.34
diff -u -u -r1.34 usystem.c
--- src/unix/usystem.c	12 Mar 2005 06:29:06 -0000	1.34
+++ src/unix/usystem.c	6 Jun 2005 02:38:22 -0000
@@ -319,6 +319,8 @@
    #ifdef ALLEGRO_HAVE_SV_PROCFS
       struct prpsinfo psinfo;
       int fd;
+   #endif
+   #if defined ALLEGRO_HAVE_SV_PROCFS || defined ALLEGRO_SYS_GETEXECNAME
       char *s;
    #endif
    char linkname[1024];
@@ -327,11 +329,26 @@
    FILE *pipe;
    pid_t pid;
    int len;
+   
+   #ifdef ALLEGRO_HAVE_GETEXECNAME
+      s = getexecname();
+      if (s) {
+         if (s[0] == '/') {   /* Absolute path */
+            do_uconvert (s, U_ASCII, output, U_CURRENT, size);
+            return;
+         }
+         else {               /* Not an absolute path */
+            if (_find_executable_file(s, output, size))
+               return;
+         }
+      }
+      s = NULL;
+   #endif
 
    /* We need the PID in order to query procfs */
    pid = getpid();
 
-   /* First try a Linux-like procfs */   
+   /* Try a Linux-like procfs */   
    /* get symolic link to executable from proc fs */
    sprintf (linkname, "/proc/%d/exe", pid);
    if (stat (linkname, &finfo) == 0) {
@@ -352,22 +369,22 @@
       close(fd);
    
       /* Use argv[0] directly if we can */
-      #ifdef ALLEGRO_HAVE_PROCFS_ARGCV
+      if (psinfo.pr_argv && psinfo.pr_argc) {
          if (_find_executable_file(psinfo.pr_argv[0], output, size))
             return;
-      #else
+      } else {
          /* Emulate it */
          /* We use the pr_psargs field to find argv[0]
-         * This is better than using the pr_fname field because we need the
-         *  additional path information that may be present in argv[0]
-         */
+          * This is better than using the pr_fname field because we need the
+          *  additional path information that may be present in argv[0]
+          */
          
          /* Skip other args */
          s = strchr(psinfo.pr_psargs, ' ');
          if (s) s[0] = '\0';
          if (_find_executable_file(psinfo.pr_psargs, output, size))
             return;
-      #endif
+      }
 
       /* Try the pr_fname just for completeness' sake if argv[0] fails */
       if (_find_executable_file(psinfo.pr_fname, output, size))


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/