Skip to content

Commit

Permalink
Merge pull request #18 from uptimejp/fix/nosuchfile
Browse files Browse the repository at this point in the history
Fix/nosuchfile
Fix pt-proc-stat to suppress an exception when the directory is not found. #17
  • Loading branch information
snaga committed Jun 4, 2015
2 parents 9847ec8 + c3cfa37 commit 28171ad
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
14 changes: 9 additions & 5 deletions bin/pt-proc-stat
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,15 @@ class PostgresProcessStat():
# Get pid from postmaster.pid if available.
if self.pgdata is not None:
log.debug("reading " + self.pgdata + "/postmaster.pid to to determine the postmaster pid.")
f = open(self.pgdata + "/postmaster.pid")
for l in f.readlines():
pid = int(l.replace('\n', ''))
break
f.close()
try:
f = open(self.pgdata + "/postmaster.pid")
for l in f.readlines():
pid = int(l.replace('\n', ''))
break
f.close()
except IOError, err:
log.error(err.strerror + " (" + self.pgdata + "/postmaster.pid" + ")")
sys.exit(1)

if pid is not None:
log.debug("found postmaster pid " + str(pid))
Expand Down
4 changes: 4 additions & 0 deletions bin/t/test-pt-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ function testConfig003()
pt-config -D $PGDATA get > $OUT
contains 'Usage: pt-config \[option...\] \[command\] \[param \[value\]\]' $OUT
assertTrue $?

# directory not found
pt-config -D nosuchdir get shared_buffers > $OUT
assertEquals 1 $?
}

function testConfig004()
Expand Down
8 changes: 8 additions & 0 deletions bin/t/test-pt-proc-stat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,12 @@ function testProcStat004()
assertEquals 0 $?
}

function testProcStat005()
{
OUT=${_SHUNIT_TEST_}.out

sudo env PATH=$PATH pt-proc-stat -D nosuchdir > $OUT
assertEquals 1 $?
}

. shunit2

0 comments on commit 28171ad

Please sign in to comment.