Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: fusl/src/unistd/faccessat.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fusl/src/unistd/dup3.c ('k') | fusl/src/unistd/fchdir.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include <unistd.h>
2 #include <fcntl.h>
3 #include <errno.h>
4 #include <sys/wait.h>
5 #include "syscall.h"
6 #include "pthread_impl.h"
7
8 struct ctx {
9 int fd;
10 const char *filename;
11 int amode;
12 };
13
14 static const int errors[] = {
15 0, -EACCES, -ELOOP, -ENAMETOOLONG, -ENOENT, -ENOTDIR,
16 -EROFS, -EBADF, -EINVAL, -ETXTBSY,
17 -EFAULT, -EIO, -ENOMEM,
18 -EBUSY
19 };
20
21 static int checker(void *p)
22 {
23 struct ctx *c = p;
24 int ret;
25 int i;
26 if (__syscall(SYS_setregid, __syscall(SYS_getegid), -1)
27 || __syscall(SYS_setreuid, __syscall(SYS_geteuid), -1))
28 __syscall(SYS_exit, 1);
29 ret = __syscall(SYS_faccessat, c->fd, c->filename, c->amode, 0);
30 for (i=0; i < sizeof errors/sizeof *errors - 1 && ret!=errors[i]; i++);
31 return i;
32 }
33
34 int faccessat(int fd, const char *filename, int amode, int flag)
35 {
36 if (!flag || (flag==AT_EACCESS && getuid()==geteuid() && getgid()==geteg id()))
37 return syscall(SYS_faccessat, fd, filename, amode, flag);
38
39 if (flag != AT_EACCESS)
40 return __syscall_ret(-EINVAL);
41
42 char stack[1024];
43 sigset_t set;
44 pid_t pid;
45 int ret = -EBUSY;
46 struct ctx c = { .fd = fd, .filename = filename, .amode = amode };
47
48 __block_all_sigs(&set);
49
50 pid = __clone(checker, stack+sizeof stack, 0, &c);
51 if (pid > 0) {
52 int status;
53 do {
54 __syscall(SYS_wait4, pid, &status, __WCLONE, 0);
55 } while (!WIFEXITED(status) && !WIFSIGNALED(status));
56 if (WIFEXITED(status))
57 ret = errors[WEXITSTATUS(status)];
58 }
59
60 __restore_sigs(&set);
61
62 return __syscall_ret(ret);
63 }
OLDNEW
« no previous file with comments | « fusl/src/unistd/dup3.c ('k') | fusl/src/unistd/fchdir.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698