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

void session::wait_for_child ( int  pid,
int &  child_status 
) [private]

Wait for a child process to complete, and check its exit status.

An error will be thrown on failure.

Parameters:
pid the pid to wait for.
child_status the place to store the child exit status.

Definition at line 829 of file sbuild-session.cc.

References chroot_status, and sbuild::auth::close_session().

Referenced by run_chroot(), and setup_chroot().

{
  child_status = EXIT_FAILURE; // Default exit status

  int status;
  bool child_killed = false;

  while (1)
    {
      if (sighup_called && !child_killed)
      {
        log_error() << _("caught hangup signal, terminating...")
                  << endl;
        kill(pid, SIGHUP);
        this->chroot_status = false;
        child_killed = true;
      }

      if (wait(&status) != pid)
      {
        if (errno == EINTR && sighup_called)
          continue; // Kill child and wait again.
        else
          {
            format fmt(_("wait for child failed: %1%"));
            fmt % strerror(errno);
            throw error(fmt);
          }
      }
      else if (sighup_called)
      {
        sighup_called = false;
        throw error(_("caught hangup signal, terminating..."));
      }
      else
      break;
    }

  try
    {
      close_session();
    }
  catch (auth::error const& e)
    {
      throw error(e.what());
    }

  if (!WIFEXITED(status))
    {
      if (WIFSIGNALED(status))
      {
        format fmt(_("Child terminated by signal %1%"));
        fmt % strsignal(WTERMSIG(status));
        throw error(fmt);
      }
      else if (WCOREDUMP(status))
      throw error(_("Child dumped core"));
      else
      throw error(_("Child exited abnormally (reason unknown; not a signal or core dump)"));
    }

  child_status = WEXITSTATUS(status);

  if (child_status)
    {
      format fmt(_("Child exited abnormally with status '%1%'"));
      fmt % child_status;
      throw error(fmt);
    }
}


Generated by  Doxygen 1.6.0   Back to index