clang: Skip attempts to access /proc/self/fd
In contrast to Linux it does not provide entries which can be readlinked -- these are just regular files, not giving the expected outcome. That's on top of procfs not being mounted by default to begin with. Reviewed by: dim Differential Revision: https://reviews.freebsd.org/D34684
This commit is contained in:
parent
ef88adc527
commit
30ed48b0a5
@ -930,7 +930,15 @@ ErrorOr<basic_file_status> directory_entry::status() const {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(F_GETPATH)
|
//
|
||||||
|
// FreeBSD optionally provides /proc/self/fd, but it is incompatible with
|
||||||
|
// Linux. The thing to use is realpath.
|
||||||
|
//
|
||||||
|
#if !defined(__FreeBSD__)
|
||||||
|
#define TRY_PROC_SELF_FD
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(F_GETPATH) && defined(TRY_PROC_SELF_FD)
|
||||||
static bool hasProcSelfFD() {
|
static bool hasProcSelfFD() {
|
||||||
// If we have a /proc filesystem mounted, we can quickly establish the
|
// If we have a /proc filesystem mounted, we can quickly establish the
|
||||||
// real name of the file with readlink
|
// real name of the file with readlink
|
||||||
@ -1117,6 +1125,7 @@ std::error_code openFileForRead(const Twine &Name, int &ResultFD,
|
|||||||
RealPath->append(Buffer, Buffer + strlen(Buffer));
|
RealPath->append(Buffer, Buffer + strlen(Buffer));
|
||||||
#else
|
#else
|
||||||
char Buffer[PATH_MAX];
|
char Buffer[PATH_MAX];
|
||||||
|
#if defined(TRY_PROC_SELF_FD)
|
||||||
if (hasProcSelfFD()) {
|
if (hasProcSelfFD()) {
|
||||||
char ProcPath[64];
|
char ProcPath[64];
|
||||||
snprintf(ProcPath, sizeof(ProcPath), "/proc/self/fd/%d", ResultFD);
|
snprintf(ProcPath, sizeof(ProcPath), "/proc/self/fd/%d", ResultFD);
|
||||||
@ -1124,13 +1133,16 @@ std::error_code openFileForRead(const Twine &Name, int &ResultFD,
|
|||||||
if (CharCount > 0)
|
if (CharCount > 0)
|
||||||
RealPath->append(Buffer, Buffer + CharCount);
|
RealPath->append(Buffer, Buffer + CharCount);
|
||||||
} else {
|
} else {
|
||||||
|
#endif
|
||||||
SmallString<128> Storage;
|
SmallString<128> Storage;
|
||||||
StringRef P = Name.toNullTerminatedStringRef(Storage);
|
StringRef P = Name.toNullTerminatedStringRef(Storage);
|
||||||
|
|
||||||
// Use ::realpath to get the real path name
|
// Use ::realpath to get the real path name
|
||||||
if (::realpath(P.begin(), Buffer) != nullptr)
|
if (::realpath(P.begin(), Buffer) != nullptr)
|
||||||
RealPath->append(Buffer, Buffer + strlen(Buffer));
|
RealPath->append(Buffer, Buffer + strlen(Buffer));
|
||||||
|
#if defined(TRY_PROC_SELF_FD)
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
return std::error_code();
|
return std::error_code();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user