home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / A / PS / PROCPS-0.000 / PROCPS-0 / procps-0.97 / gfinger.patch < prev    next >
Encoding:
Internet Message Format  |  1993-03-15  |  5.1 KB

  1. Return-Path: <qpliu@ulch.Princeton.EDU>
  2. Date: Wed, 24 Feb 93 23:37:45 -0500
  3. From: qpliu@ulch.Princeton.EDU (Quowong P Liu)
  4. To: johnsonm@stolaf.edu
  5. Subject: Suggestions for procps
  6. Reply-To: qpliu@princeton.edu
  7.  
  8. [...]
  9.  
  10. Since you are collecting programs that use the proc-fs, I have included
  11. some patches to GNU finger that allow it to read the proc information
  12. that it uses.
  13.  
  14. [...]
  15.  
  16. Here the diffs for GNU finger begin.
  17. -------------BEGIN---------------
  18. diff -ru finger-1.37.orig/lib/os.c finger-1.37/lib/os.c
  19. --- finger-1.37.orig/lib/os.c    Thu Oct 22 17:01:10 1992
  20. +++ finger-1.37/lib/os.c    Mon Feb  8 00:56:32 1993
  21. @@ -23,7 +23,9 @@
  22.  #include <sys/types.h>
  23.  #include <sys/stat.h>
  24.  #include <sys/file.h>
  25. +#ifndef linux
  26.  #include <sys/acct.h>
  27. +#endif
  28.  #include <time.h>
  29.  #include <packet.h>
  30.  
  31. @@ -43,9 +45,11 @@
  32.  
  33.  #ifdef HAVE_PROC_FS
  34.  #include <sys/signal.h>
  35. +#ifndef linux
  36.  #include <sys/fault.h>
  37.  #include <sys/syscall.h>
  38.  #include <sys/procfs.h>
  39. +#endif /*linux*/
  40.  #endif
  41.  
  42.  #include <general.h>
  43. @@ -193,6 +197,7 @@
  44.    long idle, current_time, get_last_access ();
  45.    char *hostname, *ttyloc, *tty_location ();
  46.  #ifdef HAVE_PROC_FS
  47. +#ifndef linux
  48.    prpsinfo_t procinfo;
  49.    struct procent
  50.      {
  51. @@ -202,6 +207,16 @@
  52.        char fname[sizeof (procinfo.pr_fname)];
  53.      }
  54.    *proctable, *tableptr;
  55. +#else
  56. +  struct procent
  57. +    {
  58. +      time_t start;
  59. +      int uid;
  60. +      dev_t tty;
  61. +      char fname[15];
  62. +    }
  63. +  *proctable, *tableptr;
  64. +#endif /* linux */
  65.    int nprocs = 0;
  66.  #endif /* HAVE_PROC_FS */
  67.        
  68. @@ -235,6 +250,7 @@
  69.       searching through user list. */
  70.  
  71.  #ifdef HAVE_PROC_FS
  72. +#ifndef linux
  73.    {
  74.      extern char *savedir ();
  75.      char *dirstring = savedir ("/proc", 2*1024, &nprocs);
  76. @@ -280,6 +296,64 @@
  77.      free (dirstring);
  78.        }
  79.    }
  80. +#else /* linux */
  81. +  {
  82. +
  83. +    extern char *savedir ();
  84. +    char *dirstring = savedir ("/proc", 2*1024, &nprocs);
  85. +    char *proc;
  86. +    int procfd;
  87. +    char procfile[17], procstatbuffer[1024];
  88. +    struct stat proc_fs_stat;
  89. +    char procstate;
  90. +    int tmp_tty; /* dev_t is unsigned, -1 means no controlling tty */
  91. +    
  92. +    /* Allocate process table */
  93. +    if (nprocs)
  94. +      proctable = (struct procent *) xmalloc (sizeof *proctable * nprocs);
  95. +
  96. +    /* Walk processes */
  97. +    if (dirstring && nprocs)
  98. +      {
  99. +    for (tableptr = proctable, proc = dirstring;
  100. +         *proc; proc += strlen (proc) + 1)
  101. +      {
  102. +        sprintf (procfile, "/proc/%.5s/stat", proc);
  103. +
  104. +        if ((procfd = open (procfile, O_RDONLY)) >= 0
  105. +        && read (procfd, procstatbuffer, 1024))
  106. +          {
  107. +        /* see /usr/src/linux/fs/proc/array.c
  108. +         * this is for 0.99.4
  109. +         */
  110. +        sscanf (procstatbuffer, "%*d (%14s %c %*d %*d %*d %d "
  111. +            "%*d %*u %*u %*u %*u %*u %*d %*d %*d %*d %*d %*d %*u "
  112. +            "%*u %hd" /* " %*u %*u %*u %*u %*u %*u %*u %*u %*d %*d "
  113. +            "%*d %*d %*u" */,
  114. +            tableptr->fname, &procstate, &tmp_tty,
  115. +            &tableptr->start);
  116. +        tableptr->fname[strlen(tableptr->fname)-1] = 0; /*trailing )*/
  117. +        tableptr->tty = tmp_tty;
  118. +        if (fstat (procfd, &proc_fs_stat) == 0)
  119. +            tableptr->uid = proc_fs_stat.st_uid;
  120. +
  121. +        /* Only collect non-zombies with controlling tty */
  122. +        if (tmp_tty > 0 && procstate != 'Z')
  123. +          {
  124. +            tableptr++;
  125. +          }
  126. +        else
  127. +          nprocs--;
  128. +        
  129. +        close (procfd);
  130. +          }
  131. +        else
  132. +          nprocs--;
  133. +      }
  134. +    free (dirstring);
  135. +      }
  136. +  }
  137. +#endif /* linux */
  138.  #endif /* HAVE_PROC_FS */
  139.  
  140.  
  141. @@ -332,10 +406,14 @@
  142.  
  143.          if (stat (device_name, &finfo) != -1)
  144.            {
  145. +#ifdef linux
  146. +        dev_t tty = finfo.st_rdev&0xff;
  147. +#else
  148.  #ifdef HAVE_ST_RDEV
  149.          dev_t tty = finfo.st_rdev;
  150.  #else
  151.          dev_t tty = finfo.st_dev;
  152. +#endif
  153.  #endif
  154.          int file;
  155.  
  156. diff -ru finger-1.37.orig/lib/packet.c finger-1.37/lib/packet.c
  157. --- finger-1.37.orig/lib/packet.c    Wed Oct 21 18:04:38 1992
  158. +++ finger-1.37/lib/packet.c    Mon Feb  8 01:10:00 1993
  159. @@ -348,7 +348,9 @@
  160.        perror (filename);
  161.      }
  162.  
  163. +#ifndef linux /* doesn't have fsync (as of .99.4) */
  164.    fsync (file);
  165. +#endif
  166.    close (file);
  167.  }
  168.  
  169. diff -ru finger-1.37.orig/lib/savedir.c finger-1.37/lib/savedir.c
  170. --- finger-1.37.orig/lib/savedir.c    Fri Oct 16 21:52:40 1992
  171. +++ finger-1.37/lib/savedir.c    Mon Feb  8 01:06:47 1993
  172. @@ -132,7 +132,7 @@
  173.  char *
  174.  stpcpy (dest, source)
  175.       char *dest;
  176. -     char *source;
  177. +     const char *source; /* gcc insists on prototype consistency */
  178.  {
  179.    while ((*dest++ = *source++) != '\0')
  180.      /* Do nothing. */ ;
  181. diff -ru finger-1.37.orig/src/finger.c finger-1.37/src/finger.c
  182. --- finger-1.37.orig/src/finger.c    Wed Oct 21 20:41:13 1992
  183. +++ finger-1.37/src/finger.c    Mon Feb  8 00:56:32 1993
  184. @@ -192,6 +192,9 @@
  185.    long addr;
  186.    char *finger_server = NULL;
  187.    int suppress_hostname = 0;
  188. +#if defined(linux) /* gethostbyaddr evidently returns pointer to static area */
  189. +  int do_hostfree = 0;
  190. +#endif /* linux */
  191.  
  192.  
  193.    username = savestring (arg);
  194. @@ -237,6 +240,9 @@
  195.      {
  196.        host = (struct hostent *) xmalloc (sizeof (struct hostent));
  197.        host->h_name = hostname;
  198. +#if defined (linux)
  199. +      do_hostfree = 1;
  200. +#endif /* linux */
  201.      }
  202.      }
  203.    else
  204. @@ -296,6 +302,11 @@
  205.    if (finger_server)
  206.      free (finger_server);
  207.  
  208. +#if !defined (linux)
  209.    if (host)
  210.      free (host);
  211. +#else
  212. +  if (host && do_hostfree)
  213. +    free (host);
  214. +#endif
  215.  }
  216. -------------END-------------
  217.