DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T b

⟦0f793450f⟧ TextFile

    Length: 4110 (0x100e)
    Types: TextFile
    Names: »bringdown.c«

Derivation

└─⟦9ae75bfbd⟧ Bits:30007242 EUUGD3: Starter Kit
    └─⟦653021b30⟧ »EurOpenD3/utils/downtime.tar.Z« 
        └─⟦946c717da⟧ 
            └─⟦this⟧ »bringdown.c« 

TextFile

/* 
 * Copyright (c) 1988 Michael A. Cooper, University of Southern California.
 * This program may be used, copied, modified, and redistributed freely
 * for noncommercial purposes, so long as this notice remains intact.
 */

#ifndef lint
static char *RCSid = "$Header: bringdown.c,v 4.1 88/07/05 15:58:13 mcooper Exp $";
#endif

/*
 *------------------------------------------------------------------
 *
 * $Source: /usr/skat3/src/common/usc/etc/downtime/RCS/bringdown.c,v $
 * $Revision: 4.1 $
 * $Date: 88/07/05 15:58:13 $
 * $State: Exp $
 *
 *------------------------------------------------------------------
 *
 * Michael A. Cooper
 * Research and Development Group
 * University Computing Services 
 * University of Southern California
 * (mcooper@oberon.USC.EDU)
 *
 *------------------------------------------------------------------
 *
 * $Log:	bringdown.c,v $
 * Revision 4.1  88/07/05  15:58:13  mcooper
 * Added copyright notice.
 * 
 * Revision 4.0  88/04/20  15:40:55  mcooper
 * Version 4.
 * 
 * Revision 3.3  88/04/19  18:39:39  mcooper
 * - Do more logging (ala syslog).
 * - Bring the system down with a simple
 *   call to kill(1, SIGTERM) instead of
 *   using -1.  This fixes the problems
 *   with shutting down if someone is in
 *   Suntools.
 * - If we are a 4.3BSD host, then pass
 *   the magically -l option to halt and
 *   reboot as 4.3BSD shutdown does.
 * 
 * Revision 3.2  88/04/11  19:47:36  mcooper
 * Converted all dt_flags to use flag
 * bits.
 * 
 * Revision 3.1  88/02/11  18:59:32  mcooper
 * Fixed bug that caused cancel messages
 * to be send when shutdown time arrived.
 * 
 * Revision 3.0  87/07/24  14:11:54  mcooper
 * Version 3.
 * 
 *------------------------------------------------------------------
 */


#include <stdio.h>
#include <signal.h>
#include "defs.h"
#include <syslog.h>

/*
 * bringdown - Actually bring the system down.
 */

bringdown(dt)
struct downtime *dt;
{
  FILE *fastd;
  char *ns = NULL;

  if (dt->dt_flags & F_NOSYNC)
    nosync = TRUE;
  else if (dt->dt_flags & F_FASTBOOT)
    fastboot = TRUE;

  if (nosync)
    ns = "-n";

  /*
   * log this downtime to the shutdown file
   */
  sdlog(dt);

  /*
   * log to downtime log file
   */
  dtlog("BRINGDOWN: %s%s%s.", mkdate(dt->dt_down, D_LOGFILE),
	(strcmp(dt->dt_reason, EMPTY)) ? " for " : "",
	(strcmp(dt->dt_reason, EMPTY)) ? dt->dt_reason : "");

  /*
   * delete the message for /etc/motd
   */
  delmotd(dt);

  if (fastboot) {
    if ((fastd = fopen(FASTBOOT, "w")) != NULL) {
      fprintf(fastd, "\n");
      fclose(fastd);
    }
  }

  delete(ttod(dt->dt_down), FORCE | QUIET);

  unlink(nologin);

  if (!(dt->dt_flags & F_FAKE) && !halt && !reboot && !killflg)
    dt->dt_flags |= F_FAKE;
  
  if (dt->dt_flags & F_FAKE) {
    printf("\nYou'll have to bring it down yourself!\n");
    finish();
    /*NOTREACHED*/
  }

#ifdef NEW_SYSLOG
  openlog("downtime", LOG_PID, LOG_AUTH);
#else
  openlog("downtime", LOG_PID);
#endif /* NEW_SYSLOG */

  syslog(LOG_CRIT, "%s by %s%s%s",
	 (dt->dt_flags & F_REBOOT) ? "reboot" :
	 (dt->dt_flags & F_HALT) ? "halt" : "shutdown",
	 dt->dt_shutter,
	 (strcmp(dt->dt_reason, EMPTY) == 0) ? "" : " for ",
	 (strcmp(dt->dt_reason, EMPTY) == 0) ? "" : dt->dt_reason
	 );
  closelog();
  sleep (2);

  unlink(nologin);

#ifndef DEBUG
  if (dt->dt_flags & F_REBOOT) {
#if defined(BSD) && BSD >= 43
    execle(REBOOT, "reboot", "-l", ns, 0, 0);
#else
    execle(REBOOT, "reboot", ns, 0, 0);
#endif /* BSD */
    perror(REBOOT);
  }

  if (dt->dt_flags & F_HALT) {
#if defined(BSD) && BSD >= 43
    execle(HALT, "halt", "-l", ns, 0, 0);
#else
    execle(HALT, "halt", ns, 0, 0);
#endif /* BSD */
    perror(HALT);
  }

  kill(1, SIGTERM);          /* terminate everyone */

#else
  if (dt->dt_flags & F_HALT)
    printf("HALT");
  if (dt->dt_flags & F_REBOOT)
    printf("REBOOT");
  if (fastboot)
    printf(" FASTBOOT");
  if (nosync)
    printf(" NOSYNC");

  printf(" kill -HUP 1\n");
#endif /* DEBUG */

  finish();
  /*NOTREACHED*/
}

/*
 * Cleanup and leave.
 */

finish()
{
  signal(SIGTERM, SIG_IGN);
  unlink(nologin);
  exit(0);
}