MCPcopy Create free account
hub / github.com/RsyncProject/rsync / openat2_usable

Function openat2_usable

android.c:43–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41#endif
42
43int openat2_usable(void)
44{
45#if defined(__ANDROID__) && defined(HAVE_OPENAT2)
46 static int cached = -1;
47 struct sigaction sa, old_sa;
48
49 if (cached >= 0)
50 return cached;
51
52 memset(&sa, 0, sizeof sa);
53 sa.sa_handler = openat2_probe_handler;
54 sigemptyset(&sa.sa_mask);
55 if (sigaction(SIGSYS, &sa, &old_sa) != 0)
56 return cached = 0;
57
58 if (sigsetjmp(openat2_probe_env, 1) != 0) {
59 /* SIGSYS delivered: openat2 is blocked by a seccomp filter. */
60 cached = 0;
61 } else {
62 struct open_how how;
63 int fd;
64 memset(&how, 0, sizeof how);
65 how.flags = O_RDONLY | O_DIRECTORY;
66 how.resolve = RESOLVE_BENEATH | RESOLVE_NO_MAGICLINKS;
67 fd = syscall(SYS_openat2, AT_FDCWD, ".", &how, sizeof how);
68 if (fd >= 0)
69 close(fd);
70 /* Usable only if the probe actually succeeded. Any failure --
71 * ENOSYS (kernel < 5.6), a seccomp SECCOMP_RET_ERRNO denial
72 * (EPERM/EACCES), or EINVAL (RESOLVE_BENEATH unsupported) --
73 * means we must fall back to the portable O_NOFOLLOW walk. */
74 cached = fd >= 0;
75 }
76
77 sigaction(SIGSYS, &old_sa, NULL);
78 return cached;
79#else
80 return 1;
81#endif
82}

Callers 1

openat2_beneathFunction · 0.85

Calls 1

sigactionClass · 0.70

Tested by

no test coverage detected