File: cmdmemory.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 (198 lines) | stat: -rw-r--r-- 4,974 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include "swserv.h"

#define THIS_CMD_NAME	"memory"
  
 
/*
 *      Print, refresh, or reload items in memory
 *      (not counting processes).
 */
int CmdMemory(int condescriptor, char *arg)
{
	int i, status;
        char sndbuf[CS_DATA_MAX_LEN];
        long total_mem,
             aux_mem,  
             connection_mem,
             objects_mem,   
             recycle_buf_mem,
             opm_mem,
             ocs_mem,
             schedual_mem;
        long con_object_num;
	xsw_object_struct *con_obj_ptr;


        /* Get connection's object number (assumed valid). */
        con_object_num = connection[condescriptor]->object_num;
	con_obj_ptr = xsw_object[con_object_num];


        /* Check if allowed to view memory. */
        if(con_obj_ptr->permission.uid > ACCESS_UID_MEM)
        {
            sprintf(sndbuf,
   "%s: Access level %i: Permission denied.",
                THIS_CMD_NAME, ACCESS_UID_MEM
            );
            NetSendLiveMessage(condescriptor, sndbuf);
            return(-1);
        }


        /* Calculate memory being used. */
        SWServGetMemoryStats(
            &total_mem,
            &aux_mem,
            &connection_mem,
            &objects_mem,
            &recycle_buf_mem,
            &opm_mem,  
            &ocs_mem,  
            &schedual_mem   
        );
             
             
        /* Print memory stats. */
        if((arg == NULL) ? 1 : (arg[0] == '\0'))
        {
            sprintf(sndbuf,
"-        total       con      objs    recbuf      opms      ocss scheduals"
            );
            NetSendLiveMessage(condescriptor, sndbuf);

            sprintf(sndbuf,
"Mem:\
 %9ld\
 %9ld\
 %9ld\
 %9ld\
 %9ld\
 %9ld\
 %9ld",
                total_mem,
                connection_mem,
                objects_mem,
                recycle_buf_mem,
                opm_mem,
                ocs_mem,
                schedual_mem
            );
            NetSendLiveMessage(condescriptor, sndbuf);
            
            sprintf(sndbuf,
"Ent:\
 %9ld\
 %9d\
 %9ld\
 %9d\
 %9d\
 %9d\
 %9d",   
        
                total_objects + total_connections + total_recycled_objects +
                total_opms + total_ocss,
            
                total_connections,
                total_objects,
                total_recycled_objects,
                total_opms,
                total_ocss,
                total_scheduals
            );
            NetSendLiveMessage(condescriptor, sndbuf);


            /* Print usage at end. */ 
            sprintf(
                sndbuf,
                "Usage: `%s [reload|refresh|reload_universe]'",
                THIS_CMD_NAME
            );
            NetSendLiveMessage(condescriptor, sndbuf);
 

            return(0);
        }

 
        /* ********************************************************** */

        /* Reset memory? */
        if(!strcasecmp(arg, "reset") ||
           !strcasecmp(arg, "reload")
	)
        {
            /* Permission check. */
            if(con_obj_ptr->permission.uid > ACCESS_UID_MEMOP)
            {
                sprintf(
		    sndbuf,
 "%s: Requires access level %i: Permission denied.",
		    THIS_CMD_NAME, ACCESS_UID_MEMOP
                );
                NetSendLiveMessage(condescriptor, sndbuf);
                return(-1);
            }

	    /* Set master reset to 2 so that the configuration will
	     * be reloaded.  The universe database file will NOT be
	     * reloaded.
	     */
	    master_reset = 2;
        }
        /* Refresh objects in memory. */
        else if(!strcasecmp(arg, "refresh"))
        {
	    /* Permission check. */
            if(con_obj_ptr->permission.uid > ACCESS_UID_MEMOP)
            {
                sprintf(
                    sndbuf,
 "%s: Requires access level %i: Permission denied.",
                    THIS_CMD_NAME, ACCESS_UID_MEMOP
                );
                NetSendLiveMessage(condescriptor, sndbuf);
                return(-1);
            }

            /* Set master reset to 1 so that the memory will be
	     * refreshed.
	     */
	    master_reset = 1;
        }
        /* Reload input universe file. */
        else if(strpfx(arg, "reload_universe"))
        {
            /* Permission check. */
            if(con_obj_ptr->permission.uid > ACCESS_UID_MEMRELOADUNV)
            {
                sprintf(
                    sndbuf,   
 "%s: Requires access level %i: Permission denied.",
                    THIS_CMD_NAME, ACCESS_UID_MEMRELOADUNV
                );
                NetSendLiveMessage(condescriptor, sndbuf);
                return(-1);
            }

	    /* Set master reset to 3 so that the universe database
	     * will be reloaded from the universe in file.
	     */
	    master_reset = 3;
        }
	/* Unsupported operation. */
	else
	{
	    sprintf(
		sndbuf,
		"%s: %s: Unsupported operation.",
		THIS_CMD_NAME, arg
	    );
	    NetSendLiveMessage(condescriptor, sndbuf);
	}


        return(0);
}