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
d850803e
Commit
d850803e
authored
Jan 11, 2016
by
Hisham Muhammad
Browse files
Merge branch 'master' of
https://github.com/hishamhm/htop
parents
c6ca311d
fc61e25f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Action.c
View file @
d850803e
...
...
@@ -404,7 +404,7 @@ static struct { const char* key; const char* info; } helpRight[] = {
#if (HAVE_LIBHWLOC || HAVE_NATIVE_AFFINITY)
{
.
key
=
" a: "
,
.
info
=
"set CPU affinity"
},
#endif
{
.
key
=
" i: "
,
.
info
=
"set IO prority"
},
{
.
key
=
" i: "
,
.
info
=
"set IO pr
i
ority"
},
{
.
key
=
" l: "
,
.
info
=
"list open files with lsof"
},
{
.
key
=
" s: "
,
.
info
=
"trace syscalls with strace"
},
{
.
key
=
" "
,
.
info
=
""
},
...
...
Process.c
View file @
d850803e
...
...
@@ -513,8 +513,11 @@ void Process_toggleTag(Process* this) {
}
bool
Process_setPriority
(
Process
*
this
,
int
priority
)
{
uid_t
euid
=
geteuid
();
seteuid
(
getuid
());
int
old_prio
=
getpriority
(
PRIO_PROCESS
,
this
->
pid
);
int
err
=
setpriority
(
PRIO_PROCESS
,
this
->
pid
,
priority
);
seteuid
(
euid
);
if
(
err
==
0
&&
old_prio
!=
getpriority
(
PRIO_PROCESS
,
this
->
pid
))
{
this
->
nice
=
priority
;
}
...
...
@@ -526,7 +529,10 @@ bool Process_changePriorityBy(Process* this, size_t delta) {
}
void
Process_sendSignal
(
Process
*
this
,
size_t
sgn
)
{
uid_t
euid
=
geteuid
();
seteuid
(
getuid
());
kill
(
this
->
pid
,
(
int
)
sgn
);
seteuid
(
euid
);
}
long
Process_pidCompare
(
const
void
*
v1
,
const
void
*
v2
)
{
...
...
Settings.c
View file @
d850803e
...
...
@@ -154,7 +154,12 @@ static void readFields(ProcessField* fields, int* flags, const char* line) {
}
static
bool
Settings_read
(
Settings
*
this
,
const
char
*
fileName
)
{
FILE
*
fd
=
fopen
(
fileName
,
"r"
);
FILE
*
fd
;
uid_t
euid
=
geteuid
();
seteuid
(
getuid
());
fd
=
fopen
(
fileName
,
"r"
);
seteuid
(
euid
);
if
(
!
fd
)
return
false
;
...
...
@@ -260,7 +265,11 @@ static void writeMeterModes(Settings* this, FILE* fd, int column) {
bool
Settings_write
(
Settings
*
this
)
{
FILE
*
fd
;
uid_t
euid
=
geteuid
();
seteuid
(
getuid
());
fd
=
fopen
(
this
->
filename
,
"w"
);
seteuid
(
euid
);
if
(
fd
==
NULL
)
{
return
false
;
}
...
...
@@ -345,6 +354,8 @@ Settings* Settings_new(int cpuCount) {
htopDir
=
String_cat
(
home
,
"/.config/htop"
);
}
legacyDotfile
=
String_cat
(
home
,
"/.htoprc"
);
uid_t
euid
=
geteuid
();
seteuid
(
getuid
());
(
void
)
mkdir
(
configDir
,
0700
);
(
void
)
mkdir
(
htopDir
,
0700
);
free
(
htopDir
);
...
...
@@ -357,6 +368,7 @@ Settings* Settings_new(int cpuCount) {
free
(
legacyDotfile
);
legacyDotfile
=
NULL
;
}
seteuid
(
euid
);
}
this
->
colorScheme
=
0
;
this
->
changed
=
false
;
...
...
TraceScreen.c
View file @
d850803e
...
...
@@ -86,6 +86,7 @@ void TraceScreen_run(TraceScreen* this) {
int
child
=
fork
();
if
(
child
==
-
1
)
return
;
if
(
child
==
0
)
{
seteuid
(
getuid
());
dup2
(
fdpair
[
1
],
STDERR_FILENO
);
int
ok
=
fcntl
(
fdpair
[
1
],
F_SETFL
,
O_NONBLOCK
);
if
(
ok
!=
-
1
)
{
...
...
configure.ac
View file @
d850803e
...
...
@@ -103,7 +103,7 @@ if test "x$enable_proc" = xyes; then
AC_DEFINE(HAVE_PROC, 1, [Define if using a Linux-compatible proc filesystem.])
fi
AC_ARG_WITH(proc, [
--with-proc=DIR
Location of a Linux-compatible proc filesystem (default=/proc).],
AC_ARG_WITH(proc, [
AC_HELP_STRING([
--with-proc=DIR
], [
Location of a Linux-compatible proc filesystem (default=/proc).]
)]
,
if test -n "$withval"; then
AC_DEFINE_UNQUOTED(PROCDIR, "$withval", [Path of proc filesystem])
...
...
openbsd/OpenBSDProcessList.c
View file @
d850803e
...
...
@@ -49,8 +49,8 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
int
mib
[]
=
{
CTL_HW
,
HW_NCPU
};
int
fmib
[]
=
{
CTL_KERN
,
KERN_FSCALE
};
int
i
,
e
;
OpenBSDProcessList
*
f
pl
=
calloc
(
1
,
sizeof
(
OpenBSDProcessList
));
ProcessList
*
pl
=
(
ProcessList
*
)
f
pl
;
OpenBSDProcessList
*
o
pl
=
calloc
(
1
,
sizeof
(
OpenBSDProcessList
));
ProcessList
*
pl
=
(
ProcessList
*
)
o
pl
;
size_t
size
=
sizeof
(
pl
->
cpuCount
);
ProcessList_init
(
pl
,
Class
(
OpenBSDProcess
),
usersTable
,
pidWhiteList
,
userId
);
...
...
@@ -58,31 +58,31 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
if
(
e
==
-
1
||
pl
->
cpuCount
<
1
)
{
pl
->
cpuCount
=
1
;
}
f
pl
->
cpus
=
realloc
(
f
pl
->
cpus
,
pl
->
cpuCount
*
sizeof
(
CPUData
));
o
pl
->
cpus
=
realloc
(
o
pl
->
cpus
,
pl
->
cpuCount
*
sizeof
(
CPUData
));
size
=
sizeof
(
fscale
);
if
(
sysctl
(
fmib
,
2
,
&
fscale
,
&
size
,
NULL
,
0
)
<
0
)
err
(
1
,
"fscale sysctl call failed"
);
for
(
i
=
0
;
i
<
pl
->
cpuCount
;
i
++
)
{
f
pl
->
cpus
[
i
].
totalTime
=
1
;
f
pl
->
cpus
[
i
].
totalPeriod
=
1
;
o
pl
->
cpus
[
i
].
totalTime
=
1
;
o
pl
->
cpus
[
i
].
totalPeriod
=
1
;
}
pageSizeKb
=
PAGE_SIZE_KB
;
// XXX: last arg should eventually be an errbuf
f
pl
->
kd
=
kvm_open
(
NULL
,
NULL
,
NULL
,
KVM_NO_FILES
,
NULL
);
assert
(
f
pl
->
kd
);
o
pl
->
kd
=
kvm_open
(
NULL
,
NULL
,
NULL
,
KVM_NO_FILES
,
NULL
);
assert
(
o
pl
->
kd
);
return
pl
;
}
void
ProcessList_delete
(
ProcessList
*
this
)
{
const
OpenBSDProcessList
*
f
pl
=
(
OpenBSDProcessList
*
)
this
;
if
(
f
pl
->
kd
)
kvm_close
(
f
pl
->
kd
);
const
OpenBSDProcessList
*
o
pl
=
(
OpenBSDProcessList
*
)
this
;
if
(
o
pl
->
kd
)
kvm_close
(
o
pl
->
kd
);
free
(
f
pl
->
cpus
);
free
(
o
pl
->
cpus
);
ProcessList_done
(
this
);
free
(
this
);
...
...
@@ -102,7 +102,7 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) {
pl
->
totalMem
=
uvmexp
.
npages
*
pageSizeKb
;
/*
const OpenBSDProcessList*
f
pl = (OpenBSDProcessList*) pl;
const OpenBSDProcessList*
o
pl = (OpenBSDProcessList*) pl;
size_t len = sizeof(pl->totalMem);
sysctl(MIB_hw_physmem, 2, &(pl->totalMem), &len, NULL, 0);
...
...
@@ -114,7 +114,7 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) {
pl->cachedMem *= pageSizeKb;
struct kvm_swap swap[16];
int nswap = kvm_getswapinfo(
f
pl->kd, swap, sizeof(swap)/sizeof(swap[0]), 0);
int nswap = kvm_getswapinfo(
o
pl->kd, swap, sizeof(swap)/sizeof(swap[0]), 0);
pl->totalSwap = 0;
pl->usedSwap = 0;
for (int i = 0; i < nswap; i++) {
...
...
@@ -180,7 +180,7 @@ double getpcpu(const struct kinfo_proc *kp) {
}
void
ProcessList_goThroughEntries
(
ProcessList
*
this
)
{
OpenBSDProcessList
*
f
pl
=
(
OpenBSDProcessList
*
)
this
;
OpenBSDProcessList
*
o
pl
=
(
OpenBSDProcessList
*
)
this
;
Settings
*
settings
=
this
->
settings
;
bool
hideKernelThreads
=
settings
->
hideKernelThreads
;
bool
hideUserlandThreads
=
settings
->
hideUserlandThreads
;
...
...
@@ -194,7 +194,7 @@ void ProcessList_goThroughEntries(ProcessList* this) {
OpenBSDProcessList_scanMemoryInfo
(
this
);
// use KERN_PROC_KTHREAD to also include kernel threads
struct
kinfo_proc
*
kprocs
=
kvm_getprocs
(
f
pl
->
kd
,
KERN_PROC_ALL
,
0
,
sizeof
(
struct
kinfo_proc
),
&
count
);
struct
kinfo_proc
*
kprocs
=
kvm_getprocs
(
o
pl
->
kd
,
KERN_PROC_ALL
,
0
,
sizeof
(
struct
kinfo_proc
),
&
count
);
//struct kinfo_proc* kprocs = getprocs(KERN_PROC_ALL, 0, &count);
for
(
i
=
0
;
i
<
count
;
i
++
)
{
...
...
@@ -218,11 +218,11 @@ void ProcessList_goThroughEntries(ProcessList* this) {
proc
->
starttime_ctime
=
kproc
->
p_ustart_sec
;
proc
->
user
=
UsersTable_getRef
(
this
->
usersTable
,
proc
->
st_uid
);
ProcessList_add
((
ProcessList
*
)
this
,
proc
);
proc
->
comm
=
OpenBSDProcessList_readProcessName
(
f
pl
->
kd
,
kproc
,
&
proc
->
basenameOffset
);
proc
->
comm
=
OpenBSDProcessList_readProcessName
(
o
pl
->
kd
,
kproc
,
&
proc
->
basenameOffset
);
}
else
{
if
(
settings
->
updateProcessNames
)
{
free
(
proc
->
comm
);
proc
->
comm
=
OpenBSDProcessList_readProcessName
(
f
pl
->
kd
,
kproc
,
&
proc
->
basenameOffset
);
proc
->
comm
=
OpenBSDProcessList_readProcessName
(
o
pl
->
kd
,
kproc
,
&
proc
->
basenameOffset
);
}
}
...
...
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