-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlsb_strings.c
90 lines (80 loc) · 1.96 KB
/
lsb_strings.c
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
#include "lsb_strings.h"
/*
** Retuns a string describing the current job status
** This was 'stolen' from cmd.job.c as this function is
** not available from LSFs shared libraries
*/
char * get_job_status_desc(struct jobInfoEnt *job) {
char *status;
switch (job->status) {
case JOB_STAT_NULL:
status = "NULL";
break;
case JOB_STAT_PEND:
status = "PENDING";
break;
case JOB_STAT_PSUSP:
status = "PENDING JOB SUSPENDED";
break;
case JOB_STAT_RUN:
status = "RUNNING";
break;
case JOB_STAT_RUN | JOB_STAT_WAIT:
status = "WAITING";
break;
case JOB_STAT_SSUSP:
status = "SUSPENDED BY SYSTEM";
break;
case JOB_STAT_USUSP:
status = "SUSPENDED";
break;
case JOB_STAT_EXIT:
if (job->reasons & EXIT_ZOMBIE)
status = "ZOMBIE";
else
status = "EXITED";
break;
case JOB_STAT_DONE:
case JOB_STAT_DONE|JOB_STAT_PDONE:
case JOB_STAT_DONE|JOB_STAT_WAIT:
case JOB_STAT_DONE|JOB_STAT_PERR:
status = "DONE";
break;
case JOB_STAT_UNKWN:
status = "UNKNOWN STATUS";
break;
default:
status = "ERROR";
}
return status;
}
/*
** Parses LSF's RR string and extracts mem=XXXX
** WARNING: THIS RETURNS MB - MOST OTHER VALUES ARE IN KB
*/
int get_rr_mem(char *rr) {
char match[] = "mem="; /* prefix to search */
char *scr = NULL; /* scratch buffer-pointer */
int rmem = -1; /* return value -> requested memory */
int xoff = 0; /* offset of first integer value after mem= */
int mlen = strlen(match);
int rlen = strlen(rr);
int i;
for(i=mlen;i<rlen;i++) {
if(xoff == 0 && memcmp(&rr[i-mlen], match, mlen) == 0) {
xoff = i;
}
else if(xoff && (rr[i] < '0' || rr[i] > '9')) {
break;
}
}
if(xoff) { /* hit is between i <-> xoff */
if( (scr = malloc( 1+i-xoff )) != NULL &&
(snprintf(scr, 1+i-xoff, "%s", &rr[xoff])) > 0 ) {
rmem = atoi(scr);
}
}
if(scr != NULL)
free(scr);
return rmem;
}