- bytes_read = getline (&line, &len, process);
-
- status = pclose (process);
- if (! WIFEXITED (status))
- return NULL;
-
- if (WEXITSTATUS (status))
- return NULL;
-
- if (bytes_read == -1)
- return NULL;
-
- if (bytes_read) {
- if (line[strlen(line)-1] == '\n')
- line[strlen(line)-1] = '\0';
- return line;
- } else {
- return NULL;
- }
-}
-
-
-/* Look for "wrapper" library next to currently executing binary.
- *
- * If "wrapper" is an absolute path, return it directly.
- *
- * Otherwise, ("wrapper" is relative), look for an existing file named
- * "wrapper" in the same directory as the currently executing binary,
- * (as determined by /proc/self/exe). If that file exists, return its
- * path.
- *
- * Otherwise, return the original, relative "wrapper".
- */
-static const char *
-resolve_wrapper_path (void *ctx, const char *wrapper)
-{
- char *bin_path, *lib_path;
-
- if (*wrapper == '/')
- return wrapper;
-
- bin_path = get_bin_name (ctx);
-
- chop_trailing_path_component (bin_path);
-
- lib_path = talloc_asprintf (ctx, "%s/%s", bin_path, wrapper);
-
- talloc_free (bin_path);
-
- if (exists (lib_path))
- return lib_path;
-
- talloc_free (lib_path);
-
- return wrapper;
-}
-
-/* Return path to directory containing Glaze wrapper's libGL.so.1
- * suitable for use in LD_PRELOAD or LD_LIBRARY_PATH. Note that the
- * path returned may not be a full path to the directory but may end
- * with "$LIB" which will be expanded by the Linux dynamic linker to
- * an architecture specific string (such as "lib/i386-linux-gnu" or
- * "lib/x86_64-linux-gnu"). */
-static const char *
-find_glaze_libgl_dir (void)
-{
- return CONFIG_LIBDIR "/glaze/$LIB";
-}
-
-void
-glaze_execute (int argc, char *argv[], const char *wrapper)
-{
- void *ctx = talloc_new (NULL);
- int i;
-
- /* Set GLAZE_WRAPPER to absolute path of wrapper library */
- if (wrapper == NULL || *wrapper == '\0') {
- fprintf (stderr, "Error: glaze_execute called with empty wrapper library.\n");
- return;
- }
-
- wrapper = resolve_wrapper_path (ctx, wrapper);
-
- setenv ("GLAZE_WRAPPER", wrapper, 1);
-
- /* Ensure GLAZE_LIBGL is set. If not, set GLAZE_LIBGL_32_AUTO
- * and GLAZE_LIBGL_64_AUTO