summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-01-10 04:20:55 +0100
committerLennart Poettering <lennart@poettering.net>2012-01-10 05:03:59 +0100
commit7e4ab3c5a6295193d0c58d353b6430265d842f34 (patch)
treea9b55f1b94241510f379f46ab13541e87eb0519d /src/util.c
parent6bd9fe5a734893262f2932a8e1fcfe05796f0105 (diff)
shutdown: exclude processes with argv[0][0] from killing
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index b4c5e2e65a..3179502f6c 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1119,6 +1119,57 @@ int get_process_exe(pid_t pid, char **name) {
return r;
}
+int get_process_uid(pid_t pid, uid_t *uid) {
+ char *p;
+ FILE *f;
+ int r;
+
+ assert(uid);
+
+ if (pid == 0)
+ return getuid();
+
+ if (asprintf(&p, "/proc/%lu/status", (unsigned long) pid) < 0)
+ return -ENOMEM;
+
+ f = fopen(p, "re");
+ free(p);
+
+ if (!f)
+ return -errno;
+
+ while (!feof(f)) {
+ char line[LINE_MAX], *l;
+
+ if (!fgets(line, sizeof(line), f)) {
+ if (feof(f))
+ break;
+
+ r = -errno;
+ goto finish;
+ }
+
+ l = strstrip(line);
+
+ if (startswith(l, "Uid:")) {
+ l += 4;
+ l += strspn(l, WHITESPACE);
+
+ l[strcspn(l, WHITESPACE)] = 0;
+
+ r = parse_uid(l, uid);
+ goto finish;
+ }
+ }
+
+ r = -EIO;
+
+finish:
+ fclose(f);
+
+ return r;
+}
+
char *strnappend(const char *s, const char *suffix, size_t b) {
size_t a;
char *r;