Android6.0 init.rc中创建符号链接失败问题

来源:互联网 发布:网络电视套餐 编辑:程序博客网 时间:2024/06/02 01:13

Android6.0直接在init.rc创建符号链接问题失败,说明Android6.0对权限控制更加严格了。

看看我们一开始在init.rc中的修改:

on init    # See storage config details at http://source.android.com/tech/storage/    symlink /storage/self/primary /mnt/sdcard    symlink /storage/self/primary /storage/sdcard0

在我们自己的init.rc中的init中增加下面两个软链接,没有成功,不知道什么原因,于是想在init进程中打下log

int do_symlink(int nargs, char **args){int result;const char * str = "/storage/self/primary";char *resultstr;result = symlink(args[1], args[2]);if (strcmp(args[1],str) == 0) {ERROR("1111 do_symlink str:'%s' result:%d\n", args[2], result);}if (result == -1) {resultstr = strerror(errno);ERROR("1122 do_symlink str:'%s' resultstr:'%s'\n", args[2], resultstr);}    return result;}

在init进程中修改了do_symlink函数,增加了log,最后看dmesglong发现是没有权限。


于是准备在init.te文件中增加权限,发现init.te中对根目录下sdcard做了软链接

仿造其修改,在init.te中修改了如下代码:

allow init rootfs:lnk_file { create unlink };allow init storage_file:lnk_file { create unlink };allow init tmpfs:lnk_file { create unlink };

其中storage_file和tmpfs这两个类型,通过ls -Z可以查看。


修改了以后,发现/mnt/sdcard的软链接成功了,但是storage没有成功,后面发现,在post-fs中有如下代码

on post-fs    start logd    #add for amt    chmod 0755 /amt    # once everything is setup, no need to modify /    mount rootfs rootfs / ro remount    # Mount shared so changes propagate into child namespaces    mount rootfs rootfs / shared rec    # Mount default storage into root namespace    mount none /mnt/runtime/default /storage slave bind rec

mount一个设备到storage下面,因此我们的软链接就不充了。


因此我们要在这之后再去建软链接,

on late-init    trigger early-fs    trigger fs    trigger post-fs    trigger post-fs-data    # Load properties from /system/ + /factory after fs mount. Place    # this in another action so that the load will be scheduled after the prior    # issued fs triggers have completed.    trigger load_all_props_action    # Remove a file to wake up anything waiting for firmware.    trigger firmware_mounts_complete    trigger early-boot    trigger boot

post-fs是在late-init中,因此我们可以把创建软链接放在post-fs-data

on post-fs-data    chown system system /dev/st480    chmod 0660  /dev/st480symlink /storage/self/primary /storage/sdcard0symlink /storage/self/primary /mnt/sdcard


这样就可以了,总结下需要在init.te添加创建软链接的权限,然后因为涉及到mount storage所以在storage建立的软链接没有生效。可以把创建软链接移后,放在mount storage后面








2 0