mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-28 04:25:27 +00:00
Fix random return value of faccessat() in x86
faccessat() should return 0 when success, but it returns random number with errno == 0 in x86 platform.
It’s a side effect of commit bf80b08b5f
when magisk binaries ‘corretly’ linked with library of API16 .. lol
Co-authored-by: John Wu <topjohnwu@gmail.com>
This commit is contained in:
parent
dfe1f2c108
commit
3da318b48e
@ -108,7 +108,7 @@ void mv_dir(int src, int dest) {
|
|||||||
for (dirent *entry; (entry = xreaddir(dir.get()));) {
|
for (dirent *entry; (entry = xreaddir(dir.get()));) {
|
||||||
switch (entry->d_type) {
|
switch (entry->d_type) {
|
||||||
case DT_DIR:
|
case DT_DIR:
|
||||||
if (faccessat(dest, entry->d_name, F_OK, 0) == 0) {
|
if (xfaccessat(dest, entry->d_name) == 0) {
|
||||||
// Destination folder exists, needs recursive move
|
// Destination folder exists, needs recursive move
|
||||||
int newsrc = xopenat(src, entry->d_name, O_RDONLY | O_CLOEXEC);
|
int newsrc = xopenat(src, entry->d_name, O_RDONLY | O_CLOEXEC);
|
||||||
int newdest = xopenat(dest, entry->d_name, O_RDONLY | O_CLOEXEC);
|
int newdest = xopenat(dest, entry->d_name, O_RDONLY | O_CLOEXEC);
|
||||||
|
@ -359,6 +359,20 @@ ssize_t xreadlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int xfaccessat(int dirfd, const char *pathname) {
|
||||||
|
int ret = faccessat(dirfd, pathname, F_OK, 0);
|
||||||
|
if (ret < 0) {
|
||||||
|
PLOGE("faccessat %s", pathname);
|
||||||
|
}
|
||||||
|
#if defined(__i386__) || defined(__x86_64__)
|
||||||
|
if (ret > 0 && errno == 0) {
|
||||||
|
LOGD("faccessat success but ret is %d\n", ret);
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int xsymlink(const char *target, const char *linkpath) {
|
int xsymlink(const char *target, const char *linkpath) {
|
||||||
int ret = symlink(target, linkpath);
|
int ret = symlink(target, linkpath);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
@ -42,6 +42,7 @@ int xdup2(int oldfd, int newfd);
|
|||||||
int xdup3(int oldfd, int newfd, int flags);
|
int xdup3(int oldfd, int newfd, int flags);
|
||||||
ssize_t xreadlink(const char *pathname, char *buf, size_t bufsiz);
|
ssize_t xreadlink(const char *pathname, char *buf, size_t bufsiz);
|
||||||
ssize_t xreadlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz);
|
ssize_t xreadlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz);
|
||||||
|
int xfaccessat(int dirfd, const char *pathname);
|
||||||
int xsymlink(const char *target, const char *linkpath);
|
int xsymlink(const char *target, const char *linkpath);
|
||||||
int xsymlinkat(const char *target, int newdirfd, const char *linkpath);
|
int xsymlinkat(const char *target, int newdirfd, const char *linkpath);
|
||||||
int xlinkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, int flags);
|
int xlinkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, int flags);
|
||||||
|
Loading…
Reference in New Issue
Block a user