Hi,
I never used sagan in the past, now i'm planning to use it to parse logs and get some alerts, after compile the 0.3.0 version i get strange SIGSEGV, i also try with lastest Git versión, and the problem remanins, after executing it with gdb and strace i figure the problem is in sagan (sagan.c), it tries to open the FIFO, but don't check it in fclose(), this is the strace:
stat64("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2593, ...}) = 0
write(3, "[*] [08/21/2013 15:40:59] - \n", 29) = 29
write(1, "[*] \n", 5[*]
) = 5
time(NULL) = 1377092459
stat64("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2593, ...}) = 0
write(3, "[*] [08/21/2013 15:40:59] - Atte"..., 78) = 78
write(1, "[*] Attempting to open syslog FI"..., 54[*] Attempting to open syslog FIFO (/tmp/sagan.fifo).
) = 54
open("/tmp/sagan.fifo", O_RDONLY) = -1 EACCES (Permission denied)
time(NULL) = 1377092459
stat64("/etc/localtime", {st_mode=S_IFREG|0644, st_size=2593, ...}) = 0
write(3, "[*] [08/21/2013 15:40:59] - Succ"..., 72) = 72
write(1, "[*] Successfully opened FIFO (/t"..., 48[*] Successfully opened FIFO (/tmp/sagan.fifo).
) = 48
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++
Segmentation fault
Open the FIFO gets EACCES, but Sagan display in logs: Successfully opened FIFO (/tmp/sagan.fifo)
After this the entire while(fd != NULL) { is skiped, and a call to fclose(NULL) produce a SIGSEGV.
A simple if arround fclose solves the problem, but intriduce the posibility that if the file isn't accesible a infinite loop atempting to open the file will eat a lot of resources.
FILE *fd;
fd = fopen(config->sagan_fifo, "r");
if ( config->sagan_fifo_flag == 0 ) {
Sagan_Log(0, "Successfully opened FIFO (%s).", config->sagan_fifo);
} else {
Sagan_Log(0, "Successfully opened FILE (%s) and processing events.....", config->sagan_fifo);
}
while(fd != NULL) {
...
sleep(1); /* So we don't eat 100% CPU */
} /* while(fd != NULL) */
fclose(fd); /* ???? */
} /* End of while(1) */
When i get some free time, I'll review the code with some time and send a patch if nobody solved this, a off-topic question,
I see that the code identation is something strange, my first read of the code, is some comfusing for me.
Is there any coding standard to contribute code to the project?
Really good software and a very good work.
Regards.