From: torvalds@klaava.Helsinki.FI (Linus Torvalds) Subject: Re: S_IFLNK with sym-links Date: 9 Jul 1993 00:32:08 +0300
In article <1993Jul8.162717.17078@informatik.uni-bremen.de> lucy@p222.informatik.Uni-Bremen.DE () writes:
>I tried to use S_IFLNK (stat.h) to find out if some file physicaly exist or
>if it"s sym-linked. This does not work (i think it works only for
>hart-links). Is there another way to check this (ls is able to do this
>but how ???).
You have got the right macros (use S_ISLNK(stat.st_mode)), but you are
probably using the "stat()" system call... And "stat()" follows the
symlink before returning the stat information, so you'll never get the
case that S_ISLNK() is true. What you should do is use "lstat()" which
doesn't follow the final symlink, and then test using S_ISLNK (ir do the
masking and test with S_IFLNK).
>PS In SYSV R4 (4.2?) there is an Interface to the proc-FS called truss.
> Via ioctl calls its possible to trace systemcalls and do some other
> usefull things. Has linux proc-FS the same capabilities i.e. is it
> possible to write something like truss for linux ???
> sorry , i don't have linux - proc(4) in my manpages .... ??
Linux uses the traditional "ptrace()" call for this and uses the /proc
filesystem for other things - check out the strace distribution which
probably does exactly what you want. You may even have strace already,
as I think SLS includes an older version of it. If not, check out
sunsite.unc.edu: pub/Linux/development/strace/. You can also use "gdb"
for some of this, including attaching to an already running program.
Get the man-page for the full features.
Linus