Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
htop
Commits
ffcf48fb
Commit
ffcf48fb
authored
Feb 02, 2016
by
Hisham
Browse files
Merge branch 'xalloc'
parents
301c346c
b54d2dde
Changes
43
Show whitespace changes
Inline
Side-by-side
ScreenManager.c
View file @
ffcf48fb
...
...
@@ -46,7 +46,7 @@ typedef struct ScreenManager_ {
ScreenManager
*
ScreenManager_new
(
int
x1
,
int
y1
,
int
x2
,
int
y2
,
Orientation
orientation
,
const
Header
*
header
,
const
Settings
*
settings
,
bool
owner
)
{
ScreenManager
*
this
;
this
=
m
alloc
(
sizeof
(
ScreenManager
));
this
=
xM
alloc
(
sizeof
(
ScreenManager
));
this
->
x1
=
x1
;
this
->
y1
=
y1
;
this
->
x2
=
x2
;
...
...
Settings.c
View file @
ffcf48fb
...
...
@@ -96,7 +96,7 @@ static void Settings_readMeterModes(Settings* this, char* line, int column) {
len
++
;
}
this
->
columns
[
column
].
len
=
len
;
int
*
modes
=
c
alloc
(
len
,
sizeof
(
int
));
int
*
modes
=
xC
alloc
(
len
,
sizeof
(
int
));
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
modes
[
i
]
=
atoi
(
ids
[
i
]);
}
...
...
@@ -110,27 +110,27 @@ static void Settings_defaultMeters(Settings* this) {
sizes
[
1
]
++
;
}
for
(
int
i
=
0
;
i
<
2
;
i
++
)
{
this
->
columns
[
i
].
names
=
c
alloc
(
sizes
[
i
]
+
1
,
sizeof
(
char
*
));
this
->
columns
[
i
].
modes
=
c
alloc
(
sizes
[
i
],
sizeof
(
int
));
this
->
columns
[
i
].
names
=
xC
alloc
(
sizes
[
i
]
+
1
,
sizeof
(
char
*
));
this
->
columns
[
i
].
modes
=
xC
alloc
(
sizes
[
i
],
sizeof
(
int
));
this
->
columns
[
i
].
len
=
sizes
[
i
];
}
int
r
=
0
;
if
(
this
->
cpuCount
>
8
)
{
this
->
columns
[
0
].
names
[
0
]
=
s
trdup
(
"LeftCPUs2"
);
this
->
columns
[
1
].
names
[
r
++
]
=
s
trdup
(
"RightCPUs2"
);
this
->
columns
[
0
].
names
[
0
]
=
xS
trdup
(
"LeftCPUs2"
);
this
->
columns
[
1
].
names
[
r
++
]
=
xS
trdup
(
"RightCPUs2"
);
}
else
if
(
this
->
cpuCount
>
4
)
{
this
->
columns
[
0
].
names
[
0
]
=
s
trdup
(
"LeftCPUs"
);
this
->
columns
[
1
].
names
[
r
++
]
=
s
trdup
(
"RightCPUs"
);
this
->
columns
[
0
].
names
[
0
]
=
xS
trdup
(
"LeftCPUs"
);
this
->
columns
[
1
].
names
[
r
++
]
=
xS
trdup
(
"RightCPUs"
);
}
else
{
this
->
columns
[
0
].
names
[
0
]
=
s
trdup
(
"AllCPUs"
);
this
->
columns
[
0
].
names
[
0
]
=
xS
trdup
(
"AllCPUs"
);
}
this
->
columns
[
0
].
names
[
1
]
=
s
trdup
(
"Memory"
);
this
->
columns
[
0
].
names
[
2
]
=
s
trdup
(
"Swap"
);
this
->
columns
[
0
].
names
[
1
]
=
xS
trdup
(
"Memory"
);
this
->
columns
[
0
].
names
[
2
]
=
xS
trdup
(
"Swap"
);
this
->
columns
[
1
].
names
[
r
++
]
=
s
trdup
(
"Tasks"
);
this
->
columns
[
1
].
names
[
r
++
]
=
s
trdup
(
"LoadAverage"
);
this
->
columns
[
1
].
names
[
r
++
]
=
s
trdup
(
"Uptime"
);
this
->
columns
[
1
].
names
[
r
++
]
=
xS
trdup
(
"Tasks"
);
this
->
columns
[
1
].
names
[
r
++
]
=
xS
trdup
(
"LoadAverage"
);
this
->
columns
[
1
].
names
[
r
++
]
=
xS
trdup
(
"Uptime"
);
}
static
void
readFields
(
ProcessField
*
fields
,
int
*
flags
,
const
char
*
line
)
{
...
...
@@ -306,7 +306,7 @@ bool Settings_write(Settings* this) {
Settings
*
Settings_new
(
int
cpuCount
)
{
Settings
*
this
=
c
alloc
(
1
,
sizeof
(
Settings
));
Settings
*
this
=
xC
alloc
(
1
,
sizeof
(
Settings
));
this
->
sortKey
=
PERCENT_CPU
;
this
->
direction
=
1
;
...
...
@@ -325,7 +325,7 @@ Settings* Settings_new(int cpuCount) {
this
->
showProgramPath
=
true
;
this
->
highlightThreads
=
true
;
this
->
fields
=
c
alloc
(
Platform_numberOfFields
+
1
,
sizeof
(
ProcessField
));
this
->
fields
=
xC
alloc
(
Platform_numberOfFields
+
1
,
sizeof
(
ProcessField
));
// TODO: turn 'fields' into a Vector,
// (and ProcessFields into proper objects).
this
->
flags
=
0
;
...
...
@@ -338,7 +338,7 @@ Settings* Settings_new(int cpuCount) {
char
*
legacyDotfile
=
NULL
;
char
*
rcfile
=
getenv
(
"HTOPRC"
);
if
(
rcfile
)
{
this
->
filename
=
s
trdup
(
rcfile
);
this
->
filename
=
xS
trdup
(
rcfile
);
}
else
{
const
char
*
home
=
getenv
(
"HOME"
);
if
(
!
home
)
home
=
""
;
...
...
@@ -347,7 +347,7 @@ Settings* Settings_new(int cpuCount) {
char
*
htopDir
=
NULL
;
if
(
xdgConfigHome
)
{
this
->
filename
=
String_cat
(
xdgConfigHome
,
"/htop/htoprc"
);
configDir
=
s
trdup
(
xdgConfigHome
);
configDir
=
xS
trdup
(
xdgConfigHome
);
htopDir
=
String_cat
(
xdgConfigHome
,
"/htop"
);
}
else
{
this
->
filename
=
String_cat
(
home
,
"/.config/htop/htoprc"
);
...
...
StringUtils.c
View file @
ffcf48fb
...
...
@@ -6,6 +6,7 @@ in the source distribution for its full text.
*/
#include "StringUtils.h"
#include "XAlloc.h"
#include "config.h"
...
...
@@ -22,7 +23,7 @@ in the source distribution for its full text.
char
*
String_cat
(
const
char
*
s1
,
const
char
*
s2
)
{
int
l1
=
strlen
(
s1
);
int
l2
=
strlen
(
s2
);
char
*
out
=
m
alloc
(
l1
+
l2
+
1
);
char
*
out
=
xM
alloc
(
l1
+
l2
+
1
);
strncpy
(
out
,
s1
,
l1
);
strncpy
(
out
+
l1
,
s2
,
l2
+
1
);
return
out
;
...
...
@@ -36,7 +37,7 @@ char* String_trim(const char* in) {
while
(
len
>
0
&&
(
in
[
len
-
1
]
==
' '
||
in
[
len
-
1
]
==
'\t'
||
in
[
len
-
1
]
==
'\n'
))
{
len
--
;
}
char
*
out
=
m
alloc
(
len
+
1
);
char
*
out
=
xM
alloc
(
len
+
1
);
strncpy
(
out
,
in
,
len
);
out
[
len
]
=
'\0'
;
return
out
;
...
...
@@ -55,20 +56,20 @@ inline int String_eq(const char* s1, const char* s2) {
char
**
String_split
(
const
char
*
s
,
char
sep
,
int
*
n
)
{
*
n
=
0
;
const
int
rate
=
10
;
char
**
out
=
c
alloc
(
rate
,
sizeof
(
char
*
));
char
**
out
=
xC
alloc
(
rate
,
sizeof
(
char
*
));
int
ctr
=
0
;
int
blocks
=
rate
;
char
*
where
;
while
((
where
=
strchr
(
s
,
sep
))
!=
NULL
)
{
int
size
=
where
-
s
;
char
*
token
=
m
alloc
(
size
+
1
);
char
*
token
=
xM
alloc
(
size
+
1
);
strncpy
(
token
,
s
,
size
);
token
[
size
]
=
'\0'
;
out
[
ctr
]
=
token
;
ctr
++
;
if
(
ctr
==
blocks
)
{
blocks
+=
rate
;
char
**
newOut
=
(
char
**
)
r
ealloc
(
out
,
sizeof
(
char
*
)
*
blocks
);
char
**
newOut
=
(
char
**
)
xR
ealloc
(
out
,
sizeof
(
char
*
)
*
blocks
);
if
(
newOut
)
{
out
=
newOut
;
}
else
{
...
...
@@ -80,12 +81,12 @@ char** String_split(const char* s, char sep, int* n) {
}
if
(
s
[
0
]
!=
'\0'
)
{
int
size
=
strlen
(
s
);
char
*
token
=
m
alloc
(
size
+
1
);
char
*
token
=
xM
alloc
(
size
+
1
);
strncpy
(
token
,
s
,
size
+
1
);
out
[
ctr
]
=
token
;
ctr
++
;
}
char
**
newOut
=
r
ealloc
(
out
,
sizeof
(
char
*
)
*
(
ctr
+
1
));
char
**
newOut
=
xR
ealloc
(
out
,
sizeof
(
char
*
)
*
(
ctr
+
1
));
if
(
newOut
)
{
out
=
newOut
;
}
...
...
@@ -125,5 +126,5 @@ char* String_getToken(const char* line, const unsigned short int numMatch) {
}
match
[
foundCount
]
=
'\0'
;
return
((
char
*
)
s
trdup
(
match
));
return
((
char
*
)
xS
trdup
(
match
));
}
TraceScreen.c
View file @
ffcf48fb
...
...
@@ -59,7 +59,7 @@ InfoScreenClass TraceScreen_class = {
};
TraceScreen
*
TraceScreen_new
(
Process
*
process
)
{
TraceScreen
*
this
=
m
alloc
(
sizeof
(
TraceScreen
));
TraceScreen
*
this
=
xM
alloc
(
sizeof
(
TraceScreen
));
Object_setClass
(
this
,
Class
(
TraceScreen
));
this
->
tracing
=
true
;
this
->
contLine
=
false
;
...
...
UsersTable.c
View file @
ffcf48fb
...
...
@@ -6,6 +6,7 @@ in the source distribution for its full text.
*/
#include "UsersTable.h"
#include "XAlloc.h"
#include "config.h"
...
...
@@ -27,7 +28,7 @@ typedef struct UsersTable_ {
UsersTable
*
UsersTable_new
()
{
UsersTable
*
this
;
this
=
m
alloc
(
sizeof
(
UsersTable
));
this
=
xM
alloc
(
sizeof
(
UsersTable
));
this
->
users
=
Hashtable_new
(
20
,
true
);
return
this
;
}
...
...
@@ -42,7 +43,7 @@ char* UsersTable_getRef(UsersTable* this, unsigned int uid) {
if
(
name
==
NULL
)
{
struct
passwd
*
userData
=
getpwuid
(
uid
);
if
(
userData
!=
NULL
)
{
name
=
s
trdup
(
userData
->
pw_name
);
name
=
xS
trdup
(
userData
->
pw_name
);
Hashtable_put
(
this
->
users
,
uid
,
name
);
}
}
...
...
Vector.c
View file @
ffcf48fb
...
...
@@ -37,9 +37,9 @@ Vector* Vector_new(ObjectClass* type, bool owner, int size) {
if
(
size
==
DEFAULT_SIZE
)
size
=
10
;
this
=
m
alloc
(
sizeof
(
Vector
));
this
=
xM
alloc
(
sizeof
(
Vector
));
this
->
growthRate
=
size
;
this
->
array
=
(
Object
**
)
c
alloc
(
size
,
sizeof
(
Object
*
));
this
->
array
=
(
Object
**
)
xC
alloc
(
size
,
sizeof
(
Object
*
));
this
->
arraySize
=
size
;
this
->
items
=
0
;
this
->
type
=
type
;
...
...
@@ -179,7 +179,7 @@ static void Vector_checkArraySize(Vector* this) {
//int i;
//i = this->arraySize;
this
->
arraySize
=
this
->
items
+
this
->
growthRate
;
this
->
array
=
(
Object
**
)
r
ealloc
(
this
->
array
,
sizeof
(
Object
*
)
*
this
->
arraySize
);
this
->
array
=
(
Object
**
)
xR
ealloc
(
this
->
array
,
sizeof
(
Object
*
)
*
this
->
arraySize
);
//for (; i < this->arraySize; i++)
// this->array[i] = NULL;
}
...
...
XAlloc.c
0 → 100644
View file @
ffcf48fb
#include "XAlloc.h"
#include "RichString.h"
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <unistd.h>
#include <string.h>
/*{
#include <stdlib.h>
}*/
static
char
oomMessage
[]
=
"Out of memory!
\n
"
;
void
*
xMalloc
(
size_t
size
)
{
void
*
data
=
malloc
(
size
);
if
(
!
data
&&
size
>
0
)
{
curs_set
(
1
);
endwin
();
write
(
2
,
oomMessage
,
sizeof
oomMessage
-
1
);
}
return
data
;
}
void
*
xCalloc
(
size_t
nmemb
,
size_t
size
)
{
void
*
data
=
calloc
(
nmemb
,
size
);
if
(
!
data
&&
nmemb
>
0
&&
size
>
0
)
{
curs_set
(
1
);
endwin
();
write
(
2
,
oomMessage
,
sizeof
oomMessage
-
1
);
}
return
data
;
}
void
*
xRealloc
(
void
*
ptr
,
size_t
size
)
{
void
*
data
=
realloc
(
ptr
,
size
);
if
(
!
data
&&
size
>
0
)
{
curs_set
(
1
);
endwin
();
write
(
2
,
oomMessage
,
sizeof
oomMessage
-
1
);
}
return
data
;
}
char
*
xStrdup
(
const
char
*
str
)
{
char
*
data
=
strdup
(
str
);
if
(
!
data
&&
str
)
{
curs_set
(
1
);
endwin
();
write
(
2
,
oomMessage
,
sizeof
oomMessage
-
1
);
}
return
data
;
}
XAlloc.h
0 → 100644
View file @
ffcf48fb
/* Do not edit this file. It was automatically generated. */
#ifndef HEADER_XAlloc
#define HEADER_XAlloc
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stdlib.h>
void
*
xMalloc
(
size_t
size
);
void
*
xCalloc
(
size_t
nmemb
,
size_t
size
);
void
*
xRealloc
(
void
*
ptr
,
size_t
size
);
char
*
xStrdup
(
const
char
*
str
);
#endif
darwin/DarwinProcess.c
View file @
ffcf48fb
...
...
@@ -39,7 +39,7 @@ ProcessClass DarwinProcess_class = {
};
DarwinProcess
*
DarwinProcess_new
(
Settings
*
settings
)
{
DarwinProcess
*
this
=
c
alloc
(
1
,
sizeof
(
DarwinProcess
));
DarwinProcess
*
this
=
xC
alloc
(
1
,
sizeof
(
DarwinProcess
));
Object_setClass
(
this
,
Class
(
DarwinProcess
));
Process_init
(
&
this
->
super
,
settings
);
...
...
@@ -85,7 +85,7 @@ char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int show_args ) {
}
/* Allocate space for the arguments. */
procargs
=
(
char
*
)
m
alloc
(
argmax
);
procargs
=
(
char
*
)
xM
alloc
(
argmax
);
if
(
procargs
==
NULL
)
{
goto
ERROR_A
;
}
...
...
@@ -237,7 +237,7 @@ char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int show_args ) {
}
/* Make a copy of the string. */
retval
=
s
trdup
(
sp
);
retval
=
xS
trdup
(
sp
);
/* Clean up. */
free
(
procargs
);
...
...
@@ -247,7 +247,7 @@ char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int show_args ) {
ERROR_B:
free
(
procargs
);
ERROR_A:
retval
=
s
trdup
(
k
->
kp_proc
.
p_comm
);
retval
=
xS
trdup
(
k
->
kp_proc
.
p_comm
);
return
retval
;
}
...
...
darwin/DarwinProcessList.c
View file @
ffcf48fb
...
...
@@ -87,7 +87,7 @@ struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) {
if
(
sysctl
(
mib
,
4
,
NULL
,
count
,
NULL
,
0
)
<
0
)
CRT_fatalError
(
"Unable to get size of kproc_infos"
);
processes
=
m
alloc
(
*
count
);
processes
=
xM
alloc
(
*
count
);
if
(
processes
==
NULL
)
CRT_fatalError
(
"Out of memory for kproc_infos"
);
...
...
@@ -101,7 +101,7 @@ struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) {
ProcessList
*
ProcessList_new
(
UsersTable
*
usersTable
,
Hashtable
*
pidWhiteList
,
uid_t
userId
)
{
DarwinProcessList
*
this
=
c
alloc
(
1
,
sizeof
(
DarwinProcessList
));
DarwinProcessList
*
this
=
xC
alloc
(
1
,
sizeof
(
DarwinProcessList
));
ProcessList_init
(
&
this
->
super
,
Class
(
Process
),
usersTable
,
pidWhiteList
,
userId
);
...
...
darwin/Platform.c
View file @
ffcf48fb
...
...
@@ -251,7 +251,7 @@ char* Platform_getProcessEnv(pid_t pid) {
mib
[
0
]
=
CTL_KERN
;
mib
[
1
]
=
KERN_ARGMAX
;
if
(
sysctl
(
mib
,
2
,
&
argmax
,
&
bufsz
,
0
,
0
)
==
0
)
{
char
*
buf
=
m
alloc
(
argmax
);
char
*
buf
=
xM
alloc
(
argmax
);
if
(
buf
)
{
mib
[
0
]
=
CTL_KERN
;
mib
[
1
]
=
KERN_PROCARGS2
;
...
...
@@ -279,7 +279,7 @@ char* Platform_getProcessEnv(pid_t pid) {
++
p
;
size_t
size
=
endp
-
p
;
env
=
m
alloc
(
size
+
2
);
env
=
xM
alloc
(
size
+
2
);
if
(
env
)
{
memcpy
(
env
,
p
,
size
);
env
[
size
]
=
0
;
...
...
freebsd/FreeBSDProcess.c
View file @
ffcf48fb
...
...
@@ -97,7 +97,7 @@ ProcessPidColumn Process_pidColumns[] = {
};
FreeBSDProcess
*
FreeBSDProcess_new
(
Settings
*
settings
)
{
FreeBSDProcess
*
this
=
c
alloc
(
1
,
sizeof
(
FreeBSDProcess
));
FreeBSDProcess
*
this
=
xC
alloc
(
1
,
sizeof
(
FreeBSDProcess
));
Object_setClass
(
this
,
Class
(
FreeBSDProcess
));
Process_init
(
&
this
->
super
,
settings
);
return
this
;
...
...
freebsd/FreeBSDProcessList.c
View file @
ffcf48fb
...
...
@@ -86,7 +86,7 @@ static int kernelFScale;
ProcessList
*
ProcessList_new
(
UsersTable
*
usersTable
,
Hashtable
*
pidWhiteList
,
uid_t
userId
)
{
FreeBSDProcessList
*
fpl
=
c
alloc
(
1
,
sizeof
(
FreeBSDProcessList
));
FreeBSDProcessList
*
fpl
=
xC
alloc
(
1
,
sizeof
(
FreeBSDProcessList
));
ProcessList
*
pl
=
(
ProcessList
*
)
fpl
;
ProcessList_init
(
pl
,
Class
(
FreeBSDProcess
),
usersTable
,
pidWhiteList
,
userId
);
...
...
@@ -146,8 +146,8 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
size_t
sizeof_cp_time_array
=
sizeof
(
unsigned
long
)
*
CPUSTATES
;
len
=
2
;
sysctlnametomib
(
"kern.cp_time"
,
MIB_kern_cp_time
,
&
len
);
fpl
->
cp_time_o
=
c
alloc
(
cpus
,
sizeof_cp_time_array
);
fpl
->
cp_time_n
=
c
alloc
(
cpus
,
sizeof_cp_time_array
);
fpl
->
cp_time_o
=
xC
alloc
(
cpus
,
sizeof_cp_time_array
);
fpl
->
cp_time_n
=
xC
alloc
(
cpus
,
sizeof_cp_time_array
);
len
=
sizeof_cp_time_array
;
// fetch intial single (or average) CPU clicks from kernel
...
...
@@ -156,8 +156,8 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
// on smp box, fetch rest of intial CPU's clicks
if
(
cpus
>
1
)
{
len
=
2
;
sysctlnametomib
(
"kern.cp_times"
,
MIB_kern_cp_times
,
&
len
);
fpl
->
cp_times_o
=
c
alloc
(
cpus
,
sizeof_cp_time_array
);
fpl
->
cp_times_n
=
c
alloc
(
cpus
,
sizeof_cp_time_array
);
fpl
->
cp_times_o
=
xC
alloc
(
cpus
,
sizeof_cp_time_array
);
fpl
->
cp_times_n
=
xC
alloc
(
cpus
,
sizeof_cp_time_array
);
len
=
cpus
*
sizeof_cp_time_array
;
sysctl
(
MIB_kern_cp_times
,
2
,
fpl
->
cp_times_o
,
&
len
,
NULL
,
0
);
}
...
...
@@ -165,10 +165,10 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
pl
->
cpuCount
=
MAX
(
cpus
,
1
);
if
(
cpus
==
1
)
{
fpl
->
cpus
=
r
ealloc
(
fpl
->
cpus
,
sizeof
(
CPUData
));
fpl
->
cpus
=
xR
ealloc
(
fpl
->
cpus
,
sizeof
(
CPUData
));
}
else
{
// on smp we need CPUs + 1 to store averages too (as kernel kindly provides that as well)
fpl
->
cpus
=
r
ealloc
(
fpl
->
cpus
,
(
pl
->
cpuCount
+
1
)
*
sizeof
(
CPUData
));
fpl
->
cpus
=
xR
ealloc
(
fpl
->
cpus
,
(
pl
->
cpuCount
+
1
)
*
sizeof
(
CPUData
));
}
...
...
@@ -349,13 +349,13 @@ static inline void FreeBSDProcessList_scanMemoryInfo(ProcessList* pl) {
char
*
FreeBSDProcessList_readProcessName
(
kvm_t
*
kd
,
struct
kinfo_proc
*
kproc
,
int
*
basenameEnd
)
{
char
**
argv
=
kvm_getargv
(
kd
,
kproc
,
0
);
if
(
!
argv
)
{
return
s
trdup
(
kproc
->
ki_comm
);
return
xS
trdup
(
kproc
->
ki_comm
);
}
int
len
=
0
;
for
(
int
i
=
0
;
argv
[
i
];
i
++
)
{
len
+=
strlen
(
argv
[
i
])
+
1
;
}
char
*
comm
=
m
alloc
(
len
);
char
*
comm
=
xM
alloc
(
len
);
char
*
at
=
comm
;
*
basenameEnd
=
0
;
for
(
int
i
=
0
;
argv
[
i
];
i
++
)
{
...
...
@@ -398,7 +398,7 @@ char* FreeBSDProcessList_readJailName(struct kinfo_proc* kproc) {
snprintf
(
jail_errmsg
,
JAIL_ERRMSGLEN
,
"jail_get: %s"
,
strerror
(
errno
));
return
NULL
;
}
else
if
(
jid
==
kproc
->
ki_jid
)
{
jname
=
s
trdup
(
jnamebuf
);
jname
=
xS
trdup
(
jnamebuf
);
if
(
jname
==
NULL
)
strerror_r
(
errno
,
jail_errmsg
,
JAIL_ERRMSGLEN
);
return
jname
;
...
...
@@ -408,7 +408,7 @@ char* FreeBSDProcessList_readJailName(struct kinfo_proc* kproc) {
}
else
{
jnamebuf
[
0
]
=
'-'
;
jnamebuf
[
1
]
=
'\0'
;
jname
=
s
trdup
(
jnamebuf
);
jname
=
xS
trdup
(
jnamebuf
);
}
return
jname
;
}
...
...
htop.c
View file @
ffcf48fb
...
...
@@ -128,7 +128,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) {
flags
.
useColors
=
false
;
break
;
case
'p'
:
{
char
*
argCopy
=
s
trdup
(
optarg
);
char
*
argCopy
=
xS
trdup
(
optarg
);
char
*
saveptr
;
char
*
pid
=
strtok_r
(
argCopy
,
","
,
&
saveptr
);
...
...
linux/Battery.c
View file @
ffcf48fb
...
...
@@ -50,7 +50,7 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short
char
*
entryName
=
dirEntry
->
d_name
;
if
(
strncmp
(
entryName
,
"BAT"
,
3
))
continue
;
batteries
[
nBatteries
]
=
s
trdup
(
entryName
);
batteries
[
nBatteries
]
=
xS
trdup
(
entryName
);
nBatteries
++
;
}
closedir
(
batteryDir
);
...
...
linux/LinuxProcess.c
View file @
ffcf48fb
...
...
@@ -242,7 +242,7 @@ ProcessClass LinuxProcess_class = {
};
LinuxProcess
*
LinuxProcess_new
(
Settings
*
settings
)
{
LinuxProcess
*
this
=
c
alloc
(
1
,
sizeof
(
LinuxProcess
));
LinuxProcess
*
this
=
xC
alloc
(
1
,
sizeof
(
LinuxProcess
));
Object_setClass
(
this
,
Class
(
LinuxProcess
));
Process_init
(
&
this
->
super
,
settings
);
return
this
;
...
...
linux/LinuxProcessList.c
View file @
ffcf48fb
...
...
@@ -89,7 +89,7 @@ typedef struct LinuxProcessList_ {
#endif
ProcessList
*
ProcessList_new
(
UsersTable
*
usersTable
,
Hashtable
*
pidWhiteList
,
uid_t
userId
)
{
LinuxProcessList
*
this
=
c
alloc
(
1
,
sizeof
(
LinuxProcessList
));
LinuxProcessList
*
this
=
xC
alloc
(
1
,
sizeof
(
LinuxProcessList
));
ProcessList
*
pl
=
&
(
this
->
super
);
ProcessList_init
(
pl
,
Class
(
LinuxProcess
),
usersTable
,
pidWhiteList
,
userId
);
...
...
@@ -108,7 +108,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
fclose
(
file
);
pl
->
cpuCount
=
MAX
(
cpus
-
1
,
1
);
this
->
cpus
=
c
alloc
(
cpus
,
sizeof
(
CPUData
));
this
->
cpus
=
xC
alloc
(
cpus
,
sizeof
(
CPUData
));
for
(
int
i
=
0
;
i
<
cpus
;
i
++
)
{
this
->
cpus
[
i
].
totalTime
=
1
;
...
...
@@ -366,7 +366,7 @@ static void LinuxProcessList_readCGroupFile(LinuxProcess* process, const char* d
snprintf
(
filename
,
MAX_NAME
,
"%s/%s/cgroup"
,
dirname
,
name
);
FILE
*
file
=
fopen
(
filename
,
"r"
);
if
(
!
file
)
{
process
->
cgroup
=
s
trdup
(
""
);
process
->
cgroup
=
xS
trdup
(
""
);
return
;
}
char
output
[
PROC_LINE_LENGTH
+
1
];
...
...
@@ -389,7 +389,7 @@ static void LinuxProcessList_readCGroupFile(LinuxProcess* process, const char* d
}
fclose
(
file
);
free
(
process
->
cgroup
);
process
->
cgroup
=
s
trdup
(
output
);
process
->
cgroup
=
xS
trdup
(
output
);
}
#endif
...
...
linux/Platform.c
View file @
ffcf48fb
...
...
@@ -220,16 +220,16 @@ char* Platform_getProcessEnv(pid_t pid) {
char
*
env
=
NULL
;
if
(
fd
)
{
size_t
capacity
=
4096
,
size
=
0
,
bytes
;
env
=
m
alloc
(
capacity
);
env
=
xM
alloc
(
capacity
);
while
(
env
&&
(
bytes
=
fread
(
env
+
size
,
1
,
capacity
-
size
,
fd
))
>
0
)
{
size
+=
bytes
;
capacity
*=
2
;
env
=
r
ealloc
(
env
,
capacity
);
env
=
xR
ealloc
(
env
,
capacity
);
}
fclose
(
fd
);
if
(
size
<
2
||
env
[
size
-
1
]
||
env
[
size
-
2
])
{
if
(
size
+
2
<
capacity
)
{
env
=
r
ealloc
(
env
,
capacity
+
2
);
env
=
xR
ealloc
(
env
,
capacity
+
2
);
}
env
[
size
]
=
0
;
env
[
size
+
1
]
=
0
;
...
...
openbsd/OpenBSDProcess.c
View file @
ffcf48fb
...
...
@@ -186,7 +186,7 @@ ProcessPidColumn Process_pidColumns[] = {
};
OpenBSDProcess
*
OpenBSDProcess_new
(
Settings
*
settings
)
{
OpenBSDProcess
*
this
=
c
alloc
(
sizeof
(
OpenBSDProcess
),
1
);
OpenBSDProcess
*
this
=
xC
alloc
(
sizeof
(
OpenBSDProcess
),
1
);
Object_setClass
(
this
,
Class
(
OpenBSDProcess
));
Process_init
(
&
this
->
super
,
settings
);
return
this
;
...
...
openbsd/OpenBSDProcessList.c
View file @
ffcf48fb
...
...
@@ -53,7 +53,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
int
mib
[]
=
{
CTL_HW
,
HW_NCPU
};
int
fmib
[]
=
{
CTL_KERN
,
KERN_FSCALE
};
int
i
,
e
;
OpenBSDProcessList
*
opl
=
c
alloc
(
1
,
sizeof
(
OpenBSDProcessList
));
OpenBSDProcessList
*
opl
=
xC
alloc
(
1
,
sizeof
(
OpenBSDProcessList
));
ProcessList
*
pl
=
(
ProcessList
*
)
opl
;
size_t
size
=
sizeof
(
pl
->
cpuCount
);
...
...
@@ -62,7 +62,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
if
(
e
==
-
1
||
pl
->
cpuCount
<
1
)
{
pl
->
cpuCount
=
1
;
}
opl
->
cpus
=
r
ealloc
(
opl
->
cpus
,
pl
->
cpuCount
*
sizeof
(
CPUData
));
opl
->
cpus
=
xR
ealloc
(
opl
->
cpus
,
pl
->
cpuCount
*
sizeof
(
CPUData
));
size
=
sizeof
(
fscale
);
if
(
sysctl
(
fmib
,
2
,
&
fscale
,
&
size
,
NULL
,
0
)
<
0
)
...
...
@@ -144,7 +144,7 @@ char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, in
*/
arg
=
kvm_getargv
(
kd
,
kproc
,
500
);
if
(
arg
==
NULL
)
{
if
((
s
=
s
trdup
(
kproc
->
p_comm
))
==
NULL
)
{
if
((
s
=
xS
trdup
(
kproc
->
p_comm
))
==
NULL
)
{
err
(
1
,
NULL
);
}
return
s
;
...
...
@@ -152,8 +152,8 @@ char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, in
for
(
i
=
0
;
arg
[
i
]
!=
NULL
;
i
++
)
{
len
+=
strlen
(
arg
[
i
])
+
1
;
}
if
((
buf
=
s
=
m
alloc
(
len
))
==
NULL
)
{
if
((
s
=
s
trdup
(
kproc
->
p_comm
))
==
NULL
)
{
if
((
buf
=
s
=
xM
alloc
(
len
))
==
NULL
)
{
if
((
s
=
xS
trdup
(
kproc
->
p_comm
))
==
NULL
)
{
err
(
1
,
NULL
);
}
return
s
;
...
...
Prev
1
2
3
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment