Merge pull request #457 from jackyzy823/master
Some checks failed
Debug build / build (push) Has been cancelled
Validate Gradle Wrapper / Validation (push) Has been cancelled
Test native code / test (push) Has been cancelled
Windows build / build (push) Has been cancelled

Change working directory before calling pcapd under su.

Fixes #314
This commit is contained in:
Emanuele Faranda 2024-09-11 18:47:28 +02:00 committed by GitHub
commit d2bde7b9e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -239,7 +239,22 @@ int start_subprocess(const char *prog, const char *args, bool as_root, int* out_
close(in_p[0]);
// write "su" command input
// write "su"/"sh" command input
if(as_root) {
// Some su implementations (e.g. Android-x86) change the PWD when activated,
// cd to the cache dir to ensure that the UNIX socket can be found by pcapd
char* cwd = getcwd(NULL, 0);
if (cwd) {
log_d("start_subprocess[%d]: cd %s", pid, cwd);
write(in_p[1], "cd \"",4);
write(in_p[1], cwd, strlen(cwd));
write(in_p[1], "\"\n", 2);
free(cwd);
} else
log_w("start_subprocess[%d]: getcwd failed[%d]: %s - non-magisk 'su' may fail",
pid, errno, strerror(errno));
}
log_d("start_subprocess[%d]: %s %s", pid, prog, args);
write(in_p[1], prog, strlen(prog));
write(in_p[1], " ", 1);