Skip to content

Commit

Permalink
Merge pull request #457 from jackyzy823/master
Browse files Browse the repository at this point in the history
Change working directory before calling pcapd under su.

Fixes #314
  • Loading branch information
emanuele-f authored Sep 11, 2024
2 parents dc3bb39 + ac3ce3a commit d2bde7b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion app/src/main/jni/common/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d2bde7b

Please sign in to comment.