util: introduce get_process_gid()

This commit is contained in:
Lennart Poettering
2012-09-18 01:53:15 +02:00
parent e2417e4143
commit 901c3d0d85
2 changed files with 12 additions and 3 deletions
+11 -3
View File
@@ -1108,7 +1108,7 @@ int get_process_exe(pid_t pid, char **name) {
return r;
}
int get_process_uid(pid_t pid, uid_t *uid) {
static int get_process_id(pid_t pid, const char *field, uid_t *uid) {
char *p;
FILE *f;
int r;
@@ -1140,8 +1140,8 @@ int get_process_uid(pid_t pid, uid_t *uid) {
l = strstrip(line);
if (startswith(l, "Uid:")) {
l += 4;
if (startswith(l, field)) {
l += strlen(field);
l += strspn(l, WHITESPACE);
l[strcspn(l, WHITESPACE)] = 0;
@@ -1159,6 +1159,14 @@ finish:
return r;
}
int get_process_uid(pid_t pid, uid_t *uid) {
return get_process_id(pid, "Uid:", uid);
}
int get_process_gid(pid_t pid, gid_t *gid) {
return get_process_id(pid, "Gid:", gid);
}
char *strnappend(const char *s, const char *suffix, size_t b) {
size_t a;
char *r;
+1
View File
@@ -246,6 +246,7 @@ int get_process_comm(pid_t pid, char **name);
int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char **line);
int get_process_exe(pid_t pid, char **name);
int get_process_uid(pid_t pid, uid_t *uid);
int get_process_gid(pid_t pid, gid_t *gid);
char hexchar(int x);
int unhexchar(char c);