aboutsummaryrefslogtreecommitdiff
path: root/rp/rcynic/rcynic-cron
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2015-10-26 06:29:00 +0000
committerRob Austein <sra@hactrn.net>2015-10-26 06:29:00 +0000
commitb46deb1417dc3596e9ac9fe2fe8cc0b7f42457e7 (patch)
treeca0dc0276d1adc168bc3337ce0564c4ec4957c1b /rp/rcynic/rcynic-cron
parent397beaf6d9900dc3b3cb612c89ebf1d57b1d16f6 (diff)
"Any programmer who fails to comply with the standard naming, formatting,
or commenting conventions should be shot. If it so happens that it is inconvenient to shoot him, then he is to be politely requested to recode his program in adherence to the above standard." -- Michael Spier, Digital Equipment Corporation svn path=/branches/tk705/; revision=6152
Diffstat (limited to 'rp/rcynic/rcynic-cron')
-rwxr-xr-xrp/rcynic/rcynic-cron90
1 files changed, 45 insertions, 45 deletions
diff --git a/rp/rcynic/rcynic-cron b/rp/rcynic/rcynic-cron
index 53bfea9f..3d38726c 100755
--- a/rp/rcynic/rcynic-cron
+++ b/rp/rcynic/rcynic-cron
@@ -35,34 +35,34 @@ import argparse
import rpki.autoconf
def run(*cmd, **kwargs):
- chroot_this = kwargs.pop("chroot_this", False)
- cwd = kwargs.pop("cwd", None)
- pid = os.fork()
- if pid == 0:
- if chroot_this:
- os.chdir(rpki.autoconf.RCYNIC_DIR)
- elif cwd is not None:
- os.chdir(cwd)
- if we_are_root:
- os.initgroups(pw.pw_name, pw.pw_gid)
- if chroot_this:
- os.chroot(rpki.autoconf.RCYNIC_DIR)
- if we_are_root:
- os.setgid(pw.pw_gid)
- os.setuid(pw.pw_uid)
- os.closerange(3, os.sysconf("SC_OPEN_MAX"))
- os.execvp(cmd[0], cmd)
- os._exit(1)
- else:
- status = os.waitpid(pid, 0)[1]
- if status == 0:
- return
- elif os.WIFSIGNALED(status):
- sys.exit("Process %s exited with signal %s" % (" ".join(cmd), os.WTERMSIG(status)))
- elif os.WIFEXITED(status):
- sys.exit("Program %s exited with status %s" % (" ".join(cmd), os.WEXITSTATUS(status)))
+ chroot_this = kwargs.pop("chroot_this", False)
+ cwd = kwargs.pop("cwd", None)
+ pid = os.fork()
+ if pid == 0:
+ if chroot_this:
+ os.chdir(rpki.autoconf.RCYNIC_DIR)
+ elif cwd is not None:
+ os.chdir(cwd)
+ if we_are_root:
+ os.initgroups(pw.pw_name, pw.pw_gid)
+ if chroot_this:
+ os.chroot(rpki.autoconf.RCYNIC_DIR)
+ if we_are_root:
+ os.setgid(pw.pw_gid)
+ os.setuid(pw.pw_uid)
+ os.closerange(3, os.sysconf("SC_OPEN_MAX"))
+ os.execvp(cmd[0], cmd)
+ os._exit(1)
else:
- sys.exit("Program %s exited for unknown reason %s" % (" ".join(cmd), status))
+ status = os.waitpid(pid, 0)[1]
+ if status == 0:
+ return
+ elif os.WIFSIGNALED(status):
+ sys.exit("Process %s exited with signal %s" % (" ".join(cmd), os.WTERMSIG(status)))
+ elif os.WIFEXITED(status):
+ sys.exit("Program %s exited with status %s" % (" ".join(cmd), os.WEXITSTATUS(status)))
+ else:
+ sys.exit("Program %s exited for unknown reason %s" % (" ".join(cmd), status))
parser = argparse.ArgumentParser(description = __doc__)
parser.add_argument("--chroot", action = "store_true", help = "run chrooted")
@@ -71,29 +71,29 @@ args = parser.parse_args()
we_are_root = os.getuid() == 0
if args.chroot and not we_are_root:
- sys.exit("Only root can --chroot")
+ sys.exit("Only root can --chroot")
try:
- pw = pwd.getpwnam(rpki.autoconf.RCYNIC_USER)
+ pw = pwd.getpwnam(rpki.autoconf.RCYNIC_USER)
except KeyError:
- sys.exit("Could not find passwd entry for user %s" % rpki.autoconf.RCYNIC_USER)
+ sys.exit("Could not find passwd entry for user %s" % rpki.autoconf.RCYNIC_USER)
try:
- lock = os.open(os.path.join(rpki.autoconf.RCYNIC_DIR, "data/lock"),
- os.O_RDONLY | os.O_CREAT | os.O_NONBLOCK, 0666)
- fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
- if we_are_root:
- os.fchown(lock, pw.pw_uid, pw.pw_gid)
+ lock = os.open(os.path.join(rpki.autoconf.RCYNIC_DIR, "data/lock"),
+ os.O_RDONLY | os.O_CREAT | os.O_NONBLOCK, 0666)
+ fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
+ if we_are_root:
+ os.fchown(lock, pw.pw_uid, pw.pw_gid)
except (IOError, OSError), e:
- if e.errno == errno.EAGAIN:
- sys.exit(0) # Another instance of this script is already running, exit silently
- else:
- sys.exit("Error %r opening lock %r" % (e.strerror, os.path.join(rpki.autoconf.RCYNIC_DIR, "data/lock")))
+ if e.errno == errno.EAGAIN:
+ sys.exit(0) # Another instance of this script is already running, exit silently
+ else:
+ sys.exit("Error %r opening lock %r" % (e.strerror, os.path.join(rpki.autoconf.RCYNIC_DIR, "data/lock")))
if args.chroot:
- run("/bin/rcynic", "-c", "/etc/rcynic.conf", chroot_this = True)
+ run("/bin/rcynic", "-c", "/etc/rcynic.conf", chroot_this = True)
else:
- run(os.path.join(rpki.autoconf.bindir, "rcynic"), "-c", os.path.join(rpki.autoconf.sysconfdir, "rcynic.conf"))
+ run(os.path.join(rpki.autoconf.bindir, "rcynic"), "-c", os.path.join(rpki.autoconf.sysconfdir, "rcynic.conf"))
run(os.path.join(rpki.autoconf.bindir, "rpki-rtr"),
"cronjob",
@@ -102,9 +102,9 @@ run(os.path.join(rpki.autoconf.bindir, "rpki-rtr"),
prog = os.path.join(rpki.autoconf.libexecdir, "rpkigui-rcynic")
if os.path.exists(prog):
- run(prog)
+ run(prog)
if rpki.autoconf.RCYNIC_HTML_DIR and os.path.exists(os.path.dirname(rpki.autoconf.RCYNIC_HTML_DIR)):
- run(os.path.join(rpki.autoconf.bindir, "rcynic-html"),
- os.path.join(rpki.autoconf.RCYNIC_DIR, "data/rcynic.xml"),
- rpki.autoconf.RCYNIC_HTML_DIR)
+ run(os.path.join(rpki.autoconf.bindir, "rcynic-html"),
+ os.path.join(rpki.autoconf.RCYNIC_DIR, "data/rcynic.xml"),
+ rpki.autoconf.RCYNIC_HTML_DIR)