Logo Search packages:      
Sourcecode: schroot version File versions  Download package

void chroot_block_device::setup_lock ( setup_type  type,
bool  lock 
) [virtual]

Lock a chroot during setup. The locking technique (if any) may vary depending upon the chroot type and setup stage. For example, during creation of an LVM snapshot a block device might require locking, but afterwards this will change to the new block device.

An error will be thrown on failure.

Parameters:
type the type of setup being performed
lock true to lock, false to unlock

Implements sbuild::chroot.

Reimplemented in sbuild::chroot_lvm_snapshot.

Definition at line 113 of file sbuild-chroot-block-device.cc.

References device, sbuild::chroot::EXEC_START, sbuild::chroot::EXEC_STOP, get_device(), sbuild::chroot::get_name(), sbuild::lock::LOCK_EXCLUSIVE, sbuild::device_lock::set_lock(), sbuild::chroot::SETUP_START, sbuild::chroot::SETUP_STOP, and sbuild::device_lock::unset_lock().

{
  struct stat statbuf;

  /* Only lock during setup, not run. */
  if (type == EXEC_START || type == EXEC_STOP)
    return;

  /* Lock is preserved through the entire session. */
  if ((type == SETUP_START && lock == false) ||
      (type == SETUP_STOP && lock == true))
    return;

  if (stat(this->device.c_str(), &statbuf) == -1)
    {
      format fmt(_("%1% chroot: failed to stat device %2%: %3%"));
      fmt % get_name() % get_device() % strerror(errno);
      throw error(fmt);
    }
  else if (!S_ISBLK(statbuf.st_mode))
    {
      format fmt(_("%1% chroot: %2% is not a block device"));
      fmt % get_name() % get_device();
      throw error(fmt);
    }
  else
    {
      sbuild::device_lock dlock(this->device);
      if (lock)
      {
        try
          {
            dlock.set_lock(lock::LOCK_EXCLUSIVE, 15);
          }
        catch (sbuild::lock::error const& e)
          {
            format fmt(_("%1%: failed to lock device: %2%"));
            fmt % get_device() % e.what();
            throw error(fmt);
          }
      }
      else
      {
        try
          {
            dlock.unset_lock();
          }
        catch (sbuild::lock::error const& e)
          {
            format fmt(_("%1%: failed to unlock device: %2%"));
            fmt % get_device() % e.what();
            throw error(fmt);
          }
      }
    }
}


Generated by  Doxygen 1.6.0   Back to index