system/corennnnn
Révision | d28cb2befd083eb0a9b0435cf5c8e768d08f94c7 (tree) |
---|---|
l'heure | 2016-09-04 08:47:14 |
Auteur | Steve Kondik <steve@cyng...> |
Commiter | Steve Kondik |
adb: Check for alternate shell paths
Change-Id: I191b9289b176809ef754d7a8126acfd355ab009f
@@ -85,6 +85,7 @@ | ||
85 | 85 | #include <pty.h> |
86 | 86 | #include <pwd.h> |
87 | 87 | #include <sys/select.h> |
88 | +#include <sys/stat.h> | |
88 | 89 | #include <termios.h> |
89 | 90 | |
90 | 91 | #include <memory> |
@@ -103,6 +104,8 @@ | ||
103 | 104 | #include "adb_utils.h" |
104 | 105 | #include "security_log_tags.h" |
105 | 106 | |
107 | +#include "cutils/properties.h" | |
108 | + | |
106 | 109 | namespace { |
107 | 110 | |
108 | 111 | void init_subproc_child() |
@@ -228,6 +231,7 @@ bool Subprocess::ForkAndExec(std::string* error) { | ||
228 | 231 | ScopedFd child_stdinout_sfd, child_stderr_sfd; |
229 | 232 | ScopedFd parent_error_sfd, child_error_sfd; |
230 | 233 | char pts_name[PATH_MAX]; |
234 | + char propbuf[PATH_MAX]; | |
231 | 235 | |
232 | 236 | if (command_.empty()) { |
233 | 237 | __android_log_security_bswrite(SEC_TAG_ADB_SHELL_INTERACTIVE, ""); |
@@ -334,12 +338,25 @@ bool Subprocess::ForkAndExec(std::string* error) { | ||
334 | 338 | parent_error_sfd.Reset(); |
335 | 339 | close_on_exec(child_error_sfd.fd()); |
336 | 340 | |
341 | + std::string shell_command; | |
342 | + struct stat st; | |
343 | + property_get("persist.sys.adb.shell", propbuf, ""); | |
344 | + if (propbuf[0] != '\0' && stat(propbuf, &st) == 0) { | |
345 | + shell_command = propbuf; | |
346 | + } else if (stat(_PATH_BSHELL2, &st) == 0) { | |
347 | + shell_command = _PATH_BSHELL2; | |
348 | + } else { | |
349 | + shell_command = _PATH_BSHELL; | |
350 | + } | |
351 | + | |
337 | 352 | if (command_.empty()) { |
338 | - execle(_PATH_BSHELL, _PATH_BSHELL, "-", nullptr, cenv.data()); | |
353 | + execle(shell_command.c_str(), shell_command.c_str(), "-", nullptr, cenv.data()); | |
339 | 354 | } else { |
340 | - execle(_PATH_BSHELL, _PATH_BSHELL, "-c", command_.c_str(), nullptr, cenv.data()); | |
355 | + execle(shell_command.c_str(), shell_command.c_str(), "-c", command_.c_str(), nullptr, cenv.data()); | |
341 | 356 | } |
342 | - WriteFdExactly(child_error_sfd.fd(), "exec '" _PATH_BSHELL "' failed: "); | |
357 | + | |
358 | + std::string errmsg = "exec '" + shell_command + "' failed: "; | |
359 | + WriteFdExactly(child_error_sfd.fd(), errmsg.c_str()); | |
343 | 360 | WriteFdExactly(child_error_sfd.fd(), strerror(errno)); |
344 | 361 | child_error_sfd.Reset(); |
345 | 362 | _Exit(1); |