[英]on boot my android phone init .sh script run but not fully
堆!
这是我对此的第一个问题,所以不要对我太难。
我想在启动Android时运行自己的.sh脚本文件。 为此,我重建内核映像,然后在启动完成触发器后启动的我自己的服务中添加到init.rc文件中:
on property:dev.bootcomplete=1
start fota-snoop
start fota-trigger
start startup-prober
start fairnet
服务本身:
service fairnet /system/bin/sh /system/etc/init.fairnet.sh
user root
group root
disabled
oneshot
像其他init .sh脚本一样,将/system/etc/init.fairnet.sh的权限设置为644,所有者为root:root:
-rw-r--r-- root root 280 2018-01-09 01:03 init.fairnet.sh
init.fairnet.sh:
#!/system/bin/sh
insmod /system/lib/modules/xt_HL.ko
lsmod > /system/etc/curlsmod
/system/bin/iptables -t mangle -L > /system/etc/preiptables
/system/bin/iptables -t mangle -A POSTROUTING -o rmnet+ -j TTL --ttl-set 64
/system/bin/iptables -t mangle -L > /system/etc/postiptables
最有趣的是,加载内核模块的命令在启动时也可以正常工作,但其他字符串不起作用:输出文件不存在,iptables规则未添加。 我不明白为什么insmod可以工作,而其他命令却不能。
感谢您的阅读,对不起我的英语不好。
问题解决了!
SELinux在启动时阻止了iptables。
dmesg | grep iptables
给我
<36>[ 39.819005] type=1400 audit(1516096993.541:9): avc: denied { create } for pid=2652 comm="iptables" lport=255 scontext=u:r:init_shell:s0 tcontext=u:r:init_shell:s0 tclass=rawip_socket op_res=-13 ppid=2640 pcomm="sh" tgid=2640 tgcomm="sh"
这意味着在当前/ sepolicy中没有我需要的规则。
对于加入这一规则我使用sepolicy-注入 ,用于构建它需要/usr/lib/libsepol.a, libsepol1-dev的包含它。 也可以对所有拱门使用构建的二进制文件 (对我不起作用,我构建自己的二进制文件 )。
./sepolicy-inject -s init_shell -t init_shell -c rawip_socket -p getopt,create,setopt -P sepolicy -o sepolicy_new
添加所需的规则,并从设备的旧Sepolicy中创建新的sepolicy_new。
带有带有新bootop.img的新设备的Flash设备,我将AIK用于Win。
做完了! 现在,启动后,我的.sh脚本会自动运行并完全运行。
感谢您的阅读,并再次抱歉我的英语太糟糕了。
PS我将自己的服务从init.sony.rc替换为init.qcom.rc,并删除了root用户组并禁用了该服务,但是我这样做只是出于意识形态原因,不能解决问题。
将PPS从“强制”更改为“允许”的方式可能可以解决问题,但是我不想失去SELinux。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.