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

Re: [MiNT] MiNT, CT60 and power off



> I've just checked the code and it seems there is no sync before
> shutdown.

Not true, it is even done twice. The sys_s_hutdown() calls shutdown(), and
this calls sys_s_ync() twice, i.e. before and after unmounting the disks.
BTW. you have these problems too?

/*
 * shut down processes; this involves waking them all up, and sending
 * them SIGTERM to give them a chance to clean up after themselves
 */
/*
 * This is the code that shuts the system down. It's no longer in
s_hutdown(),
 * as it's also called from main.c, where there has been a similar routine,
 * which missed some functionality (mainly invalidating/unmounting of
 * filesystems). Thus, ending the initial process and calling Shutdown() now
 * does exactly the same, and we've also removed some redundant code.
 */
static void
shutdown(void)
{
 struct proc *p;
 int posts = 0;
 int i;

 DEBUG(("shutdown() entered"));
 assert(curproc->p_sigacts);

 /* Ignore signals, that could terminate this process */
 SIGACTION(curproc, SIGCHLD).sa_handler = SIG_IGN;
 SIGACTION(curproc, SIGTERM).sa_handler = SIG_IGN;
 SIGACTION(curproc, SIGABRT).sa_handler = SIG_IGN;
 SIGACTION(curproc, SIGQUIT).sa_handler = SIG_IGN;
 SIGACTION(curproc, SIGHUP).sa_handler = SIG_IGN;

 for (p = proclist; p; p = p->gl_next)
 {
  /* Skip MiNT, curproc and AES */
  if (p->pid && (p != curproc) && ((p->p_mem->memflags & F_OS_SPECIAL) ==
0))
  {
   if (p->wait_q != ZOMBIE_Q && p->wait_q != TSR_Q)
   {
    if (p->wait_q && p->wait_q != READY_Q)
    {
     ushort sr = spl7();
     rm_q(p->wait_q, p);
     add_q(READY_Q, p);
     spl(sr);
    }

    DEBUG(("SIGTERM -> %s (pid %i)", p->name, p->pid));
    post_sig(p, SIGTERM);

    posts++;
   }
  }
 }

 while (posts--)
  for (i = 0; i < 16; i++) /* sleep */
   sys_s_yield();

 sys_q[READY_Q] = 0;

 DEBUG(("Close open files ..."));
 close_filesys();
 DEBUG(("done"));

 DEBUG(("Syncing file systems ..."));
 sys_s_ync();
 DEBUG(("done"));

 for (i = 0; i < NUM_DRIVES; i++)
 {
  FILESYS *fs = drives[i];

  if (fs)
  {
   if (fs->fsflags & FS_EXT_1)
   {
    DEBUG(("Unmounting %c: ...", 'A'+i));
    xfs_unmount(fs, i);
   }
   else
   {
    DEBUG(("Invalidate %c: ...", 'A'+i));
    xfs_dskchng(fs, i, 1);
   }
  }
 }

 DEBUG(("Syncing file systems ..."));
 sys_s_ync();
 DEBUG(("done"));
}

/*
 * where restart is:
 *
 * 0 = halt
 * 1 = warm start
 * 2 = cold start,
 * 3 = poweroff
 *
 */
long _cdecl
sys_s_hutdown(long restart)
{
 PROC *p = curproc;

 /* only root may shut down the system */
 if ((p->p_cred->ucr->euid == 0) || (p->p_cred->ruid == 0))
 {
  shutdown();

  switch (restart)
  {
   case  SHUT_POWER:
   {
    hw_poweroff();
    /* fall through */
   }
   case  SHUT_HALT:
   {
    DEBUG(("Halting system ..."));
    hw_halt();
   }
   case  SHUT_COLD:
   {
    hw_coldboot();
   }
   case  SHUT_BOOT:
   default:
   {
    DEBUG(("Rebooting ..."));
    hw_warmboot();
   }
  }

  /* not reached */
 }

 return EPERM;
}

--
CVV
Konrad M.Kokoszkiewicz, http://draco.atari.org

** Ea natura multitudinis est, aut seruit humiliter, aut superbe dominatur.
** Taka to już natura pospólstwa, albo służalczo się płaszczy,
** albo bezczelnie się panoszy. (T. Liuius XXIV, 25).