-chop_trailing_path_component (char *path)
-{
- char *slash;
-
- slash = strrchr (path, '/');
-
- if (slash == NULL)
- return;
-
- if (slash == path)
- return;
-
- *slash = '\0';
-}
-
-/* Find the absolute path of the currently executing binary.
- *
- * Returns: a string talloc'ed to 'ctx'
- */
-static char *
-get_bin_name (void *ctx)
-{
- const char *link = "/proc/self/exe";
- char *name;
-
- /* Yes, PATH_MAX is cheesy. I would have preferred to have
- * used lstat and read the resulting st_size, but everytime I
- * did that with /proc/self/exe I got a value of 0, (whereas
- * with a "real" symbolic link I make myself I get the length
- * of the filename being linked to). Go figure. */
- int name_len = PATH_MAX + 1;
-
- name = talloc_size (ctx, name_len);
- if (name == NULL) {
- fprintf (stderr, "Out of memory.\n");
- exit (1);
- }
-
- name_len = readlink (link, name, name_len - 1);
- if (name_len < 0) {
- fprintf (stderr, "Failed to readlink %s: %s\n", link,
- strerror (errno));
- exit (1);
- }
-
- name[name_len] = '\0';
-
- return name;
-}
-
-/* Does path exist? */
-static int
-exists (const char *path)
-{
- struct stat st;
- int err;
-
- err = stat (path, &st);
-
- /* Failed to stat. It either doesn't exist, or might as well not. */
- if (err == -1)
- return 0;
-
- return 1;
-}
-
-/* Execute "program" in a pipe, reads its first line of output on
- * stdout, and returns that as a string (discarding any further
- * output).
- *
- * Returns NULL if the program failed to execute for any reason.
- *
- * NOTE: The caller should free() the returned string when done with
- * it.
- */
-static char *
-read_process_output_one_line (const char *program)
-{
- FILE *process;
- int status;
- char *line = NULL;
- size_t len = 0;
- ssize_t bytes_read;
-
- process = popen (program, "r");
- if (process == NULL)
- return NULL;
-
- 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)