This is the mail archive of the
cluster-cvs@sourceware.org
mailing list for the cluster.
fence-agents: master - fence_*.py: Fix no fencing.py based scripts toforce stdout close
- From: Jan Friesse <honzaf at fedoraproject dot org>
- To: cluster-cvs-relay at redhat dot com
- Date: Tue, 3 Mar 2009 10:58:48 +0000 (UTC)
- Subject: fence-agents: master - fence_*.py: Fix no fencing.py based scripts toforce stdout close
Gitweb: http://git.fedorahosted.org/git/fence-agents.git?p=fence-agents.git;a=commitdiff;h=e421362e3f6926ce6a0914dff33ffadb3d12deaf
Commit: e421362e3f6926ce6a0914dff33ffadb3d12deaf
Parent: a6d00b47d451a71e5d9efcd173829fdaf503d14d
Author: Jan Friesse <jfriesse@redhat.com>
AuthorDate: Tue Mar 3 11:58:36 2009 +0100
Committer: Jan Friesse <jfriesse@redhat.com>
CommitterDate: Tue Mar 3 11:58:36 2009 +0100
fence_*.py: Fix no fencing.py based scripts to force stdout close
This feature is advise from Jim Meyering. On the beginning
of script, we register end callback, which close stdout and
show error, if this wasn't successful.
---
fence/agents/apc_snmp/fence_apc_snmp.py | 10 ++++++++++
fence/agents/cisco_mds/fence_cisco_mds.py | 2 ++
fence/agents/ifmib/fence_ifmib.py | 10 ++++++++++
fence/agents/rsa/fence_rsa.py | 11 +++++++++++
fence/agents/rsb/fence_rsb.py | 11 +++++++++++
5 files changed, 44 insertions(+), 0 deletions(-)
diff --git a/fence/agents/apc_snmp/fence_apc_snmp.py b/fence/agents/apc_snmp/fence_apc_snmp.py
index b7a8c8a..d2530da 100644
--- a/fence/agents/apc_snmp/fence_apc_snmp.py
+++ b/fence/agents/apc_snmp/fence_apc_snmp.py
@@ -13,6 +13,7 @@ import datetime
import time
import select
import signal
+import atexit
from glob import glob
#BEGIN_VERSION_GENERATION
@@ -243,9 +244,18 @@ def log(msg, error=False):
o = sys.stdout
o.write(msg)
+def atexit_handler():
+ try:
+ sys.stdout.close()
+ os.close(1)
+ except IOError:
+ sys.stderr.write("%s failed to close standard output\n"%(sys.argv[0]))
+ sys.exit(1)
def main():
+ atexit.register(atexit_handler)
+
try:
main2()
return 0
diff --git a/fence/agents/cisco_mds/fence_cisco_mds.py b/fence/agents/cisco_mds/fence_cisco_mds.py
index d5de816..0e18037 100644
--- a/fence/agents/cisco_mds/fence_cisco_mds.py
+++ b/fence/agents/cisco_mds/fence_cisco_mds.py
@@ -87,6 +87,8 @@ def main():
"snmp_priv_prot", "snmp_priv_passwd", "snmp_priv_passwd_script",
"udpport"]
+ atexit.register(atexit_handler)
+
options=process_input(device_opt)
# Emulate enable/disable functionality
diff --git a/fence/agents/ifmib/fence_ifmib.py b/fence/agents/ifmib/fence_ifmib.py
index 3f0c43d..42345ff 100644
--- a/fence/agents/ifmib/fence_ifmib.py
+++ b/fence/agents/ifmib/fence_ifmib.py
@@ -19,6 +19,7 @@ BUILD_DATE="March, 2008"
import os
os.environ['PYSNMP_API_VERSION'] = 'v2'
import sys, getopt, random, socket
+import atexit
from pysnmp import role, v2c, asn1
ifAdminStatus = '.1.3.6.1.2.1.2.2.1.7.'
@@ -160,8 +161,17 @@ def snmpset (host, comm, oid, type, value):
else:
raise IOError('SNMP error while setting')
+def atexit_handler():
+ try:
+ sys.stdout.close()
+ os.close(1)
+ except IOError:
+ sys.stderr.write("%s failed to close standard output\n"%(sys.argv[0]))
+ sys.exit(1)
def main():
+ atexit.register(atexit_handler)
+
if len (sys.argv) > 1:
(comm, host, index, option, verbose) = parseargs ()
else:
diff --git a/fence/agents/rsa/fence_rsa.py b/fence/agents/rsa/fence_rsa.py
index 51910e8..831848e 100644
--- a/fence/agents/rsa/fence_rsa.py
+++ b/fence/agents/rsa/fence_rsa.py
@@ -4,6 +4,7 @@ import getopt, sys
import os
import socket
import time
+import atexit
from telnetlib import Telnet
@@ -38,6 +39,14 @@ def version():
print "%s\n" % REDHAT_COPYRIGHT
sys.exit(0)
+def atexit_handler():
+ try:
+ sys.stdout.close()
+ os.close(1)
+ except IOError:
+ sys.stderr.write("%s failed to close standard output\n"%(sys.argv[0]))
+ sys.exit(1)
+
def main():
POWER_OFF = 0
@@ -67,6 +76,8 @@ def main():
regex_list.append("Power:")
regex_list.append("Error:")
+ atexit.register(atexit_handler)
+
if len(sys.argv) > 1:
try:
opts, args = getopt.getopt(sys.argv[1:], "a:hl:o:p:S:vV", ["help", "output="])
diff --git a/fence/agents/rsb/fence_rsb.py b/fence/agents/rsb/fence_rsb.py
index a11e7ce..1df0374 100644
--- a/fence/agents/rsb/fence_rsb.py
+++ b/fence/agents/rsb/fence_rsb.py
@@ -4,6 +4,7 @@ import getopt, sys
import os
import socket
import time
+import atexit
from telnetlib import Telnet
@@ -40,6 +41,14 @@ def version():
print "%s\n" % REDHAT_COPYRIGHT
sys.exit(0)
+def atexit_handler():
+ try:
+ sys.stdout.close()
+ os.close(1)
+ except IOError:
+ sys.stderr.write("%s failed to close standard output\n"%(sys.argv[0]))
+ sys.exit(1)
+
def main():
depth = 0
POWER_OFF = 0
@@ -80,6 +89,8 @@ def main():
regex_list.append("really want to")
regex_list.append("CLOSING TELNET CONNECTION")
+ atexit.register(atexit_handler)
+
if len(sys.argv) > 1:
try:
opts, args = getopt.getopt(sys.argv[1:], "a:hl:n:o:p:S:vV", ["help", "output="])