#6208 BLOC Update.: olpc-update should inhibit ebook mode suspends

Zarro Boogs per Child bugtracker at laptop.org
Wed Feb 13 14:23:48 EST 2008


#6208: olpc-update should inhibit ebook mode suspends
------------------------------+---------------------------------------------
  Reporter:  cjb              |       Owner:  ApprovalForUpdate
      Type:  defect           |      Status:  new              
  Priority:  blocker          |   Milestone:  Update.1         
 Component:  upgrade utility  |     Version:                   
Resolution:                   |    Keywords:                   
  Verified:  0                |    Blocking:                   
 Blockedby:                   |  
------------------------------+---------------------------------------------
Changes (by cscott):

 * cc: cjb (added)
  * owner:  cscott => ApprovalForUpdate


Comment:

 OK, olpcupdate-2.3 is what's currently in update.1 rc2.  Asking for
 approval to put olpcupdate-2.4 in update.1.  Changelog:

   * Trac #6208: inhibit ebook suspend during olpc-update, not just ohm
 suspend.
   * Workaround trac #6275: try to clean up old inhibit-suspend file.

 Diff:
 {{{
 diff --git a/bitfrost/update/setup.py b/bitfrost/update/setup.py
 index 772f97e..7d799b7 100644
 --- a/bitfrost/update/setup.py
 +++ b/bitfrost/update/setup.py
 @@ -9,9 +9,27 @@ from subprocess import call, check_call, Popen, PIPE
  import os, os.path, re, struct, sys, time
  from bitfrost.contents.utils import UnifiedContents

 -def inhibit_suspend(f):
 +def _cleanup_lock(filename):
 +    """Try to delete lock file if the PID which wrote it is no longer
 around.
 +    Return `True` if we were successful cleaning up the lock (which means
 +    it's worthwhile to retry."""
 +    try:
 +        oldpid = int(open(filename, 'r').read().strip())
 +        try:
 +            os.getpgid(oldpid)
 +            return False # process still exists.
 +        except OSError:
 +            # pid is dead, clean up lock & retry.
 +            os.unlink(filename)
 +            time.sleep(1) # limit busy looping even in worst case.
 +            return True # retry.
 +    except:
 +        # some other error: probably file has something other than a PID
 +        return False
 +
 +
 +def with_suspend_lock(f, INHIBIT_FILE='/etc/ohm/inhibit-suspend'):
      """Decorator to inhibit suspend during execution of the given
 function."""
 -    INHIBIT_FILE = '/etc/ohm/inhibit-suspend' # too bad this isn't in
 /var/run
      def new_f(*args, **kwds):
          ohm_installed = os.path.isdir(os.path.dirname(INHIBIT_FILE))
          was_inhibited = False
 @@ -21,6 +39,10 @@ def inhibit_suspend(f):
                  os.write(fd, str(os.getpid()))
                  os.close(fd)
              except:
 +                # work around trac #6275: if the file exists and has a
 PID
 +                # in it, double-check that the process is still around.
 +                if _cleanup_lock(INHIBIT_FILE):
 +                    return new_f(*args, **kwds) # back to top, try again.
                  was_inhibited = True
          try:
              return f(*args, **kwds)
 @@ -29,6 +51,14 @@ def inhibit_suspend(f):
      new_f.func_name = f.func_name
      return new_f

 +# XXX: the inhibit files should really be in /var/run (or /var/lib/ohm,
 +#      but then that would have to be manually added as a tmpfs).
 +def inhibit_suspend(f):
 +    """Use both the ebook and ohm suspend inhibit hooks."""
 +    f = with_suspend_lock(f, '/etc/ohm/inhibit-suspend')
 +    f = with_suspend_lock(f, '/etc/inhibit-ebook-sleep')
 +    return f
 +
  def _mklockfile(filename):
      """Attempt to create a lock file; throws an exception if the lock
 file
      already exists and the process which created the lock file is still
 @@ -43,16 +73,11 @@ def _mklockfile(filename):
      except:
          # if file already exists, but pid doesn't exist anymore,
          # unlink and try again.
 -        try:
 -            oldpid = int(open(filename, 'r').read().strip())
 -            os.getpgid(oldpid)
 -        except:
 -            os.unlink(filename)
 -            time.sleep(1) # limit busy looping even in worst case
 +        if _cleanup_lock(filename):
              return _mklockfile(filename)
          # no, old lock file is legit.
          raise RuntimeError('Process %s already holds lockfile %s' %
 -                           (oldpid, filename))
 +                           (open(filename).read(), filename))

  def with_lock_file(filename):
      """Decorator to limit concurrency of a given function using a lock
 file."""
 }}}

 cc'ing cjb so he can double-check the filenames.

-- 
Ticket URL: <http://dev.laptop.org/ticket/6208#comment:2>
One Laptop Per Child <http://dev.laptop.org>
OLPC bug tracking system



More information about the Bugs mailing list