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 d

⟦2480c5823⟧ TextFile

    Length: 3932 (0xf5c)
    Types: TextFile
    Names: »delete.c«

Derivation

└─⟦9ae75bfbd⟧ Bits:30007242 EUUGD3: Starter Kit
    └─⟦653021b30⟧ »EurOpenD3/utils/downtime.tar.Z« 
        └─⟦946c717da⟧ 
            └─⟦this⟧ »delete.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: delete.c,v 4.1 88/07/05 15:59:14 mcooper Exp $";
#endif

/*
 *------------------------------------------------------------------
 *
 * $Source: /usr/skat3/src/common/usc/etc/downtime/RCS/delete.c,v $
 * $Revision: 4.1 $
 * $Date: 88/07/05 15:59:14 $
 * $State: Exp $
 *
 *------------------------------------------------------------------
 *
 * Michael A. Cooper
 * Research and Development Group
 * University Computing Services 
 * University of Southern California
 * (mcooper@oberon.USC.EDU)
 *
 *------------------------------------------------------------------
 *
 * $Log:	delete.c,v $
 * Revision 4.1  88/07/05  15:59:14  mcooper
 * Added copyright notice.
 * 
 * Revision 4.0  88/04/20  15:42:02  mcooper
 * Version 4.
 * 
 * Revision 3.5  88/04/19  18:27:01  mcooper
 * Use stmsg() to print status of what
 * we are doing.
 * 
 * Revision 3.4  88/04/15  16:13:02  mcooper
 * Use new flag bits (flags) D_KILL and
 * D_SENDCANCEL.
 * 
 * Revision 3.3  88/04/11  20:39:44  mcooper
 * Remove stupid calls to dot().
 * 
 * Revision 3.2  88/02/11  19:00:07  mcooper
 * Fixed bug that caused cancel messages
 * to be send when shutdown time arrived.
 * 
 * Revision 3.1  88/02/04  15:19:25  mcooper
 * - Fixed problem with sending a kill signal
 *   to a running downtime process.
 * - Now send cancel messages via cancelmsg().
 * 
 * Revision 3.0  87/07/24  14:16:21  mcooper
 * Version 3.
 * 
 *------------------------------------------------------------------
 */


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

/*
 * delete - Delete entry marked as "date".
 */
delete(date, flags)
char *date;
int flags;
{
  FILE *fd, *fdtmp;
  char buf[BUFSIZ], tmp[BUFSIZ];
  char *tmpfile = TMPFILE;
  struct downtime *d;

  dtrewind();

  if ((d = getdtdate(date)) == NULL) {
    fprintf(stderr, "No such entry as %s.\n", mkdate(dtot(date), D_DATE));
    return(-1);
  }

  if ((flags & FORCE) == 0) {
    printf("\n");
    prinfo(d);
    printf("\n");
    if (!yes("Delete"))
      return(-1);
  }

  if ((flags & QUIET) == 0) {
    printf("\n  Deleting [%s] ... ", mkdate(d->dt_down, D_DATE));
    fflush(stdout);
  }

  /*
   * nuke the PID, if any
   */
  if (flags & DOKILL && d->dt_islocked > 1) {
    stmsg("\n    Killing active PID ...");
    if (kill(d->dt_islocked, SIGKILL) < 0) {
      fprintf(stderr, "\nCould not kill PID %d: ", d->dt_islocked);
      perror("");
      fprintf(stderr, "\n");
    }
  }
      
  unlink(nologin);

  stmsg("\n    Remove motd message ...");
  /*
   * delete from motd if present
   */
  delmotd(d);

  stmsg("\n    Lock data file ...");
  if (dtfilelock() < 0) {
    return(-1);
  }

  dtclose();

  if ((fd = fopen(datafile, "r")) == NULL) {
    perror(datafile);
    return(-1);
  }

  mktemp(tmpfile);
  if ((fdtmp = fopen(tmpfile, "w")) == NULL) {
    perror(tmpfile);
    return(-1);
  }

  stmsg("\n    Scanning data file ...");
  while (fgets(buf, sizeof(buf), fd)) {
    sscanf(buf, "%s", tmp);
    if (strncmp(tmp, date, strlen(date))) 
      fputs(buf, fdtmp);
  }

  fclose(fd);
  fclose(fdtmp);

  if (unlink(datafile) < 0) {
    fprintf(stderr, "unlink: ");
    perror(datafile);
    return(-1);
  }

  if (rename(tmpfile, datafile) < 0) {
    fprintf(stderr, "rename: %s --> ", tmpfile);
    perror(datafile);
    return(-1);
  }

  stmsg("\n    Unlock data file ...");
  if (dtfileunlock() < 0) {
    return(-1);
  }

  /*
   * Tell everyone that it's been canceled.
   */
  if (flags & SENDCANCEL && !uflag) {
    stmsg("\n    Sending cancel messages ...");
    cancelmsg(d);
  }

  dtlog("DELETE: %s.", mkdate(d->dt_down, D_LOGFILE));

  if ((flags & QUIET) == 0) {
    printf("done.\n\n");
  }

  return(0);
}