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
794419e6
Commit
794419e6
authored
Aug 19, 2018
by
multiplexd
Committed by
Hisham Muhammad
Aug 24, 2018
Browse files
OpenBSD: add environment reading support (#819)
parent
7ec53129
Changes
1
Show whitespace changes
Inline
Side-by-side
openbsd/Platform.c
View file @
794419e6
...
...
@@ -23,6 +23,7 @@ in the source distribution for its full text.
#include <sys/sched.h>
#include <uvm/uvmexp.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/swap.h>
#include <unistd.h>
...
...
@@ -34,6 +35,9 @@ in the source distribution for its full text.
#include <sys/time.h>
#include <sys/resource.h>
#include <time.h>
#include <fcntl.h>
#include <kvm.h>
#include <limits.h>
/*{
#include "Action.h"
...
...
@@ -302,6 +306,48 @@ void Platform_setTasksValues(Meter* this) {
}
char
*
Platform_getProcessEnv
(
pid_t
pid
)
{
// TODO
char
errbuf
[
_POSIX2_LINE_MAX
];
char
*
env
;
char
**
ptr
;
int
count
;
kvm_t
*
kt
;
struct
kinfo_proc
*
kproc
;
size_t
capacity
=
4096
,
size
=
0
;
if
((
kt
=
kvm_openfiles
(
NULL
,
NULL
,
NULL
,
KVM_NO_FILES
,
errbuf
))
==
NULL
)
return
NULL
;
if
((
kproc
=
kvm_getprocs
(
kt
,
KERN_PROC_PID
,
pid
,
sizeof
(
struct
kinfo_proc
),
&
count
))
==
NULL
)
{
\
(
void
)
kvm_close
(
kt
);
return
NULL
;
}
if
((
ptr
=
kvm_getenvv
(
kt
,
kproc
,
0
))
==
NULL
)
{
(
void
)
kvm_close
(
kt
);
return
NULL
;
}
env
=
xMalloc
(
capacity
);
for
(
char
**
p
=
ptr
;
*
p
;
p
++
)
{
size_t
len
=
strlen
(
*
p
)
+
1
;
if
(
size
+
len
>
capacity
)
{
capacity
*=
2
;
env
=
xRealloc
(
env
,
capacity
);
}
strlcpy
(
env
+
size
,
*
p
,
len
);
size
+=
len
;
}
if
(
size
<
2
||
env
[
size
-
1
]
||
env
[
size
-
2
])
{
if
(
size
+
2
<
capacity
)
env
=
xRealloc
(
env
,
capacity
+
2
);
env
[
size
]
=
0
;
env
[
size
+
1
]
=
0
;
}
(
void
)
kvm_close
(
kt
);
return
env
;
}
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