1、现象
在升级系统是,卡在Recovery中,从串口信息看,停在
init: skipping insecure file '/default.prop'
init: skipping insecure file '/init.rc'
init: Timed out waiting for /dev/.coldboot_done
大概意思 是 跳过这些文件,但是同事和我说,init文件非常重要,怎么能跳过!
于是网上搜索了下,这个问题是因为,android从4.1以后,读取文件增加了权限判断,在 android\system\core\init\util.c
/* reads a file, making sure it is terminated with \n \0 */
void *read_file(const char *fn, unsigned *_sz)
{
char *data;
int sz;
int fd;
struct stat sb;
data = 0;
fd = open(fn, O_RDONLY);
if(fd < 0) return 0;
// for security reasons, disallow world-writable
// or group-writable files
if (fstat(fd, &sb) < 0) {
ERROR("fstat failed for '%s'\n", fn);
goto oops;
}
if ((sb.st_mode & (S_IWGRP | S_IWOTH)) != 0) {
ERROR("skipping insecure file '%s'\n", fn);
goto oops;
}
sz = lseek(fd, 0, SEEK_END);
if(sz < 0) goto oops;
if(lseek(fd, 0, SEEK_SET) != 0) goto oops;
data = (char*) malloc(sz + 2);
if(data == 0) goto oops;
if(read(fd, data, sz) != sz) goto oops;
close(fd);
data[sz] = '\n';
data[sz+1] = 0;
if(_sz) *_sz = sz;
return data;
oops:
close(fd);
if(data != 0) free(data);
return 0;
}
其中的
if ((sb.st_mode & (S_IWGRP | S_IWOTH)) != 0) {
ERROR("skipping insecure file '%s'\n", fn);
goto oops;
}
表示如果有写的权限,就跳过。
2、原因
从上面看,原因比较清楚,升级的系统包内,文件权限必然有问题:
升级有问题的:
正常的系统:
包括编译的环境,我看了下所以文件也都多了一个“w”
3、解决方法:
修改编译目录,用户权限:
umask 0022
另外,查看权限:umask -S