From 9be48af56bb1fa3d738ea0b5ac5271a9df136718 Mon Sep 17 00:00:00 2001 From: jackyzy823 Date: Wed, 11 Sep 2024 10:52:07 +0800 Subject: [PATCH] Change working directory before calling pcapd under su. Some implementation of Android su will reset environment variables, so the current working directory will not be preserved. To make sure the creation of pid file and log file, change working directory manually. --- app/src/main/jni/common/utils.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/jni/common/utils.c b/app/src/main/jni/common/utils.c index 71507c61..1de33f02 100644 --- a/app/src/main/jni/common/utils.c +++ b/app/src/main/jni/common/utils.c @@ -240,6 +240,13 @@ int start_subprocess(const char *prog, const char *args, bool as_root, int* out_ close(in_p[0]); // write "su" command input + if(as_root) { + char* cwd = getcwd(NULL, 0); + log_d("start_subprocess[%d]: cd %s", pid, cwd); + write(in_p[1], "cd ",3); + write(in_p[1], cwd, strlen(cwd)); + write(in_p[1], "\n", 1); + } log_d("start_subprocess[%d]: %s %s", pid, prog, args); write(in_p[1], prog, strlen(prog)); write(in_p[1], " ", 1);