[转]查找项目中的线程不安全API使用
2009-10-22 19:19
429 查看
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 |
然后,通过find和grep获得项目的源代码文件列表
FileList=$(find $WorkDir -type f | grep -iP '/.(c|cpp|cxx|h|hxx)$') |
APIList=$(cat api.txt) |
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 |
相关文章推荐
- 线程池动态并安全地中断所有线程不需要使用shutdownnow()同时可以继续添加任务
- (7)java5线程并发库的应用(线程池) 以及在实际项目中的使用。。
- 线程安全:分配堆与内存 API:HeapCreate HeapAlloc HeapSize HeapFree HeapDestroy
- 使用Windows API PostThreadMessage进行线程间消息通信
- 项目开发中的一些注意事项以及技巧总结 基于Repository模式设计项目架构—你可以参考的项目架构设计 Asp.Net Core中使用RSA加密 EF Core中的多对多映射如何实现? asp.net core下的如何给网站做安全设置 获取服务端https证书 Js异常捕获
- Google Play Service中安全检测API的使用说明
- 使用 OpenSSL API 进行安全编程
- 使用 OpenSSL API 建立安全连接 - 双向认证
- 使用 OpenSSL API 进行安全编程
- 使用 OpenSSL API 进行安全编程,第 2 部分: 安全握手(二)
- JAVA线程安全相关数据结构使用建议
- 使用 OpenSSL API 进行安全编程
- 使用eclipse 生成自己项目的API帮助文档
- 使用OpenSSL API 建立SSL安全通信的一般流程
- 对象使用中的线程安全和线程不安全问题
- HTML5项目笔记4:使用Audio API设计绚丽的HTML5音乐播放器
- MSIL 教程(二):数组、分支、循环、使用不安全代码和如何调用Win32 API
- 使用线程时应注意的安全问题
- 项目中使用到的封装---后台子线程执行任务,前台显示加载条
- 使用Xcode查找项目中的中文字符串