Skip to content

Commit

Permalink
support adb-shell style cpp_rpc (apache#8223)
Browse files Browse the repository at this point in the history
* support adb-shell style cpp_rpc

* fix review problems,  apache#8223

* add comment & use /data/local/tmp dir in shell terminal case

* fix spelling errors

* fix spelling errors

Co-authored-by: rqg <ranqingguo90@qq.com>
Co-authored-by: rqg <ranqingguo318@gmail.com>
  • Loading branch information
3 people authored and ylc committed Jan 13, 2022
1 parent 74ca50b commit b10c3bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion apps/cpp_rpc/rpc_env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ int mkdir(const char* path, int /* ignored */) { return _mkdir(path); }
#include <iostream>
#include <string>
#include <vector>

#include "../../src/support/utils.h"
#include "rpc_env.h"

Expand Down Expand Up @@ -95,7 +96,16 @@ RPCEnv::RPCEnv(const std::string& wd) {
auto cmdline = fopen("/proc/self/cmdline", "r");
fread(cwd, 1, sizeof(cwd), cmdline);
fclose(cmdline);
base_ = "/data/data/" + std::string(cwd) + "/cache/rpc";
std::string android_base_ = "/data/data/" + std::string(cwd) + "/cache";
struct stat statbuf;
// Check if application data directory exist. If not exist, usually means we run tvm_rpc from
// adb shell terminal.
if (stat(android_base_.data(), &statbuf) == -1 || !S_ISDIR(statbuf.st_mode)) {
// Tmp directory is always writable for 'shell' user.
android_base_ = "/data/local/tmp";
}
base_ = android_base_ + "/rpc";

#elif !defined(_WIN32)
char cwd[PATH_MAX];
if (getcwd(cwd, sizeof(cwd))) {
Expand Down
2 changes: 1 addition & 1 deletion apps/cpp_rpc/rpc_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class RPCServer {
auto pid = fork();
if (pid == 0) {
ServerLoopProc(conn, addr, work_dir_);
exit(0);
_exit(0);
}
// Wait for the result
int status = 0;
Expand Down

0 comments on commit b10c3bb

Please sign in to comment.