[Sanitizer] Make temporary filename depend on user ID

llvm-svn: 175424
This commit is contained in:
Alexey Samsonov 2013-02-18 07:17:12 +00:00
parent 595eb44a2c
commit 9211bd33ec
4 changed files with 16 additions and 5 deletions

View File

@ -126,6 +126,7 @@ void DumpProcessMap();
bool FileExists(const char *filename);
const char *GetEnv(const char *name);
const char *GetPwd();
u32 GetUid();
void ReExec();
bool StackSizeIsUnlimited();
void SetStackSizeLimitInBytes(uptr limit);

View File

@ -44,6 +44,10 @@ int GetPid() {
return getpid();
}
u32 GetUid() {
return getuid();
}
uptr GetThreadSelf() {
return (uptr)pthread_self();
}

View File

@ -131,6 +131,10 @@ const char *GetPwd() {
UNIMPLEMENTED();
}
u32 GetUid() {
UNIMPLEMENTED();
}
void DumpProcessMap() {
UNIMPLEMENTED();
}

View File

@ -55,22 +55,24 @@ TEST(SanitizerCommon, FileOps) {
const char *str2 = "zxcv";
uptr len2 = internal_strlen(str2);
const char kTempFileName[] = "/tmp/sanitizer_common.tmp";
fd_t fd = OpenFile(kTempFileName, true);
u32 uid = GetUid();
char temp_filename[128];
internal_snprintf(temp_filename, 128, "/tmp/sanitizer_common.tmp.%d", uid);
fd_t fd = OpenFile(temp_filename, true);
EXPECT_NE(fd, kInvalidFd);
EXPECT_EQ(len1, internal_write(fd, str1, len1));
EXPECT_EQ(len2, internal_write(fd, str2, len2));
internal_close(fd);
fd = OpenFile(kTempFileName, false);
fd = OpenFile(temp_filename, false);
EXPECT_NE(fd, kInvalidFd);
uptr fsize = internal_filesize(fd);
EXPECT_EQ(len1 + len2, fsize);
#if SANITIZER_TEST_HAS_STAT_H
struct stat st1, st2, st3;
EXPECT_EQ(0, internal_stat(kTempFileName, &st1));
EXPECT_EQ(0, internal_lstat(kTempFileName, &st2));
EXPECT_EQ(0, internal_stat(temp_filename, &st1));
EXPECT_EQ(0, internal_lstat(temp_filename, &st2));
EXPECT_EQ(0, internal_fstat(fd, &st3));
EXPECT_EQ(fsize, (uptr)st3.st_size);
#endif