From 9adc8529679dc5e7b6426dc0a47469fb0d890fb2 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Tue, 3 Sep 2002 13:56:36 +0000 Subject: 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 --- byterun/unix.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'byterun/unix.c') 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 -- cgit v1.2.3-70-g09d2