remove legacy commented code
use new open_tmp_file helper
rename var
fix open_tmp_file return value
add read permitions