diff options
author | Janne Blomqvist <jb@gcc.gnu.org> | 2011-05-22 19:38:05 +0300 |
---|---|---|
committer | Janne Blomqvist <jb@gcc.gnu.org> | 2011-05-22 19:38:05 +0300 |
commit | eec2794c17c802a3027874aaa49f6bb3e5ef9f22 (patch) | |
tree | 1d313e75de83830a8ebf1e687e1c911765f13b29 /libgfortran/runtime/main.c | |
parent | 15f072f97b41fa6fdbc62c10a9a2c55a3295f65a (diff) | |
download | gcc-eec2794c17c802a3027874aaa49f6bb3e5ef9f22.zip gcc-eec2794c17c802a3027874aaa49f6bb3e5ef9f22.tar.gz gcc-eec2794c17c802a3027874aaa49f6bb3e5ef9f22.tar.bz2 |
PR 48931 Make backtrace async-signal-safe, reformat output
From-SVN: r174030
Diffstat (limited to 'libgfortran/runtime/main.c')
-rw-r--r-- | libgfortran/runtime/main.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/libgfortran/runtime/main.c b/libgfortran/runtime/main.c index f5d4721..54d9e09 100644 --- a/libgfortran/runtime/main.c +++ b/libgfortran/runtime/main.c @@ -92,6 +92,19 @@ store_exe_path (const char * argv0) if (please_free_exe_path_when_done) free ((char *) exe_path); + /* Reading the /proc/self/exe symlink is Linux-specific(?), but if + it works it gives the correct answer. */ +#ifdef HAVE_READLINK + int len; + if ((len = readlink ("/proc/self/exe", buf, sizeof (buf) - 1)) != -1) + { + buf[len] = '\0'; + exe_path = strdup (buf); + please_free_exe_path_when_done = 1; + return; + } +#endif + /* On the simulator argv is not set. */ if (argv0 == NULL || argv0[0] == '/') { @@ -107,7 +120,9 @@ store_exe_path (const char * argv0) cwd = ""; #endif - /* exe_path will be cwd + "/" + argv[0] + "\0" */ + /* exe_path will be cwd + "/" + argv[0] + "\0". This will not work + if the executable is not in the cwd, but at this point we're out + of better ideas. */ size_t pathlen = strlen (cwd) + 1 + strlen (argv0) + 1; path = malloc (pathlen); snprintf (path, pathlen, "%s%c%s", cwd, DIR_SEPARATOR, argv0); |