日期:2014-05-16  浏览次数:20694 次

linux mktemp 不可重入 问题

问题起源:

lighttpd 在接收到上传数据(PUT/POST),会生成大小为1M的很多临时文件。

线上最近有很多上传请求,lighttpd 经常报警,说上传的临时文件丢失,


分析

起初怀疑是被其它程序删除,后来勇哥提到,会不会是我们生成临时文件的方法有问题,生成了重名的临时文件?

查了lighttpd 的实现,使用的是mktemp函数:



http://linux.die.net/man/3/mktemp


If the call was successful, the last six bytes of template will have been modified in such a way that the resulting name is unique (does not exist already). If the call was unsuccessful, template is made an empty string.

Never use mktemp(). Some implementations follow 4.3BSD and replace XXXXXX by the current process ID and a single letter, so that at most 26 different names can be returned.



The tempnam() function is re-entrant while mktemp() isn't
不可重入,可能两个进程产生同一个文件名


实验:


友情链接: 爱易网 云虚拟主机技术 云服务器技术 程序设计技术 开发网站 APP开发教程
Copyright © 2013-2024 爱易网页 当前在线:785人  网站在10时49分9秒内访问总人数:135354人 当前 35.94%  粤ICP备18100884号-2