Workaround compiler optimization bug

This commit is contained in:
topjohnwu
2018-02-21 14:44:24 +08:00
parent 0afa601551
commit 9c6e64f47d
3 changed files with 5 additions and 2 deletions

View File

@ -339,7 +339,7 @@ static void patch_socket_name(const char *path) {
mmap_rw(path, &buf, &size);
if (SOCKET_OFF < 0) {
for (int i = 0; i < size; ++i) {
if (memcmp(buf + i, SOCKET_NAME, sizeof(SOCKET_NAME)) == 0) {
if (memcmp(buf + i, socket_name, sizeof(SOCKET_NAME)) == 0) {
SOCKET_OFF = i;
break;
}

View File

@ -8,13 +8,15 @@
#include "utils.h"
#include "magisk.h"
char socket_name[] = SOCKET_NAME;
/* Setup the address and return socket fd */
int setup_socket(struct sockaddr_un *sun) {
int fd = xsocket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
memset(sun, 0, sizeof(*sun));
sun->sun_family = AF_LOCAL;
sun->sun_path[0] = '\0';
memcpy(sun->sun_path + 1, SOCKET_NAME, sizeof(SOCKET_NAME));
memcpy(sun->sun_path + 1, socket_name, sizeof(SOCKET_NAME));
return fd;
}