Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/pynslcd/mypidfile.py
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2017-06-25 16:05:44 +0200
committerArthur de Jong <arthur@arthurdejong.org>2017-06-25 16:06:46 +0200
commit65695aa1d0fbc0a4aa5e7b1bb28c66fbb4879e01 (patch)
tree688ff0bf41d04f9f072d2e3f279b86016baa954b /pynslcd/mypidfile.py
parent419aab2656c8678840cd9dd7c3afc928cdd57d7f (diff)
Create pidfile directory in pynslcd
This ensures that /var/run/nslcd is created (when it does not exist) when starting pynslcd.
Diffstat (limited to 'pynslcd/mypidfile.py')
-rw-r--r--pynslcd/mypidfile.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/pynslcd/mypidfile.py b/pynslcd/mypidfile.py
index e386f3e..2bf158f 100644
--- a/pynslcd/mypidfile.py
+++ b/pynslcd/mypidfile.py
@@ -1,7 +1,7 @@
# mypidfile.py - functions for properly locking a PIDFile
#
-# Copyright (C) 2010, 2011, 2012 Arthur de Jong
+# Copyright (C) 2010-2017 Arthur de Jong
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -22,6 +22,8 @@ import errno
import fcntl
import os
+import cfg
+
class MyPIDLockFile(object):
"""Implementation of a PIDFile fit for use with the daemon module
@@ -32,6 +34,12 @@ class MyPIDLockFile(object):
def __enter__(self):
"""Lock the PID file and write the process ID to the file."""
+ # create the directory for the pidfile if needed
+ piddir = os.path.dirname(self.path)
+ if not os.path.isdir(piddir):
+ os.mkdir(piddir)
+ u, gid = cfg.get_usergid()
+ os.chown(piddir, u.u.pw_uid, gid)
fd = os.open(self.path, os.O_RDWR | os.O_CREAT, 0644)
try:
fcntl.lockf(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)