blob: f3aad38d80d64e891833b0e86716b3207d46227f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#include <u.h>
#include <libc.h>
#include <auth.h>
int
procsetuser(char *user)
{
char name[32];
Dir dir;
nulldir(&dir);
dir.uid = user;
snprint(name, sizeof(name), "/proc/%lud/ctl", (ulong)getpid());
if(dirwstat(name, &dir) < 0){
/*
* this is backwards compatibility code as
* devproc initially didnt allow changing
* the user to none.
*/
int fd;
if(strcmp(user, "none") != 0)
return -1;
fd = open("#c/user", OWRITE|OCEXEC);
if(fd < 0)
return -1;
if(write(fd, "none", 4) != 4){
close(fd);
return -1;
}
close(fd);
}
return 0;
}
|