Skip to content

Commit

Permalink
Merge pull request #4 from murraybd/debian/sid
Browse files Browse the repository at this point in the history
Handle the situation where you may not be able to decrease process niceness e.g. on an lxc container.
  • Loading branch information
mvo5 committed Mar 5, 2015
2 parents 42c61ab + 440b261 commit ca30142
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions unattended-upgrade
Expand Up @@ -41,6 +41,7 @@ import sys


from email.message import Message
from errno import EACCESS, EPERM
from gettext import gettext as _
from io import StringIO
from optparse import (
Expand Down Expand Up @@ -1103,7 +1104,16 @@ def main(options, rootdir=""):

# FIXME: make this into a ContextManager
# be nice when calculating the upgrade as its pretty CPU intensive
os.nice(19)
old_priority = os.nice(0)
try:
# Check that we will be able to restore the priority
os.nice(-1)
os.nice(20)
except OSError as e:
if e.errno in (EPERM, EACCESS):
pass
else:
raise

# speed things up with latest apt
actiongroup = apt_pkg.ActionGroup(cache._depcache)
Expand All @@ -1121,7 +1131,7 @@ def main(options, rootdir=""):

# FIXME: make this into a ContextManager
# stop being nice
os.nice(-19)
os.nice(old_priority - os.nice(0))

# download what looks good
if options.debug:
Expand Down

2 comments on commit ca30142

@murraybd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this again all of errno is imported so importing EACCES and EPERM seems wrong.

@mvo5
Copy link
Owner Author

@mvo5 mvo5 commented on ca30142 Mar 6, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.