summaryrefslogtreecommitdiff
path: root/cloudinit/config/cc_power_state_change.py
diff options
context:
space:
mode:
authorHarm Weites <harm@weites.com>2013-12-14 22:49:32 +0000
committerHarm Weites <harm@weites.com>2013-12-14 22:49:32 +0000
commitd5613a54c27f3b494c7012dbdd68635a112e1e57 (patch)
treecd986a143b473e0428adebdafd12f96c7ff84d10 /cloudinit/config/cc_power_state_change.py
parentd6dcee2a818b97ccae8cd662cf108e954fc89e5c (diff)
downloadvyos-cloud-init-d5613a54c27f3b494c7012dbdd68635a112e1e57.tar.gz
vyos-cloud-init-d5613a54c27f3b494c7012dbdd68635a112e1e57.zip
change: Just run the required command and let the exception do the rest
if the process died. Checking first if the process is still alive proofed to be quite error prone, atleast on a rather slow compute node.
Diffstat (limited to 'cloudinit/config/cc_power_state_change.py')
-rw-r--r--cloudinit/config/cc_power_state_change.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/cloudinit/config/cc_power_state_change.py b/cloudinit/config/cc_power_state_change.py
index 50897b5f..6bd14b7e 100644
--- a/cloudinit/config/cc_power_state_change.py
+++ b/cloudinit/config/cc_power_state_change.py
@@ -31,16 +31,12 @@ frequency = PER_INSTANCE
EXIT_FAIL = 254
#
-# Returns the cmdline for the given process id.
+# Returns the cmdline for the given process id. In Linux we can use procfs for
+# this but on BSD there is /usr/bin/procstat.
#
def givecmdline(pid):
- # Check if this pid still exists by sending it the harmless 0 signal.
try:
- os.kill(pid, signal.SIG_DFL)
- except OSError:
- return None
- else:
# Example output from procstat -c 1
# PID COMM ARGS
# 1 init /bin/init --
@@ -51,6 +47,8 @@ def givecmdline(pid):
return m.group(2)
else:
return util.load_file("/proc/%s/cmdline" % pid)
+ except IOError:
+ return None
def handle(_name, cfg, _cloud, log, _args):