dumpsys中的管道与thefuck的原理猜想

dumpsys命令是Android中非常实用的命令,通过在dumpsys程序中发起向server端的binder调用来执行server端的dump方法,

打印出server端的相应信息。

之前的dumpsys的代码实现比较清晰,似乎是Android 6后,进行了修改,很上去复杂了不少

 

frameworks/native/cmds/dumpsys/dumpsys.cpp

 

185            int sfd[2];
186
187            if (pipe(sfd) != 0) {
188                aerr << "Failed to create pipe to dump service info for " << service_name
189                     << ": " << strerror(errno) << endl;
190                continue;
191            }
192
193            unique_fd local_end(sfd[0]);
194            unique_fd remote_end(sfd[1]);

使用了管道,把写端的fd传给了远程服务,可以从读端的fd获取数据,通过管道的中转,可以进行超时处理

 

 

thefuck工具似乎就是使用了类似的管道处理机制,获取到命令的打印信息,再把输错的命令修正过来

➜ puthon
No command 'puthon' found, did you mean:
 Command 'python' from package 'python-minimal' (main)
 Command 'python' from package 'python3' (main)
zsh: command not found: puthon

➜ fuck
python [enter/↑/↓/ctrl+c]
Python 3.4.2 (default, Oct  8 2014, 13:08:17)
...

 

https://www.jianshu.com/p/58675fdbe9e2

https://github.com/nvbn/thefuck

 

 

发布了336 篇原创文章 · 获赞 13 · 访问量 33万+

猜你喜欢

转载自blog.csdn.net/aaajj/article/details/103328353
今日推荐