home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume4 / sco-crash / crash.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-03  |  3.5 KB  |  221 lines

  1. #include <sys/param.h>
  2. #include <sys/sysmacros.h>
  3. #include <sys/types.h>
  4. #include <sys/page.h>
  5. #include <sys/seg.h>
  6. #include <sys/proc.h>
  7. #include <sys/signal.h>
  8. #include <sys/dir.h>
  9. #include <sys/user.h>
  10. #include <sys/var.h>
  11. #include <sys/utsname.h>
  12. #include <fcntl.h>
  13. #include <stdio.h>
  14. #include "crash.h"
  15.  
  16. int    memfd;
  17. int    kmemfd;
  18. int    swapfd;
  19.  
  20. int    bflag;
  21. int    fflag;
  22. int    iflag;
  23. int    mflag;
  24. int    pflag;
  25. int    sflag;
  26. int    tflag;
  27. int    uflag;
  28. int    vflag;
  29.  
  30. int    anyflag;
  31.  
  32. struct    var    v;
  33. struct    file    *files;
  34. struct    inode    *inodes;
  35. struct    text    *texts;
  36. struct    proc    *procs;
  37. struct    mount    *mounts;
  38. struct    buf    *bufs;
  39. struct    buf    *bufstart;
  40. struct    user    user;
  41. daddr_t    swplo;
  42. struct    utsname    utsname;
  43. time_t    ktime;
  44. time_t    klbolt;
  45.  
  46. struct    xlist    namelist[] = {
  47.     { 0, 0, 0, "_v" },
  48.     { 0, 0, 0, "_file" },
  49.     { 0, 0, 0, "_inode" },
  50.     { 0, 0, 0, "_proc" },
  51.     { 0, 0, 0, "_text" },
  52.     { 0, 0, 0, "_mount" },
  53.     { 0, 0, 0, "_bufstrt" },
  54.     { 0, 0, 0, "_swplo" },
  55.     { 0, 0, 0, "_time" },
  56.     { 0, 0, 0, "_lbolt" },
  57.     { 0, 0, 0, "_utsname" },
  58.     { 0, 0, 0, "_u" },
  59.     { 0, 0, 0, (char *) 0 }
  60. };
  61.  
  62. usage ()
  63. {
  64.     fprintf (stderr, "usage: crash -bfimpstv [ -N namelist ] ");
  65.     fprintf (stderr, "[ -C corefile ] [ -S swapfile ]\n");
  66.     exit (1);
  67. }
  68.  
  69. r_read (fd, buf, n)
  70. int    fd;
  71. char    *buf;
  72. int    n;
  73. {
  74.     int    i;
  75.  
  76.     if ((i = read (fd, buf, n)) == -1) {
  77.         perror ("error on read");
  78.         return (-1);
  79.     } else
  80.         return (i);
  81. }
  82.  
  83. long    l_lseek (fd, offs, whence)
  84. int    fd;
  85. long    offs;
  86. int    whence;
  87. {
  88.     long    i;
  89.     long    lseek ();
  90.  
  91.     if ((i = lseek (fd, offs, whence)) == -1L) {
  92.         perror ("error on lseek");
  93.         return (-1);
  94.     } else
  95.         return (i);
  96. }
  97.  
  98. main (argc, argv)
  99. int    argc;
  100. char    **argv;
  101. {
  102.     char    newname[10];
  103.     char    *namefile = "/xenix";
  104.     char    *corefile = "/dev/mem";
  105.     char    *kmemfile = "/dev/kmem";
  106.     char    *swapfile = "/dev/swap";
  107.     int    c;
  108.     extern    int    optind;
  109.     extern    char    *optarg;
  110.  
  111.     setbuf (stdout, NULL);
  112.     setbuf (stderr, NULL);
  113.  
  114.     while ((c = getopt (argc, argv, "bfimpstuvN:C:S:")) != EOF) {
  115.         switch (c) {
  116.             case 'b':
  117.                 bflag++;
  118.                 anyflag++;
  119.                 break;
  120.             case 'C':
  121.                 corefile = optarg;
  122.                 kmemfile = optarg;
  123.                 break;
  124.             case 'f':
  125.                 fflag++;
  126.                 anyflag++;
  127.                 break;
  128.             case 'i':
  129.                 iflag++;
  130.                 anyflag++;
  131.                 break;
  132.             case 'm':
  133.                 mflag++;
  134.                 anyflag++;
  135.                 break;
  136.             case 'N':
  137.                 namefile = optarg;
  138.                 break;
  139.             case 'p':
  140.                 pflag++;
  141.                 anyflag++;
  142.                 break;
  143.             case 's':
  144.                 sflag++;
  145.                 anyflag++;
  146.                 break;
  147.             case 'S':
  148.                 swapfile = optarg;
  149.                 break;
  150.             case 't':
  151.                 tflag++;
  152.                 anyflag++;
  153.                 break;
  154.             case 'u':
  155.                 uflag++;
  156.                 anyflag++;
  157.                 break;
  158.             case 'v':
  159.                 vflag++;
  160.                 anyflag++;
  161.                 break;
  162.             default:
  163.                 usage ();
  164.         }
  165.     }
  166.     if (xlist (namefile, namelist) != 0) {
  167.         perror ("pstat: namelist");
  168.         exit (1);
  169.     }
  170.     if ((memfd = open (corefile, O_RDONLY)) < 0) {
  171.         perror ("pstat: corefile");
  172.         exit (1);
  173.     }
  174.     if ((kmemfd = open (kmemfile, O_RDONLY)) < 0) {
  175.         perror ("pstat: kmemfile");
  176.         exit (1);
  177.     }
  178.     if ((swapfd = open (swapfile, O_RDONLY)) < 0) {
  179.         perror ("pstat: swapfile");
  180.         exit (1);
  181.     }
  182.     l_lseek (kmemfd, namelist[NM_V].xl_value, 0);
  183.     r_read (kmemfd, &v, sizeof v);
  184.     l_lseek (kmemfd, namelist[NM_SWPLO].xl_value, 0);
  185.     r_read (kmemfd, &swplo, sizeof swplo);
  186.  
  187.     if (bflag)
  188.         prbufs ((int *) 0, 0);
  189.  
  190.     if (fflag)
  191.         prfiles ((int *) 0, 0);
  192.  
  193.     if (iflag)
  194.         prinodes ((int *) 0, 0);
  195.  
  196.     if (mflag) 
  197.         prmounts ((int *) 0, 0);
  198.  
  199.     if (pflag)
  200.         prprocs ((int *) 0, 0);
  201.  
  202.     if (sflag)
  203.         prstats ((int *) 0, 0);
  204.  
  205.     if (tflag)
  206.         prtexts ((int *) 0, 0);
  207.  
  208.     if (uflag)
  209.         prusers ((int *) 0, 0);
  210.  
  211.     if (vflag)
  212.         prvars ((int *) 0, 0);
  213.  
  214.     if (! anyflag) {
  215.         interact ();
  216.         exit (0);
  217.     } else {
  218.         exit (0);
  219.     }
  220. }
  221.