diff options
author | Harm Weites <harm@weites.com> | 2014-01-23 16:35:33 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2014-01-23 16:35:33 -0500 |
commit | 8e035f857a06adb5493bbcd35bd427cf2a9e813b (patch) | |
tree | e2f5aa7d6df52b11c242f9e3e4ea2fbf3395de67 /cloudinit/config/cc_power_state_change.py | |
parent | c833a84f08019ba4413937f2f1b1f12a4ffe5632 (diff) | |
parent | 75d6f035bcd94e6420ba6de5a9d12c1f554771cf (diff) | |
download | vyos-cloud-init-8e035f857a06adb5493bbcd35bd427cf2a9e813b.tar.gz vyos-cloud-init-8e035f857a06adb5493bbcd35bd427cf2a9e813b.zip |
Initial Freebsd support
This gets initial support for freebsd.
Diffstat (limited to 'cloudinit/config/cc_power_state_change.py')
-rw-r--r-- | cloudinit/config/cc_power_state_change.py | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/cloudinit/config/cc_power_state_change.py b/cloudinit/config/cc_power_state_change.py index e3150808..561c5abd 100644 --- a/cloudinit/config/cc_power_state_change.py +++ b/cloudinit/config/cc_power_state_change.py @@ -22,6 +22,7 @@ from cloudinit import util import errno import os import re +import signal import subprocess import time @@ -30,6 +31,24 @@ frequency = PER_INSTANCE EXIT_FAIL = 254 +def givecmdline(pid): + # Returns the cmdline for the given process id. In Linux we can use procfs + # for this but on BSD there is /usr/bin/procstat. + try: + # Example output from procstat -c 1 + # PID COMM ARGS + # 1 init /bin/init -- + if util.system_info()["platform"].startswith('FreeBSD'): + (output, _err) = util.subp(['procstat', '-c', str(pid)]) + line = output.splitlines()[1] + m = re.search('\d+ (\w|\.|-)+\s+(/\w.+)', line) + return m.group(2) + else: + return util.load_file("/proc/%s/cmdline" % pid) + except IOError: + return None + + def handle(_name, cfg, _cloud, log, _args): try: @@ -42,8 +61,8 @@ def handle(_name, cfg, _cloud, log, _args): return mypid = os.getpid() - cmdline = util.load_file("/proc/%s/cmdline" % mypid) + cmdline = givecmdline(mypid) if not cmdline: log.warn("power_state: failed to get cmdline of current process") return @@ -119,8 +138,6 @@ def run_after_pid_gone(pid, pidcmdline, timeout, log, func, args): msg = None end_time = time.time() + timeout - cmdline_f = "/proc/%s/cmdline" % pid - def fatal(msg): if log: log.warn(msg) @@ -134,16 +151,14 @@ def run_after_pid_gone(pid, pidcmdline, timeout, log, func, args): break try: - cmdline = "" - with open(cmdline_f) as fp: - cmdline = fp.read() + cmdline = givecmdline(pid) if cmdline != pidcmdline: msg = "cmdline changed for %s [now: %s]" % (pid, cmdline) break except IOError as ioerr: if ioerr.errno in known_errnos: - msg = "pidfile '%s' gone [%d]" % (cmdline_f, ioerr.errno) + msg = "pidfile gone [%d]" % ioerr.errno else: fatal("IOError during wait: %s" % ioerr) break |