bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Killing processes on system shutdow


From: Moritz Schulte
Subject: Killing processes on system shutdow
Date: 23 Aug 2001 23:01:09 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

Hello,

a question regarding init/init.c::reboot_system(): Why do we only kill
processes, if we _are_ in a subhurd (i.e.: fakeboot is true)?

The code:

void
reboot_system (int flags)
{
  notify_shutdown ("shutdown");

  if (fakeboot)
    {
      pid_t *pp;
      u_int npids = 0;
      error_t err;
      int ind;

      err = proc_getallpids (procserver, &pp, &npids);
      if (err == MACH_SEND_INVALID_DEST)
        {
        procbad:
          /* The procserver must have died.  Give up. */
          error (0, 0, "Can't simulate crash; proc has died");
          reboot_mach (flags);
        }
      for (ind = 0; ind < npids; ind++)
        {
          task_t task;

          err = proc_pid2task (procserver, pp[ind], &task);
          if (err == MACH_SEND_INVALID_DEST)
            goto procbad;
          else  if (err)
            {
              error (0, err, "Getting task for pid %d", pp[ind]);
              continue;
            }

          /* Postpone self so we can finish; postpone proc
             so that we can finish. */
          if (task != mach_task_self () && task != proctask)
            {
              struct procinfo *pi = 0;
              u_int pisize = 0;
              char *noise;
              unsigned noise_len;
              int flags;
              err = proc_getprocinfo (procserver, pp[ind], &flags,
                                      (int **)&pi, &pisize,
                                      &noise, &noise_len);
              if (err == MACH_SEND_INVALID_DEST)
                goto procbad;
              if (err)
                {
                  error (0, err, "Getting procinfo for pid %d", pp[ind]);
                  continue;
                }
              if (!(pi->state & PI_NOPARENT))
                {
                  printf ("%s: Killing pid %d\n",
                          program_invocation_short_name, pp[ind]);
                  fflush (stdout);
                  task_terminate (task);
                }
              if (noise_len > 0)
                munmap (noise, noise_len);
            }
        }
      printf ("%s: Killing proc server\n", program_invocation_short_name);
      fflush (stdout);
      task_terminate (proctask);
      printf ("%s: Exiting", program_invocation_short_name);
      fflush (stdout);
    }
  reboot_mach (flags);
}

        moritz
-- 
Moritz Schulte <moritz@chaosdorf.de> http://www.chaosdorf.de/moritz/
Debian/GNU supporter - http://www.debian.org/ http://www.gnu.org/
GPG fingerprint = 3A14 3923 15BE FD57 FC06  B501 0841 2D7B 6F98 4199



reply via email to

[Prev in Thread] Current Thread [Next in Thread]