Changeset View
Changeset View
Standalone View
Standalone View
processcore/processes_linux_p.cpp
Show First 20 Lines • Show All 132 Lines • ▼ Show 20 Line(s) | 132 | { | |||
---|---|---|---|---|---|
133 | mFile.setFileName(dir + QStringLiteral("status")); | 133 | mFile.setFileName(dir + QStringLiteral("status")); | ||
134 | if(!mFile.open(QIODevice::ReadOnly)) | 134 | if(!mFile.open(QIODevice::ReadOnly)) | ||
135 | return false; /* process has terminated in the meantime */ | 135 | return false; /* process has terminated in the meantime */ | ||
136 | 136 | | |||
137 | process->setUid(0); | 137 | process->setUid(0); | ||
138 | process->setGid(0); | 138 | process->setGid(0); | ||
139 | process->setTracerpid(-1); | 139 | process->setTracerpid(-1); | ||
140 | process->setNumThreads(0); | 140 | process->setNumThreads(0); | ||
141 | process->setNoNewPrivileges(0); | ||||
141 | 142 | | |||
142 | int size; | 143 | int size; | ||
143 | int found = 0; //count how many fields we found | 144 | int found = 0; //count how many fields we found | ||
144 | while( (size = mFile.readLine( mBuffer, sizeof(mBuffer))) > 0) { //-1 indicates an error | 145 | while( (size = mFile.readLine( mBuffer, sizeof(mBuffer))) > 0) { //-1 indicates an error | ||
145 | switch( mBuffer[0]) { | 146 | switch( mBuffer[0]) { | ||
146 | case 'N': | 147 | case 'N': | ||
147 | if((unsigned int)size > sizeof("Name:") && qstrncmp(mBuffer, "Name:", sizeof("Name:")-1) == 0) { | 148 | if((unsigned int)size > sizeof("Name:") && qstrncmp(mBuffer, "Name:", sizeof("Name:")-1) == 0) { | ||
148 | if(process->command().isEmpty()) | 149 | if(process->command().isEmpty()) | ||
149 | process->setName(QString::fromLocal8Bit(mBuffer + sizeof("Name:")-1, size-sizeof("Name:")+1).trimmed()); | 150 | process->setName(QString::fromLocal8Bit(mBuffer + sizeof("Name:")-1, size-sizeof("Name:")+1).trimmed()); | ||
150 | if(++found == 5) goto finish; | 151 | if(++found == 6) goto finish; | ||
152 | } else if((unsigned int)size > sizeof("NoNewPrivs:") && qstrncmp(mBuffer, "NoNewPrivs:", sizeof("NoNewPrivs:")-1) == 0) { | ||||
153 | process->setNoNewPrivileges(atol(mBuffer + sizeof("NoNewPrivs:")-1)); | ||||
154 | if(++found == 6) goto finish; | ||||
151 | } | 155 | } | ||
152 | break; | 156 | break; | ||
153 | case 'U': | 157 | case 'U': | ||
154 | if((unsigned int)size > sizeof("Uid:") && qstrncmp(mBuffer, "Uid:", sizeof("Uid:")-1) == 0) { | 158 | if((unsigned int)size > sizeof("Uid:") && qstrncmp(mBuffer, "Uid:", sizeof("Uid:")-1) == 0) { | ||
155 | qlonglong uid; | 159 | qlonglong uid; | ||
156 | qlonglong euid; | 160 | qlonglong euid; | ||
157 | qlonglong suid; | 161 | qlonglong suid; | ||
158 | qlonglong fsuid; | 162 | qlonglong fsuid; | ||
159 | sscanf(mBuffer + sizeof("Uid:") -1, "%Ld %Ld %Ld %Ld", &uid, &euid, &suid, &fsuid); | 163 | sscanf(mBuffer + sizeof("Uid:") -1, "%Ld %Ld %Ld %Ld", &uid, &euid, &suid, &fsuid); | ||
160 | process->setUid(uid); | 164 | process->setUid(uid); | ||
161 | process->setEuid(euid); | 165 | process->setEuid(euid); | ||
162 | process->setSuid(suid); | 166 | process->setSuid(suid); | ||
163 | process->setFsuid(fsuid); | 167 | process->setFsuid(fsuid); | ||
164 | if(++found == 5) goto finish; | 168 | if(++found == 6) goto finish; | ||
165 | } | 169 | } | ||
166 | break; | 170 | break; | ||
167 | case 'G': | 171 | case 'G': | ||
168 | if((unsigned int)size > sizeof("Gid:") && qstrncmp(mBuffer, "Gid:", sizeof("Gid:")-1) == 0) { | 172 | if((unsigned int)size > sizeof("Gid:") && qstrncmp(mBuffer, "Gid:", sizeof("Gid:")-1) == 0) { | ||
169 | qlonglong gid, egid, sgid, fsgid; | 173 | qlonglong gid, egid, sgid, fsgid; | ||
170 | sscanf(mBuffer + sizeof("Gid:")-1, "%Ld %Ld %Ld %Ld", &gid, &egid, &sgid, &fsgid); | 174 | sscanf(mBuffer + sizeof("Gid:")-1, "%Ld %Ld %Ld %Ld", &gid, &egid, &sgid, &fsgid); | ||
171 | process->setGid(gid); | 175 | process->setGid(gid); | ||
172 | process->setEgid(egid); | 176 | process->setEgid(egid); | ||
173 | process->setSgid(sgid); | 177 | process->setSgid(sgid); | ||
174 | process->setFsgid(fsgid); | 178 | process->setFsgid(fsgid); | ||
175 | if(++found == 5) goto finish; | 179 | if(++found == 6) goto finish; | ||
176 | } | 180 | } | ||
177 | break; | 181 | break; | ||
178 | case 'T': | 182 | case 'T': | ||
179 | if((unsigned int)size > sizeof("TracerPid:") && qstrncmp(mBuffer, "TracerPid:", sizeof("TracerPid:")-1) == 0) { | 183 | if((unsigned int)size > sizeof("TracerPid:") && qstrncmp(mBuffer, "TracerPid:", sizeof("TracerPid:")-1) == 0) { | ||
180 | process->setTracerpid(atol(mBuffer + sizeof("TracerPid:")-1)); | 184 | process->setTracerpid(atol(mBuffer + sizeof("TracerPid:")-1)); | ||
181 | if (process->tracerpid() == 0) | 185 | if (process->tracerpid() == 0) | ||
182 | process->setTracerpid(-1); | 186 | process->setTracerpid(-1); | ||
183 | if(++found == 5) goto finish; | 187 | if(++found == 6) goto finish; | ||
184 | } else if((unsigned int)size > sizeof("Threads:") && qstrncmp(mBuffer, "Threads:", sizeof("Threads:")-1) == 0) { | 188 | } else if((unsigned int)size > sizeof("Threads:") && qstrncmp(mBuffer, "Threads:", sizeof("Threads:")-1) == 0) { | ||
185 | process->setNumThreads(atol(mBuffer + sizeof("Threads:")-1)); | 189 | process->setNumThreads(atol(mBuffer + sizeof("Threads:")-1)); | ||
186 | if(++found == 5) goto finish; | 190 | if(++found == 6) goto finish; | ||
187 | } | 191 | } | ||
188 | break; | 192 | break; | ||
189 | default: | 193 | default: | ||
190 | break; | 194 | break; | ||
191 | } | 195 | } | ||
192 | } | 196 | } | ||
193 | 197 | | |||
194 | finish: | 198 | finish: | ||
▲ Show 20 Lines • Show All 525 Lines • Show Last 20 Lines |