Skip to content

Commit

Permalink
Merge pull request cms-sw#166 from cms-analysis/development
Browse files Browse the repository at this point in the history
Merge bugfix cms-sw#165 into sl6
  • Loading branch information
gpetruc committed Dec 5, 2014
2 parents d52eb8c + 9d63b8e commit 84b8aa1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/CloseCoutSentry.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "../interface/CloseCoutSentry.h"

#include <cstdio>
#include <cassert>
#include <unistd.h>

bool CloseCoutSentry::open_ = true;
Expand All @@ -22,6 +23,7 @@ CloseCoutSentry::CloseCoutSentry(bool silent) :
}
freopen("/dev/null", "w", stdout);
freopen("/dev/null", "w", stderr);
assert(owner_ == 0);
owner_ = this;
} else {
silent_ = false;
Expand All @@ -36,7 +38,10 @@ CloseCoutSentry::~CloseCoutSentry()

void CloseCoutSentry::clear()
{
if (stdOutIsMine_) { fclose(trueStdOut_); trueStdOut_ = 0; }
if (stdOutIsMine_) {
assert(this == owner_);
fclose(trueStdOut_); trueStdOut_ = 0; stdOutIsMine_ = false;
}
if (silent_) {
reallyClear();
silent_ = false;
Expand Down Expand Up @@ -70,6 +75,8 @@ FILE *CloseCoutSentry::trueStdOut()
{
if (open_) return stdout;
if (trueStdOut_) return trueStdOut_;
if (owner_ != this && owner_ != 0) return owner_->trueStdOut();
assert(owner_ == this);
stdOutIsMine_ = true;
char buf[50];
sprintf(buf, "/dev/fd/%d", fdOut_); trueStdOut_ = fopen(buf, "w");
Expand Down

0 comments on commit 84b8aa1

Please sign in to comment.