1: #include    <stdio.h>
   2: 
   3: #ifdef  RCSIDENT
   4: static char rcsid[] = "$Header: nfabort.c,v 1.7 85/01/18 15:40:50 notes Rel $";
   5: #endif	RCSIDENT
   6: 
   7: /*
   8:  *	nfabort(nf, message, title, cname, exitcode)
   9:  *
  10:  *	Dump a core file and leave it in "cname" suffixed with
  11:  *	the pid of the current process.  Place "message" and
  12:  *	a line about where the core dump is in "nf" with "title"
  13:  *	and then terminate with "exitcode" as an exit code.
  14:  *
  15:  *	Ray Essick,	February 1984
  16:  */
  17: 
  18: extern char *malloc ();
  19: 
  20: nfabort (nf, message, title, cname, exitcode)
  21: char   *nf;
  22: char   *message;
  23: char   *title;
  24: char   *cname;
  25: int     exitcode;
  26: {
  27:     int     mypid;
  28:     int     pid;
  29:     int     rpid;
  30:     int     retcode;
  31:     char    pbuf[256];                  /* char buffer */
  32:     char   *p;                      /* for message */
  33: 
  34:     if (message == NULL)                /* empty */
  35:     message = "";                   /* fake one */
  36:     if (cname == NULL || *cname == '\0')        /* make one */
  37:     cname = "core";
  38:     if (title == NULL || *title == '\0')        /* title */
  39:     title = "nfabort";
  40:     mypid = getpid ();
  41: 
  42:     switch (pid = fork ())
  43:     {
  44:     case -1:                    /* couldn't fork! */
  45:         fprintf (stderr, "nfabort() unable to log dump\n");
  46:         fflush (stderr);
  47:                             /* dump core anyway */
  48:     case 0:                     /* child */
  49:         umask (0);
  50:         abort ();                   /* die quick */
  51: 
  52:     default:                    /* parent */
  53:         while ((rpid = wait (&retcode)) != pid && rpid != -1);
  54:         sprintf (pbuf, "/bin/mv core %s.%d", cname, mypid);
  55:         system (pbuf);              /* move it */
  56:         sprintf (pbuf, "/bin/chmod 666 %s.%d", cname, mypid);
  57:         system (pbuf);              /* un-protect it */
  58:         sprintf (pbuf, "Core image left in %s.%d\n", cname, mypid);
  59:         p = malloc (strlen (message) + strlen (pbuf) + 4);
  60:         if (p == NULL)              /* no space */
  61:         p = message;                /* write something */
  62:         else
  63:         sprintf (p, "%s\n\n%s", message, pbuf);
  64:         if (nf)                 /* only if given */
  65:         nfcomment (nf, p, title, 0, 0);     /* and log it */
  66:         exit (exitcode);
  67:     }
  68: }

Defined functions

nfabort defined in line 20; used 1 times

Defined variables

rcsid defined in line 4; never used
Last modified: 1985-07-19
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 309
Valid CSS Valid XHTML 1.0 Strict