diff --git a/native/jni/init/rootdir.cpp b/native/jni/init/rootdir.cpp index b0fd5fb77..addd637a0 100644 --- a/native/jni/init/rootdir.cpp +++ b/native/jni/init/rootdir.cpp @@ -217,14 +217,7 @@ static void recreate_sbin(const char *mirror, bool use_bind_mount) { struct stat st; fstatat(src, entry->d_name, &st, AT_SYMLINK_NOFOLLOW); if (S_ISLNK(st.st_mode)) { -#if defined(__i386__) - // readlinkat() may failed on x86 platform, returning random value - // instead of number of bytes placed in buf (length of link) - memset(buf, 0, sizeof(buf)); - readlinkat(src, entry->d_name, buf, sizeof(buf)); -#else xreadlinkat(src, entry->d_name, buf, sizeof(buf)); -#endif xsymlink(buf, sbin_path.data()); } else { sprintf(buf, "%s/%s", mirror, entry->d_name); diff --git a/native/jni/utils/xwrap.cpp b/native/jni/utils/xwrap.cpp index 29a6db369..4abce6b2d 100644 --- a/native/jni/utils/xwrap.cpp +++ b/native/jni/utils/xwrap.cpp @@ -285,13 +285,24 @@ ssize_t xreadlink(const char *pathname, char *buf, size_t bufsiz) { } ssize_t xreadlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz) { + // readlinkat() may fail on x86 platform, returning random value + // instead of number of bytes placed in buf (length of link) +#if defined(__i386__) || defined(__x86_64__) + memset(buf, 0, bufsiz); ssize_t ret = readlinkat(dirfd, pathname, buf, bufsiz); if (ret == -1) { PLOGE("readlinkat %s", pathname); + } + return ret; +#else + ssize_t ret = readlinkat(dirfd, pathname, buf, bufsiz); + if (ret < 0) { + PLOGE("readlinkat %s", pathname); } else { buf[ret] = '\0'; } return ret; +#endif } int xsymlink(const char *target, const char *linkpath) {