Skip to content

Commit

Permalink
Unix: Fix FD leaks and Windows compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
nyuszika7h committed Feb 27, 2014
1 parent a3c79d6 commit bc4cfb9
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions plugins/Unix/plugin.py
Expand Up @@ -210,10 +210,11 @@ def fortune(self, irc, msg, args):
args.append('-a')
args.extend(self.registryValue('fortune.files'))
try:
inst = subprocess.Popen(args, close_fds=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=open(os.devnull))
with open(os.devnull) as null:
inst = subprocess.Popen(args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=null)
except OSError as e:
irc.error(_('It seems the configured fortune command was '
'not available.'), Raise=True)
Expand Down Expand Up @@ -241,10 +242,11 @@ def wtf(self, irc, msg, args, foo, something):
if wtfCmd:
something = something.rstrip('?')
try:
inst = subprocess.Popen([wtfCmd, something], close_fds=True,
stdout=subprocess.PIPE,
stderr=open(os.devnull),
stdin=open(os.devnull))
with open(os.devnull, 'r+') as null:
inst = subprocess.Popen([wtfCmd, something],
stdout=subprocess.PIPE,
stderr=null,
stdin=null)
except OSError:
irc.error(_('It seems the configured wtf command was not '
'available.'), Raise=True)
Expand Down Expand Up @@ -291,9 +293,11 @@ def ping(self, irc, msg, args, optlist, host):
args.append('5')
args.append(host)
try:
inst = subprocess.Popen(args, stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=open(os.devnull))
with open(os.devnull) as null:
inst = subprocess.Popen(args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=null)
except OSError as e:
irc.error('It seems the configured ping command was '
'not available (%s).' % e, Raise=True)
Expand Down Expand Up @@ -323,10 +327,11 @@ def sysuptime(self, irc, msg, args):
if uptimeCmd:
args = [uptimeCmd]
try:
inst = subprocess.Popen(args, close_fds=True,
with open(os.devnull) as null:
inst = subprocess.Popen(args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=open(os.devnull))
stdin=null)
except OSError as e:
irc.error('It seems the configured uptime command was '
'not available.', Raise=True)
Expand All @@ -351,10 +356,11 @@ def sysuname(self, irc, msg, args):
if unameCmd:
args = [unameCmd, '-a']
try:
inst = subprocess.Popen(args, close_fds=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=open(os.devnull))
with open(os.devnull) as null:
inst = subprocess.Popen(args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=null)
except OSError as e:
irc.error('It seems the configured uptime command was '
'not available.', Raise=True)
Expand All @@ -381,9 +387,10 @@ def call(self, irc, msg, args, text):
"""
args = shlex.split(text)
try:
inst = subprocess.Popen(args, stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=open(os.devnull))
with open(os.devnull) as null:
inst = subprocess.Popen(args, stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=null)
except OSError as e:
irc.error('It seems the requested command was '
'not available (%s).' % e, Raise=True)
Expand Down

0 comments on commit bc4cfb9

Please sign in to comment.