summaryrefslogtreecommitdiffstats
path: root/byterun/unix.c
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2002-09-03 13:56:36 +0000
committerXavier Leroy <xavier.leroy@inria.fr>2002-09-03 13:56:36 +0000
commit9adc8529679dc5e7b6426dc0a47469fb0d890fb2 (patch)
tree24a87f739d45597c6d00a4f3a31013cbd6b84b6a /byterun/unix.c
parented82bb65a6f23401fba1196d991197554e748bdb (diff)
Blinder la lecture de /proc/self/exe (sur de vieux noyaux Linux, ca ne renvoie pas un nom de fichier, mais un inode)
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@5113 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'byterun/unix.c')
-rw-r--r--byterun/unix.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/byterun/unix.c b/byterun/unix.c
index 465b68409..6fbf0922e 100644
--- a/byterun/unix.c
+++ b/byterun/unix.c
@@ -254,3 +254,24 @@ void aligned_munmap (char * addr, asize_t size)
}
#endif
+
+/* Recover executable name from /proc/self/exe if possible */
+
+#ifdef __linux__
+
+int executable_name(char * name, int name_len)
+{
+ int retcode;
+ struct stat st;
+
+ retcode = readlink("/proc/self/exe", name, name_len);
+ if (retcode == -1 || retcode >= name_len) return -1;
+ name[retcode] = 0;
+ /* Make sure that the contents of /proc/self/exe is a regular file.
+ (Old Linux kernels return an inode number instead.) */
+ if (stat(name, &st) != 0) return -1;
+ if (! S_ISREG(st.st_mode)) return -1;
+ return 0;
+}
+
+#endif