Skip to content

Commit

Permalink
Change pidfile permissions to 600
Browse files Browse the repository at this point in the history
  • Loading branch information
Radek Novacek committed Feb 23, 2016
1 parent 59f4e01 commit 4ddbb75
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions virtwho.py
Expand Up @@ -651,8 +651,8 @@ def __init__(self, filename):

def is_locked(self):
try:
f = open(self.filename, "r")
pid = int(f.read().strip())
with open(self.filename, "r") as f:
pid = int(f.read().strip())
try:
os.kill(pid, 0)
return True
Expand All @@ -667,7 +667,7 @@ def is_locked(self):
def __enter__(self):
# Write pid to pidfile
try:
with open(self.filename, "w") as f:
with os.fdopen(os.open(self.filename, os.O_WRONLY | os.O_CREAT, 0600), 'w') as f:
f.write("%d" % os.getpid())
except Exception as e:
print >>sys.stderr, "Unable to create pid file: %s" % str(e)
Expand Down

0 comments on commit 4ddbb75

Please sign in to comment.