home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume13 / backups / proclist.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-01-31  |  3.1 KB  |  165 lines

  1. static char rcsid[] = "$Header: proclist.c,v 1.6 87/05/25 16:55:54 scooter Exp $";
  2.  
  3. /*
  4.  * proclist
  5.  *
  6.  * This routine returns a list of candidate procedures for
  7.  * killing.
  8.  *
  9.  * $Log:    proclist.c,v $
  10.  * Revision 1.6  87/05/25  16:55:54  scooter
  11.  * Added Appleshare stuff to "special processing" list
  12.  * 
  13.  * Revision 1.5  86/10/15  09:26:13  scooter
  14.  * Added syslogd to the exclusion list
  15.  * 
  16.  * Revision 1.4  86/10/14  01:33:46  scooter
  17.  * Added process specific startup/shutdown stuff
  18.  * 
  19.  *
  20.  */
  21.  
  22. #include "backup.h"
  23. #include "ulist.h"
  24. #include <stdio.h>
  25.  
  26. /*
  27.  * Table of offsets for portions of the ps -l line
  28.  */
  29.  
  30. #define    UID    7
  31. #define    PID    12
  32. #define    PPID    18
  33. #define    STAT    61
  34. #define    CMD    75
  35.  
  36. /*
  37.  * List of processes to exclude
  38.  */
  39.  
  40. char    *exlist[] =
  41.     { "init",
  42.       "swapper",
  43.       "pagedaemon",
  44.       "/etc/timed",
  45.       "/etc/named",
  46.       "/etc/syslogd",
  47.       "/etc/atalkad",        /* Kinetics route info server */
  48.       "/usr/local/lib/lsrv",    /* Appletalk spooler */
  49.       "/usr/local/lib/atis",    /* Appletalk name server */
  50.       "- std.9600",
  51.       "- std.4800",
  52.       "- std.1200",
  53.       "- P4800",
  54.       "- P1200",
  55.       "- D1200",
  56.       "- Console",
  57.       0 };
  58.  
  59. /*
  60.  * Processes which require special shutdown/restart
  61.  */
  62.  
  63. struct    proc_struct 
  64. {
  65.     char    *pr_name;
  66.     char    *pr_shutdown;
  67.     char    *pr_restart;
  68. } special_procs[] = {
  69.     {"/etc/rjecop","opr 0 .d","/etc/hsp_reload"},
  70.     {"genie Aufs Daemon","kill -TERM %d","cd /usr/adm;/usr/local/lib/aufs -V AppleSharePublicVolumes -U 20"},
  71.     {"jinn Aufs Daemon","kill -TERM %d","cd /usr/adm;/usr/local/lib/aufs -U 20"},
  72.     {0,0,0}
  73. };
  74.  
  75. struct ulist *
  76. proclist()
  77. {
  78.     struct ulist *head=NULL;
  79.     struct ulist *tail=NULL;
  80.     FILE *pschan,*popen();
  81.     char string[180],*tmp,*rindex();
  82.     int i,ex_flag;
  83.  
  84.     pschan = popen("/bin/ps -lgaxw","r");
  85.     if (pschan == NULL)
  86.     {
  87.         fprintf(stderr,"*** Unable to get ps listing ***");
  88.         exit (1);
  89.     }
  90.  
  91.     fgets(string,180,pschan);    /* Skip the header */
  92.  
  93.     while ( fgets(string,180,pschan) != NULL )
  94.     {
  95.  
  96.         /*
  97.          * Check for excluded processes
  98.          */
  99.  
  100.         i = ex_flag = 0;
  101.  
  102.         while ( tmp = exlist[i++] )
  103.         {
  104.             if (!strncmp(string+CMD,tmp,strlen(tmp)))
  105.             {
  106.                 ex_flag = 1;
  107.                 break;
  108.             }
  109.         }
  110.  
  111.         if (ex_flag) continue;
  112.  
  113.         if (head == NULL)
  114.         {
  115.             head = tail = (struct ulist *)
  116.                 malloc(sizeof(struct ulist));
  117.         } else
  118.         {
  119.             tail->next = (struct ulist *)
  120.                 malloc(sizeof(struct ulist));
  121.             tail = tail->next;
  122.         }
  123.  
  124.         tail->uid = atoi(string+UID);
  125.         tail->pid = atoi(string+PID);
  126.         tail->ppid = atoi(string+PPID);
  127.         strncpy(tail->stat,string+STAT,4);
  128.         strncpy(tail->cmd,string+CMD,39);
  129.         tmp = rindex(tail->cmd,'\n');
  130.         if (tmp != NULL)*tmp = '\0';
  131.         tail->special_flag = 0;
  132.         tail->next = NULL;
  133.  
  134.         /*
  135.          * Check for special shutdown/startup
  136.          */
  137.         
  138.         i = 0;
  139.         while ( tmp = special_procs[i].pr_name )
  140.         {
  141.             if (!strncmp(tail->cmd,tmp,strlen(tmp)))
  142.             {
  143.                 tail->special_flag++;
  144.                 
  145.                 /* Allow single argument (pid) -- this will allow special signals */
  146.                 sprintf(tail->proc_shutdn, special_procs[i].pr_shutdown, tail->pid);
  147.                 sprintf(tail->proc_restart, special_procs[i].pr_restart, tail->pid);
  148.                 break;
  149.             }
  150.             i++;
  151.         }
  152.  
  153.  
  154. #ifdef    DEBUG
  155.         if (x_opt)
  156.             printf("%6d, %6d, %6d, %4s, %s\n",tail->uid,tail->pid,
  157.                     tail->ppid,tail->stat,tail->cmd);
  158. #endif    DEBUG
  159.  
  160.     }
  161.     pclose(pschan);
  162.  
  163.     return(head);
  164. }
  165.