File: SunOS.c

package info (click to toggle)
libproc-processtable-perl 0.637-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 672 kB
  • sloc: ansic: 5,765; perl: 568; makefile: 15
file content (96 lines) | stat: -rw-r--r-- 2,324 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * Copyright (c) 2001 by Shawn A. Clifford <shawn.a.clifford@lmco.com>
 * This file may be distributed under the same terms as Perl.
 *
 * Modification History:
 *
 * Who	When		Description
 * ---	----------	--------------------------------------------
 * SAC	30July2001	Original code
 */

#include "os/SunOS.h"

char* OS_initialize(void) {
    return NULL;
}

void OS_get_table(void) {
   struct proc *p;
   struct user *u;
   struct ucred cr;
   struct sess sess;
   char **arg;
   char **env;
   char cmdline[_POSIX_ARG_MAX];
   char fname[_POSIX_PATH_MAX];
   kvm_t *kd;
   int i, count;
   int ttynum;
        
   /* Open the kernel for reading */
   if ((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL)) == NULL) {
      ppt_croak("kvm_open: can't open kernel");
   }
   
   /*
    *  Loop over all processes
    */ 
   while ((p = kvm_nextproc(kd)) != NULL) {
     
      /* Get the u-area for this process or skip this process */
      if ((u = kvm_getu(kd, p)) == NULL) continue;

      /* Get the command line arguments for this process or skip */
      bzero(fname, sizeof(fname));
      if (kvm_getcmd(kd, p, u, &arg, &env) < 0) {
         sprintf(fname, "%s", u->u_comm);
         sprintf(cmdline, "%s", u->u_comm);
      } else {
         sprintf(fname, "%s", arg[0]);
         bzero(cmdline, sizeof(cmdline));
         i=0;
         while (arg[i] != NULL) {
            count = sizeof(cmdline) - strlen(cmdline) - 1;
            strncat(cmdline, arg[i++], count);
            if (arg[i] != NULL) strcat(cmdline, " ");
         }
      }
      
      /* Get the process credentials */
      if (kvm_read(kd, p->p_cred, &cr, sizeof(struct ucred)) < 0) continue;

      /* Get the session info */
      kvm_read(kd, p->p_sessp, &sess, sizeof(struct sess));
      ttynum = minor(sess.s_ttyd);
      if (major(sess.s_ttyd) == 0) ttynum = -1;
      
      /* Send if off to Perl */
      bless_into_proc(  Format,
			Fields,
			cr.cr_ruid,
			cr.cr_rgid,
			cr.cr_uid,
			cr.cr_gid,
			p->p_pid,
			p->p_ppid,
			p->p_pgrp,
			p->p_pri,
			p->p_flag,
			(p->p_dsize+p->p_ssize)*4,
			p->p_rssize*4,
			p->p_nice,
			p->p_time,
			fname,
			cmdline,
			p->p_cpticks,
			p->p_pctcpu,
			States[(int)p->p_stat],
			sess.s_sid,
			sess.s_sid,
			ttynum );
   }

   /* Close the kernel and exit */
   kvm_close(kd);
}