[转]查找项目中的线程不安全API使用
来源:互联网 发布:js 正则 大于0整数 编辑:程序博客网 时间:2024/05/16 14:07
http://cache.baidu.com/c?m=9d78d513d99207f407ba837e7c01a6120e22f4744cd6c7640ec0d408cd6b01070124f4ba543f0d4196806b6776f91217baae217240527de88699d50d9dfac5352e9f2040325cdb14528046b28a1c729f7e8d1bb3f847b9e2b12f93acd0d8dd5550c14e067e81f688501714bd35b64b6f&p=9f3fc54adc9b12a058f7d10c51&user=baidu
在项目中由于是基于某一个开源项目做的,由于项目暂时使用的是一个线程池模型,但是使用的那个开源库不是线程安全的,因此我们需要修改开源库的代码,使其线程安全。
对一个线程不安全的库的改造,首先要做的第一件事情,就是要修改库中的线程不安全的API的使用,于是就写了个脚本来完成这个事情。
首先,通过man 7 pthreads得到一个线程不安全的API的列表:
asctime
basename
catgets
crypt
ctermid
ctime
dbm_clearerr
dbm_close
dbm_delete
dbm_error
dbm_fetch
dbm_firstkey
dbm_nextkey
dbm_open
dbm_store
dirname
dlerror
drand48
ecvt
encrypt
endgrent
endpwent
endutxent
fcvt
ftw
gcvt
getc_unlocked
getchar_unlocked
getdate
getenv
getgrent
getgrgid
getgrnam
gethostbyaddr
gethostbyname
gethostent
getlogin
getnetbyaddr
getnetbyname
getnetent
getopt
getprotobyname
getprotobynumber
getprotoent
getpwent
getpwnam
getpwuid
getservbyname
getservbyport
getservent
getutxent
getutxid
getutxline
gmtime
hcreate
hdestroy
hsearch
inet_ntoa
l64a
lgamma
lgammaf
lgammal
localeconv
localtime
lrand48
mrand48
nftw
nl_langinfo
ptsname
putc_unlocked
putchar_unlocked
putenv
pututxline
rand
readdir
setenv
setgrent
setkey
setpwent
setutxent
strerror
strtok
tmpnam
ttyname
unsetenv
wcrtomb
wcsrtombs
wcstombs
wctomb
把这些API写入到一个文件api.txt中,每行一个。
然后,通过find和grep获得项目的源代码文件列表
FileList=$(find $WorkDir -type f | grep -iP '/.(c|cpp|cxx|h|hxx)$')获得API的列表:
APIList=$(cat api.txt)
对每一个源代码文件,分别调用grep搜索不同的API名(这样的话,频繁的读写同一个文件,会提高文件系统的缓存利用率;如果是对不同API,grep所有的源代码文件的话,就会导致文件系统缓存失效严重):
for file in $FileList
do
echo "Searching "$file" ......"
for api in $APIList
do
grep -w "$api" $file -nH >> non-thread-safe.log
done
done
脚本总体为:
if [ -z $1 ];then
WorkDir="."
else
WorkDir=$1
fi
#获得API列表
APIList=$(cat api.txt)
#获得项目源代码文件列表
FileList=$(find $WorkDir -type f | grep -iP '/.(c|cpp|cxx|h|hxx)$')
rm -f non-thread-safe.log
for file in $FileList
do
echo "Searching "$file" ......"
for api in $APIList
do
grep -w "$api" $file -nH >> non-thread-safe.log
done
done
- [转]查找项目中的线程不安全API使用
- 对象使用中的线程安全和线程不安全问题
- 使用HashMap线程不安全造成CPU 100%
- NHibernate中的线程安全与线程不安全问题
- 使用Xcode查找项目中的中文字符串
- Servlet线程不安全及解决方法【转】
- 线程安全&线程不安全
- Java线程(一):线程安全与不安全(转)
- SimpleDateFormat是线程不安全的,怎样使用使其安全?
- 查找应用中的 Private API
- qsort 线程不安全
- 线程不安全函数
- 解决ArrayList线程不安全
- Servlet线程安全?不安全?
- 线程安全和不安全
- 线程安全与不安全
- 解决ArrayList线程不安全
- java SimpleDateFormat线程不安全
- 新的起点
- Linux VI命令使用大全
- (转)C# WebBrowser准确判断网页最终装载完毕
- 解决call an undefined function exif_imagetype()
- 天下莫柔弱于水,而攻坚强者莫之能胜,以其无以易之。弱之胜强,柔之胜刚,天下莫不知,莫能行……
- [转]查找项目中的线程不安全API使用
- CentOS Tomcat 的启动服务脚本
- 键盘F1-F12
- 页面自定义拖拽布局,兼容ie5以上、firefox、Opera
- ASSERT和if用法浅谈
- 尚观培训Day4 软件安装/磁盘分区
- 内存相关函数(内存映射文件)
- 首页调用的代码
- Java开发小技巧总结