diff options
author | Gregor Giesen <giesen@zaehlwerk.net> | 2016-09-10 13:19:55 +0200 |
---|---|---|
committer | Rene Moser <mail@renemoser.net> | 2016-10-19 15:52:17 +0200 |
commit | 531e09ce167c44387fc9c6505dd0453a7251b8f9 (patch) | |
tree | a6a9fab83f3154bcce529464c6127bf38c334603 | |
parent | c00ae0082f6dd5477f7449e96bb4a84737e47641 (diff) | |
download | ansible-modules-core-531e09ce167c44387fc9c6505dd0453a7251b8f9.tar.gz |
cron: replacement for os.getlogin()
os.getlogin() returns the user logged in on the controlling terminal. However
'crontab' only looks for the login name of the process' real user id which
pwd.getpwuid(os.getuid())[0] does provide.
While in most cases there is no difference, the former might fail under certain
circumstances (e.g. a lxc container connected by attachment without login),
throwing the error 'OSError: [Errno 25] Inappropriate ioctl for device'.
-rw-r--r-- | system/cron.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/system/cron.py b/system/cron.py index 8152c6e5..a983a398 100644 --- a/system/cron.py +++ b/system/cron.py @@ -198,6 +198,7 @@ EXAMPLES = ''' ''' import os +import pwd import re import tempfile import platform @@ -477,7 +478,7 @@ class CronTab(object): return "%s -l %s" % (pipes.quote(CRONCMD), pipes.quote(self.user)) elif platform.system() == 'HP-UX': return "%s %s %s" % (CRONCMD , '-l', pipes.quote(self.user)) - elif os.getlogin() != self.user: + elif pwd.getpwuid(os.getuid())[0] != self.user: user = '-u %s' % pipes.quote(self.user) return "%s %s %s" % (CRONCMD , user, '-l') @@ -489,7 +490,7 @@ class CronTab(object): if self.user: if platform.system() in ['SunOS', 'HP-UX', 'AIX']: return "chown %s %s ; su '%s' -c '%s %s'" % (pipes.quote(self.user), pipes.quote(path), pipes.quote(self.user), CRONCMD, pipes.quote(path)) - elif os.getlogin() != self.user: + elif pwd.getpwuid(os.getuid())[0] != self.user: user = '-u %s' % pipes.quote(self.user) return "%s %s %s" % (CRONCMD , user, pipes.quote(path)) |