On 5 February 2011 13:39, Jonathan Conder <jonno.con...@gmail.com> wrote:
> According to FOPEN(3), using fclose on an fdopen'd file stream also > closes the underlying file descriptor. This happened in _alpm_lckmk > (util.c), which meant that when alpm_trans_release closed it again, the > log file (which reused the original file descriptor) was closed instead. > I wrote a small test case for this in order to better explain the bug. You can compile it with gcc test.c -o test -Wall -pedantic -lalpm It will create a log file at /tmp/pacman.log and can be run without root privileges. The expected contents of this log should be two lines, as you can probably tell from the source. However, without my patch the second line is not logged. Thanks, Jonathan
#include <stdio.h> #include <alpm.h> int main(int argc, const char *argv[]) { if(alpm_initialize() < 0) { return(1); } alpm_option_set_root("/"); alpm_option_set_dbpath("/tmp"); alpm_option_set_logfile("/tmp/pacman.log"); if(alpm_trans_init(0, NULL, NULL, NULL) < 0) { return(2); } alpm_logaction((char *) "line 1\n"); if(alpm_trans_release() < 0) { return(3); } alpm_logaction((char *) "line 2\n"); if(alpm_release() < 0) { return(4); } return(0); }