devproc: add user file to /proc/$PID
authorFergus Simpson <afergs@google.com>
Thu, 5 Jan 2017 17:53:43 +0000 (09:53 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 18 Jan 2017 18:27:54 +0000 (13:27 -0500)
The owner of a process is indicated by the owner of the directory for
the process in /proc, but Akaros's bash can't read directory owners
correctly.

This adds a read-only "user" file to /proc/$PID so one can just cat for
the owner of a process.

Change-Id: I86ecfabaed2da983f33298d8a47b966862b1a369
Signed-off-by: Fergus Simpson <afergs@google.com>
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/drivers/dev/proc.c

index 2c406e2..ea35586 100644 (file)
@@ -57,6 +57,7 @@ enum {
        Qnotepg,
        Qproc,
        Qregs,
+       Quser,
        Qsegment,
        Qstatus,
        Qstrace,
@@ -120,6 +121,7 @@ struct dirtab procdir[] = {
        {"ns", {Qns}, 0, 0444},
        {"proc", {Qproc}, 0, 0400},
        //  {"regs",        {Qregs},    sizeof(Ureg),       0000},
+       {"user", {Quser}, 0, 0444},
        {"segment", {Qsegment}, 0, 0444},
        {"status", {Qstatus}, STATSIZE, 0444},
        {"strace", {Qstrace}, 0, 0666},
@@ -611,6 +613,7 @@ static struct chan *procopen(struct chan *c, int omode)
                                error(EPERM, ERROR_FIXME);
                        c->aux = kzmalloc(sizeof(struct mntwalk), MEM_WAIT);
                        break;
+               case Quser:
                case Qstatus:
                case Qvmstatus:
                case Qctl:
@@ -950,6 +953,13 @@ static long procread(struct chan *c, void *va, long n, int64_t off)
                default:
                        proc_decref(p);
                        break;
+               case Quser: {
+                               int i;
+
+                               i = readstr(off, va, n, p->user.name);
+                               proc_decref(p);
+                               return i;
+                       }
                case Qstatus:{
                                /* the old code grew the stack and was hideous.
                                 * status is not a high frequency operation; just malloc. */