Bug 535564 - automation.py: WindowsError: [Error 13] The process cannot access the file because it is being used by another process. Don't keep the PID log open all the time, but only open it when it is needed. r?griffin

--HG--
extra : rebase_source : 1072e20feb1db8a98f99de5617e416ca23efb511
This commit is contained in:
Benjamin Smedberg 2010-01-26 09:53:32 -05:00
Родитель a1270d8a1b
Коммит 7e7f0841a8
2 изменённых файлов: 17 добавлений и 18 удалений

Просмотреть файл

@ -42,37 +42,36 @@ const void *const *StackTrace::Addresses(size_t* count) {
namespace mozilla {
EnvironmentLog::EnvironmentLog(const char* varname)
: fd_(NULL)
{
const char *e = getenv(varname);
printf("EnvironmentLog<%p>(%s)\n", (void*) this, e ? e : "(null)");
if (e && *e) {
if (!strcmp(e, "-")) {
fd_ = fdopen(dup(STDOUT_FILENO), "a");
}
else {
fd_ = fopen(e, "a");
}
}
if (e && *e)
fname_ = e;
}
EnvironmentLog::~EnvironmentLog()
{
printf("~EnvironmentLog<%p>\n", (void*) this);
if (fd_)
fclose(fd_);
}
void
EnvironmentLog::print(const char* format, ...)
{
if (!fname_.size())
return;
FILE* f;
if (fname_.compare("-") == 0)
f = fdopen(dup(STDOUT_FILENO), "a");
else
f = fopen(fname_.c_str(), "a");
if (!f)
return;
va_list a;
va_start(a, format);
if (fd_) {
vfprintf(fd_, format, a);
fflush(fd_);
}
vfprintf(f, format, a);
va_end(a);
fclose(f);
}
} // namespace mozilla

Просмотреть файл

@ -78,7 +78,7 @@ public:
void print(const char* format, ...);
private:
FILE* fd_;
std::string fname_;
DISALLOW_EVIL_CONSTRUCTORS(EnvironmentLog);
};