--- ./lib/xalflaunch.c Sun Apr 22 10:37:02 2001 +++ ../xalf-0.12/./lib/xalflaunch.c Sat Sep 29 14:12:27 2001 @@ -10,7 +10,6 @@ * This library is hopefully threadsafe. Please report bugs. * */ -#undef DEBUG /* Uncomment below for debugging */ /* #define DEBUG */ @@ -33,11 +32,27 @@ #include #define PID_ENV_NAME "XALF_LAUNCH_PID" -#define SAVED_PRELOAD_NAME "XALF_SAVED_PRELOAD" +#ifdef __sgi +#define NUM_ABI 3 +static char *saved_preload_name[NUM_ABI] = { "XALF_SAVED_PRELOAD", + "XALF_SAVED_PRELOADN32", + "XALF_SAVED_PRELOAD64" }; +static char *saved_preload_set[NUM_ABI] = { "XALF_SAVED_PRELOAD=", + "XALF_SAVED_PRELOADN32=", + "XALF_SAVED_PRELOAD64=" }; +static char *ld_preload[NUM_ABI] = { "_RLD_LIST", "_RLDN32_LIST", "_RLD64_LIST" }; +static char *ld_preload_set[NUM_ABI] = { "_RLD_LIST=", "_RLDN32_LIST=", "_RLD64_LIST=" }; +#else +#define NUM_ABI 1 +static char *saved_preload_name[NUM_ABI] = { "XALF_SAVED_PRELOAD" }; +static char *saved_preload_set[NUM_ABI] = { "XALF_SAVED_PRELOAD=" }; +static char *ld_preload[NUM_ABI] = { "LD_PRELOAD" }; +static char *ld_preload_set[NUM_ABI] = { "LD_PRELOAD=" }; +#endif /* Prototypes */ static void restore_env(); -static long int launch_pid = 0; +static pid_t launch_pid = 0; /* Init function. I wish there were some better way of doing this... */ @@ -61,9 +76,9 @@ pid_string = getenv (PID_ENV_NAME); if (pid_string) launch_pid = atol (pid_string); - DPRINTF ((stderr, "libxalflaunch: launch_pid is %ld\n", launch_pid)); + DPRINTF ((stderr, "libxalflaunch: launch_pid is %ld\n", (long)launch_pid)); - if (launch_pid == -1) + if (launch_pid == (pid_t)-1) { /* The xalf wrapper was only testing for our existence. */ DPRINTF ((stderr, "libxalflaunch: Exiting immediately from _init()\n")); @@ -101,7 +116,7 @@ /* we don't want to kill neither 0 nor init */ if (launch_pid > 1) { - DPRINTF ((stderr, "libxalflaunch: Sending signal to process %d\n", launch_pid)); + DPRINTF ((stderr, "libxalflaunch: Sending signal to process %ld\n", (long)launch_pid)); kill (launch_pid, SIGUSR1); launch_pid = 0; } @@ -151,7 +166,7 @@ /* we don't want to kill neither 0 nor init */ if (launch_pid > 1) { - DPRINTF ((stderr, "libxalflaunch: Sending signal to process %d\n", launch_pid)); + DPRINTF ((stderr, "libxalflaunch: Sending signal to process %ld\n", (long)launch_pid)); kill (launch_pid, SIGUSR1); launch_pid = 0; } @@ -191,17 +206,17 @@ #ifdef HAVE_UNSETENV - #define PRELOAD_UNSETTER unsetenv ("LD_PRELOAD"); - #define SAVED_PRELOAD_UNSETTER unsetenv (SAVED_PRELOAD_NAME); + #define PRELOAD_UNSETTER unsetenv (ld_preload[i]); + #define SAVED_PRELOAD_UNSETTER unsetenv (saved_preload_name[i]); #define PID_UNSETTER unsetenv (PID_ENV_NAME); #else #define PRELOAD_UNSETTER \ - if (putenv ("LD_PRELOAD=")) \ - fprintf (stderr, "libxalflaunch: unsetting LD_PRELOAD failed\n"); + if (putenv (ld_preload_set[i])) \ + fprintf (stderr, "libxalflaunch: unsetting %s failed\n", ld_preload[i]); #define SAVED_PRELOAD_UNSETTER \ - if (putenv (SAVED_PRELOAD_NAME"=")) \ - fprintf (stderr, "libxalflaunch: unsetting "SAVED_PRELOAD_NAME" failed\n"); + if (putenv (saved_preload_set[i])) \ + fprintf (stderr, "libxalflaunch: unsetting %s failed\n", saved_preload_name[i]); #define PID_UNSETTER \ if (putenv (PID_ENV_NAME"=")) \ fprintf (stderr, "libxalflaunch: unsetting "PID_ENV_NAME" failed\n"); @@ -208,44 +223,46 @@ #endif /* HAVE_UNSETENV */ -/* Unset or restore LD_PRELOAD +/* Unset or restore LD_PRELOAD/_RLD_LIST and unset PID_ENV_NAME */ static void restore_env() { char *saved_preload = NULL; char *new_preload = NULL; + int i; - saved_preload = getenv (SAVED_PRELOAD_NAME); + for (i = 0; i < NUM_ABI; i++) { + saved_preload = getenv (saved_preload_name[i]); - if (saved_preload) + if (saved_preload) /* LD_PRELOAD was set before Xalf was called. Restore it. */ { - DPRINTF ((stderr, "libxalflaunch: Restoring LD_PRELOAD=%s\n", saved_preload)); - /* LD_PRELOAD= is 11 characters, and one more for \0 */ - new_preload = malloc (strlen (saved_preload) + 12); - if (new_preload == NULL) - /* Malloc failed. */ - { - fprintf (stderr, "libxalflaunch: malloc failed\n"); - } - else - { - strcpy (new_preload, "LD_PRELOAD="); - strcat (new_preload, saved_preload); - /* Note: saved_preload+11 becomes a part of the new environment, - and should not be free:d. */ - if (putenv (new_preload)) - fprintf (stderr, "libxalflaunch: putenv failed\n"); - } + DPRINTF ((stderr, "libxalflaunch: Restoring %s%s\n", ld_preload_set[i], saved_preload)); + new_preload = malloc (strlen (saved_preload) + strlen(ld_preload_set[i]) + 1); + if (new_preload == NULL) + /* Malloc failed. */ + { + fprintf (stderr, "libxalflaunch: malloc failed\n"); + } + else + { + strcpy (new_preload, ld_preload_set[i]); + strcat (new_preload, saved_preload); + /* Note: new_preload becomes a part of the new environment, + and should not be free:d. */ + if (putenv (new_preload)) + fprintf (stderr, "libxalflaunch: putenv failed\n"); + } - /* Unset the saved LD_PRELOAD. */ - SAVED_PRELOAD_UNSETTER; + /* Unset the saved LD_PRELOAD. */ + SAVED_PRELOAD_UNSETTER; } - else + else { - DPRINTF ((stderr, "libxalflaunch: Unsetting LD_PRELOAD\n")); - PRELOAD_UNSETTER; + DPRINTF ((stderr, "libxalflaunch: Unsetting LD_PRELOAD\n")); + PRELOAD_UNSETTER; } + } /* Unset PID_ENV_NAME */ PID_UNSETTER; --- ./src/xalf.c Sun Apr 22 08:57:08 2001 +++ ../xalf-0.12/./src/xalf.c Sat Sep 29 14:28:37 2001 @@ -53,7 +53,6 @@ #include "sp7.xpm" #include "sp8.xpm" -#undef DEBUG /* Uncomment below for debugging */ /* #define DEBUG */ @@ -64,8 +63,26 @@ #endif #define PID_ENV_NAME "XALF_LAUNCH_PID" -#define SAVED_PRELOAD_NAME "XALF_SAVED_PRELOAD" -#define PRELOAD_LIBRARY LIBDIR"/libxalflaunch.so.0" +#ifdef __sgi +#define MULTI_PRELOAD +#define NUM_ABI 3 +#define MY_ABI (_MIPS_SIM - 1) +static char *saved_preload_name[NUM_ABI] = { "XALF_SAVED_PRELOAD", + "XALF_SAVED_PRELOADN32", + "XALF_SAVED_PRELOAD64" }; +static char *preload_library[NUM_ABI] = { PREFIX"/lib/libxalflaunch.so.1", + PREFIX"/lib32/libxalflaunch.so.1", + PREFIX"/lib64/libxalflaunch.so.1" }; +static char *ld_preload[NUM_ABI] = { "_RLD_LIST", "_RLDN32_LIST", "_RLD64_LIST" }; +#define DEFAULT_PRELOAD ":DEFAULT" +#else +#define NUM_ABI 1 +#define MY_ABI 0 +static char *saved_preload_name[NUM_ABI] = { "XALF_SAVED_PRELOAD" }; +static char *preload_library[NUM_ABI] = { LIBDIR"/libxalflaunch.so.0" }; +static char *ld_preload[NUM_ABI] = { "LD_PRELOAD" }; +#define DEFAULT_PRELOAD "" +#endif #define USAGE "\ Usage: %s [options] command\n\ options:\n\ @@ -246,23 +263,24 @@ return 0; } - /* Check if we have to force --mappingmode */ static int forced_mappingmode(char **argv) { int mappingmode_opt = FALSE; + int i; #ifndef MULTI_PRELOAD + for (i = 0; i < NUM_ABI; i++) { char *preload_env; - /* If LD_PRELOAD is alread set and this system does not support + /* If LD_PRELOAD is already set and this system does not support multiple libs in LD_PRELOAD, use use --mappingmode. */ - preload_env = getenv("LD_PRELOAD"); + preload_env = getenv(ld_preload[i]); if ( (preload_env != NULL) && (*preload_env != '\0') ) { fprintf (stderr, - "%s: LD_PRELOAD is already set. Using --mappingmode\n", - programname); + "%s: %s is already set. Using --mappingmode\n", + ld_preload[i], programname); mappingmode_opt = TRUE; } } @@ -269,23 +287,36 @@ #endif /* Check if preload library is available */ + for (i = 0; i < NUM_ABI; i++) { - void *handle = NULL; - /* Set PID_ENV_NAME to -1. libxalflaunch.so knows about this case - and refrains from doing anything (like unsetting an - original LD_PRELOAD) */ - putenv (PID_ENV_NAME"=-1"); - handle = dlopen (PRELOAD_LIBRARY, RTLD_LAZY); - if (!handle) - { + if (i == MY_ABI) { + void *handle = NULL; + /* Set PID_ENV_NAME to -1. libxalflaunch.so knows about this case + and refrains from doing anything (like unsetting an + original LD_PRELOAD) */ + putenv (PID_ENV_NAME"=-1"); + + handle = dlopen (preload_library[i], RTLD_LAZY); + if (!handle) { fprintf (stderr, - "%s: preload library not found. Using --mappingmode\n", - programname); + "%s: %s not found. Using --mappingmode\n", + programname, preload_library[i]); mappingmode_opt = TRUE; } - /* Note: We do not close */ - + /* Note: We do not close dlopen'd libraries */ + } else { + /* We cannot dlopen() libraries for other ABI. */ + FILE *handle = fopen (preload_library[i], "r"); + if (!handle) { + fprintf (stderr, + "%s: warning: %s not found. Use --mappingmode if this fails.\n", + programname, preload_library[i]); + } else { + fclose(handle); + } + } } + /* Check if program is setuid or setgid */ { gchar *abs_name; @@ -334,28 +365,29 @@ return mappingmode_opt; } - static int launch_application (int mappingmode_opt, char **argv) { - int pid; - char *preload_string = NULL; - char *saved_preload = NULL; - char *saved_preload_env = NULL; + pid_t pid; + int i; + char *preload_string[NUM_ABI] = { NULL }; + char *saved_preload[NUM_ABI] = { NULL }; + char *saved_preload_env[NUM_ABI] = { NULL }; /* Set up preload_string */ + for (i = 0; i < NUM_ABI; i++) { #ifdef MULTI_PRELOAD - saved_preload = getenv("LD_PRELOAD"); - if (saved_preload != NULL) - { - preload_string = g_strconcat ("LD_PRELOAD=", saved_preload, ":", PRELOAD_LIBRARY, NULL); - saved_preload_env = g_strconcat (SAVED_PRELOAD_NAME"=", saved_preload, NULL); + saved_preload[i] = getenv(ld_preload[i]); + if (saved_preload[i] != NULL) { + preload_string[i] = g_strconcat (ld_preload[i], "=", saved_preload[i], ":", preload_library[i], NULL); + saved_preload_env[i] = g_strconcat (saved_preload_name[i], "=", saved_preload[i], NULL); } - else - preload_string = g_strconcat ("LD_PRELOAD=", PRELOAD_LIBRARY, NULL); + else + preload_string[i] = g_strconcat (ld_preload[i], "=", preload_library[i], DEFAULT_PRELOAD, NULL); #else - preload_string = g_strconcat ("LD_PRELOAD=", PRELOAD_LIBRARY, NULL); + preload_string[i] = g_strconcat (ld_preload[i], "=", preload_library[i], DEFAULT_PRELOAD, NULL); #endif /* MULTI_PRELOAD */ + } /* Make sure that the file descriptor is not passed to the client. */ if (fcntl (ConnectionNumber (dpy), F_SETFD, 1L) == -1) { @@ -379,9 +411,11 @@ case 0: if (!mappingmode_opt) { - putenv (preload_string); - if (saved_preload_env) - putenv (saved_preload_env); + for (i = 0; i < NUM_ABI; i++) { + putenv (preload_string[i]); + if (saved_preload_env[i]) + putenv (saved_preload_env[i]); + } putenv (pid_string); } execvp (argv[optind], argv+optind); @@ -392,7 +426,6 @@ } return 0; } - int main (int argc, char **argv) --- ./src/Makefile.am Sun Apr 22 10:03:48 2001 +++ ../xalf-0.12/./src/Makefile.am Sat Sep 29 01:30:05 2001 @@ -10,7 +10,7 @@ INCLUDES = @GTK_CFLAGS@ -CFLAGS = -DLIBDIR=\""$(libdir)"\" +CFLAGS = -DLIBDIR=\""$(libdir)"\" -DPREFIX=\""$(prefix)"\" EXTRA_DIST = hourglass.xpm splash.xpm hgcursor.h hgcursor_mask.h getopt.h \ --- ./src/Makefile.in Sun Apr 22 10:57:01 2001 +++ ../xalf-0.12/./src/Makefile.in Sat Sep 29 01:30:10 2001 @@ -86,7 +86,7 @@ INCLUDES = @GTK_CFLAGS@ -CFLAGS = -DLIBDIR=\""$(libdir)"\" +CFLAGS = -DLIBDIR=\""$(libdir)"\" -DPREFIX=\""$(prefix)"\" EXTRA_DIST = hourglass.xpm splash.xpm hgcursor.h hgcursor_mask.h getopt.h sp1.xpm sp2.xpm sp3.xpm sp4.xpm sp5.xpm sp6.xpm sp7.xpm sp8.xpm sp9.xpm --- ./src/xalfoff.c Sun Apr 22 10:12:22 2001 +++ ../xalf-0.12/./src/xalfoff.c Sat Sep 29 01:08:37 2001 @@ -9,7 +9,6 @@ #include #include -#undef DEBUG /* Uncomment below for debugging */ /* #define DEBUG */