From 6af132daa2d80608eeb817b461235af278f6aea8 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Sat, 14 Jul 2012 08:15:02 -0400 Subject: [PATCH] kern/devfs-posix: fix chmod after rename (thanks Cinap) R=rsc http://codereview.appspot.com/6401047 --- kern/devfs-posix.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/kern/devfs-posix.c b/kern/devfs-posix.c index 23a7dbc..bf3ad90 100644 --- a/kern/devfs-posix.c +++ b/kern/devfs-posix.c @@ -425,6 +425,14 @@ fswstat(Chan *c, uchar *buf, int n) uif = c->aux; + fspath(c, 0, old); + if(~d.mode != 0 && (int)(d.mode&0777) != (int)(stbuf.st_mode&0777)) { + if(chmod(old, d.mode&0777) < 0) + error(strerror(errno)); + uif->mode &= ~0777; + uif->mode |= d.mode&0777; + } + if(d.name[0] && strcmp(d.name, lastelem(c)) != 0) { fspath(c, 0, old); strcpy(new, old); @@ -434,13 +442,6 @@ fswstat(Chan *c, uchar *buf, int n) error(strerror(errno)); } - fspath(c, 0, old); - if(~d.mode != 0 && (int)(d.mode&0777) != (int)(stbuf.st_mode&0777)) { - if(chmod(old, d.mode&0777) < 0) - error(strerror(errno)); - uif->mode &= ~0777; - uif->mode |= d.mode&0777; - } /* p = name2pass(gid, d.gid); if(p == 0)