FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
seer/src/QProcessInfo.cpp at main · CKLinuxProject/seer · GitHub
CKLinuxProject
/
seer
Public
forked from
epasveer/seer
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
seer
/
src
/
QProcessInfo.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
173 lines (127 loc) · 4.78 KB
Breadcrumbs
seer
/
src
/
QProcessInfo.cpp
Copy path
File metadata and controls
173 lines (127 loc) · 4.78 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
//
//
My version is based on this person's code.
//
//
Copyright (c) 2016, Baldur Karlsson
//
Licensed under BSD 2-Clause License, see LICENSE file.
//
Obtained from https://github.com/baldurk/qprocessinfo
//
#
include
"
QProcessInfo.h
"
#
include
<
QtCore/QDir
>
#
include
<
QtCore/QProcess
>
#
include
<
QtCore/QRegExp
>
#
include
<
QtCore/QStandardPaths
>
#
include
<
QtCore/QTextStream
>
#
include
<
QtCore/QDebug
>
#
include
<
stdlib.h
>
#
include
<
pwd.h
>
#
include
<
stdio.h
>
#
include
<
unistd.h
>
#
include
<
sys/types.h
>
QProcessList
QProcessInfo::populate
() {
QProcessList ret;
QDir
proc
(
QStringLiteral
(
"
/proc
"
));
QStringList files = proc.
entryList
();
for
(
const
QString& f : files) {
bool
ok =
false
;
uint32_t
pid = f.
toUInt
(&ok);
if
(ok) {
QProcessInfo info;
info.
setPid
(pid);
QDir
processDir
(
QStringLiteral
(
"
/proc/
"
) + f);
//
default to the exe symlink if valid
QFileInfo
exe
(processDir.
absoluteFilePath
(
QStringLiteral
(
"
exe
"
)));
exe =
QFileInfo
(exe.
symLinkTarget
());
info.
setName
(exe.
completeBaseName
());
//
if we didn't get a name from the symlink, check in the status file
if
(info.
name
().
isEmpty
()) {
QFile
status
(processDir.
absoluteFilePath
(
QStringLiteral
(
"
status
"
)));
if
(status.
open
(QIODevice::ReadOnly)) {
QByteArray contents = status.
readAll
();
QTextStream
in
(&contents);
while
(!in.
atEnd
()) {
QString line = in.
readLine
();
if
(line.
startsWith
(
QStringLiteral
(
"
Name:
"
))) {
line.
remove
(
0
,
5
);
//
if we're using this name, surround with []s to indicate it's not a file
info.
setName
(
QStringLiteral
(
"
[%1]
"
).
arg
(line.
trimmed
()));
break
;
}
}
status.
close
();
}
}
//
Get the username.
QFile
status
(processDir.
absoluteFilePath
(
QStringLiteral
(
"
status
"
)));
if
(status.
open
(QIODevice::ReadOnly)) {
QByteArray contents = status.
readAll
();
QTextStream
in
(&contents);
while
(!in.
atEnd
()) {
QString line = in.
readLine
();
if
(line.
startsWith
(
QStringLiteral
(
"
Uid:
"
))) {
//
qDebug() << line;
//
qDebug() << line.split(QRegExp("\\s+")).at(0);
//
qDebug() << line.split(QRegExp("\\s+")).at(1);
//
qDebug() << "";
info.
setUsername
(line.
split
(
QRegExp
(
"
\\
s+
"
)).
at
(
1
));
break
;
}
}
status.
close
();
struct
passwd
* pw =
getpwuid
(info.
username
().
toULong
());
if
(pw) {
info.
setUsername
(pw->
pw_name
);
}
}
//
Get the command line
QFile
cmdline
(processDir.
absoluteFilePath
(
QStringLiteral
(
"
cmdline
"
)));
if
(cmdline.
open
(QIODevice::ReadOnly)) {
QByteArray contents = cmdline.
readAll
();
int
nullIdx = contents.
indexOf
(
'
\0
'
);
if
(nullIdx >
0
) {
QString firstparam =
QString::fromUtf8
(contents.
data
(), nullIdx);
//
if name is a truncated form of a filename, replace it
if
(firstparam.
endsWith
(info.
name
()) &&
QFileInfo::exists
(firstparam)) {
info.
setName
(
QFileInfo
(firstparam).
completeBaseName
());
}
//
if we don't have a name, replace it but with []s
if
(info.
name
().
isEmpty
()) {
info.
setName
(
QStringLiteral
(
"
[%1]
"
).
arg
(firstparam));
}
contents.
replace
(
'
\0
'
,
'
'
);
}
info.
setCommandLine
(
QString::fromUtf8
(contents).
trimmed
());
cmdline.
close
();
}
//
Add the process to the list.
ret.
push_back
(info);
}
}
return
ret;
}
QProcessInfo::QProcessInfo
() {
_pid =
0
;
}
uint32_t
QProcessInfo::pid
()
const
{
return
_pid;
}
void
QProcessInfo::setPid
(
uint32_t
pid) {
_pid = pid;
}
const
QString &
QProcessInfo::username
()
const
{
return
_username;
}
void
QProcessInfo::setUsername
(
const
QString &username) {
_username = username;
}
const
QString &
QProcessInfo::name
()
const
{
return
_name;
}
void
QProcessInfo::setName
(
const
QString &name) {
_name = name;
}
const
QString &
QProcessInfo::commandLine
()
const
{
return
_cmdLine;
}
void
QProcessInfo::setCommandLine
(
const
QString &cmd) {
_cmdLine = cmd;
}
Back
|
FazBrowse Home
|
New Git URL