]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/9/port/devpipe.c
devproc: return process id when reading /proc/n/ctl file
[plan9front.git] / sys / src / 9 / port / devpipe.c
old mode 100755 (executable)
new mode 100644 (file)
index bea354b..40491ef
@@ -14,6 +14,7 @@ struct Pipe
        Pipe    *next;
        int     ref;
        ulong   path;
+       long    perm;
        Queue   *q[2];
        int     qref[2];
 };
@@ -60,6 +61,10 @@ pipeattach(char *spec)
        Chan *c;
 
        c = devattach('|', spec);
+       if(waserror()){
+               chanfree(c);
+               nexterror();
+       }
        p = malloc(sizeof(Pipe));
        if(p == 0)
                exhausted("memory");
@@ -72,14 +77,16 @@ pipeattach(char *spec)
        }
        p->q[1] = qopen(conf.pipeqsize, 0, 0, 0);
        if(p->q[1] == 0){
-               free(p->q[0]);
+               qfree(p->q[0]);
                free(p);
                exhausted("memory");
        }
+       poperror();
 
        lock(&pipealloc);
        p->path = ++pipealloc.path;
        unlock(&pipealloc);
+       p->perm = pipedir[Qdata0].perm;
 
        mkqid(&c->qid, NETQID(2*p->path, Qdir), 0, QTDIR);
        c->aux = p;
@@ -95,7 +102,7 @@ pipegen(Chan *c, char*, Dirtab *tab, int ntab, int i, Dir *dp)
        Pipe *p;
 
        if(i == DEVDOTDOT){
-               devdir(c, c->qid, "#|", 0, eve, DMDIR|0555, dp);
+               devdir(c, c->qid, "#|", 0, eve, 0555, dp);
                return 1;
        }
        i++;    /* skip . */
@@ -116,7 +123,7 @@ pipegen(Chan *c, char*, Dirtab *tab, int ntab, int i, Dir *dp)
                break;
        }
        mkqid(&q, NETQID(NETID(c->qid.path), tab->qid.path), 0, QTFILE);
-       devdir(c, q, tab->name, len, eve, tab->perm, dp);
+       devdir(c, q, tab->name, len, eve, p->perm, dp);
        return 1;
 }
 
@@ -158,13 +165,13 @@ pipestat(Chan *c, uchar *db, int n)
 
        switch(NETTYPE(c->qid.path)){
        case Qdir:
-               devdir(c, c->qid, ".", 0, eve, DMDIR|0555, &dir);
+               devdir(c, c->qid, ".", 0, eve, 0555, &dir);
                break;
        case Qdata0:
-               devdir(c, c->qid, "data", qlen(p->q[0]), eve, 0600, &dir);
+               devdir(c, c->qid, "data", qlen(p->q[0]), eve, p->perm, &dir);
                break;
        case Qdata1:
-               devdir(c, c->qid, "data1", qlen(p->q[1]), eve, 0600, &dir);
+               devdir(c, c->qid, "data1", qlen(p->q[1]), eve, p->perm, &dir);
                break;
        default:
                panic("pipestat");
@@ -175,6 +182,36 @@ pipestat(Chan *c, uchar *db, int n)
        return n;
 }
 
+static int
+pipewstat(Chan* c, uchar* db, int n)
+{
+       int m;
+       Dir *dir;
+       Pipe *p;
+
+       p = c->aux;
+       if(strcmp(up->user, eve) != 0)
+               error(Eperm);
+       if(NETTYPE(c->qid.path) == Qdir)
+               error(Eisdir);
+
+       dir = smalloc(sizeof(Dir)+n);
+       if(waserror()){
+               free(dir);
+               nexterror();
+       }
+       m = convM2D(db, n, &dir[0], (char*)&dir[1]);
+       if(m == 0)
+               error(Eshortstat);
+       if(!emptystr(dir[0].uid))
+               error("can't change owner");
+       if(dir[0].mode != ~0UL)
+               p->perm = dir[0].mode;
+       poperror();
+       free(dir);
+       return m;
+}
+
 /*
  *  if the stream doesn't exist, create it
  */
@@ -387,5 +424,5 @@ Dev pipedevtab = {
        pipewrite,
        pipebwrite,
        devremove,
-       devwstat,
+       pipewstat,
 };