summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-09-18 01:53:15 +0200
committerLennart Poettering <lennart@poettering.net>2012-09-18 01:53:15 +0200
commit901c3d0d85628e6a4708bc9748766029cf5c7f97 (patch)
tree5ae17d1b8a2451cebc081c4a5ded25a66beec7c8 /src/shared/util.c
parente2417e4143bb892e4599b01de7b031763421bb64 (diff)
util: introduce get_process_gid()
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 20e5faf34b..59c1417b44 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -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;