File: cmdps.c

package info (click to toggle)
xshipwars 1.32-5
  • links: PTS
  • area: main
  • in suites: potato
  • size: 17,176 kB
  • ctags: 6,357
  • sloc: ansic: 157,152; makefile: 226; sh: 75
file content (79 lines) | stat: -rw-r--r-- 1,955 bytes parent folder | download
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
#include "swserv.h"
  
 
/*
 *      List processes.
 *      
 *      NOTE: This function is not completely formalized,
 *      information sent to connection is not standard.  
 */
int CmdPS(int condescriptor, char *arg)
{
        char sndbuf[CS_DATA_MAX_LEN];
        int schedual_num;
        char can_view_others;
        int uid;
        long object_num;
        int processes_listed;
        schedual_struct **shptr;
        
        
        /* Get object number. */
        object_num = connection[condescriptor]->object_num;
        if(DBIsObjectGarbage(object_num))
            return(-1);


        /* Get uid. */
        uid = xsw_object[object_num]->permission.uid;

        /* Can connection view processes that belong to others? */
        can_view_others = (uid > ACCESS_UID_PSO) ? 0 : 1;


        /* Print header. */
        NetSendLiveMessage(
            condescriptor,
            "-   PID  STAT     INT  USER"
        );


        /* Begin printing schedualed events. */
        processes_listed = 0;
        shptr = (schedual_struct **)schedual;
        for(schedual_num = 0;
            schedual_num < total_scheduals;
            schedual_num++, shptr++
        )
        {
            if(!SchedualIsActive(schedual_num)) continue;

            /* Check if allowed to view others. */
            if((object_num != (*shptr)->run_owner) &&
               !can_view_others
            )
                continue;


            /* Print line. */
            sprintf(sndbuf, "-%6d  %4d  %6ld  %s",
                schedual_num,
                1,
                (*shptr)->act_int,
                DBGetFormalNameStr((*shptr)->run_owner)
            );
            NetSendLiveMessage(condescriptor, sndbuf);

            processes_listed++;
        }


        /* Print footer. */
        sprintf(sndbuf, "%i processes.",
            processes_listed
        );
        NetSendLiveMessage(condescriptor, sndbuf);


        return(0);
}