feature: dumpfile list mode support read pcap file path from stdin

This commit is contained in:
luwenpeng
2024-08-20 19:29:31 +08:00
parent b46a5d4b23
commit 6e46dbf762

View File

@@ -136,15 +136,24 @@ static void *dumpfile_thread(void *arg)
} }
else // PACKET_IO_DUMPFILELIST else // PACKET_IO_DUMPFILELIST
{ {
FILE *fp = fopen(handle->dumpfile_path, "r"); FILE *fp = NULL;
if (strcmp(handle->dumpfile_path, "-") == 0)
{
PACKET_IO_LOG_ERROR("dumpfile list is empty");
fp = stdin;
}
else
{
fp = fopen(handle->dumpfile_path, "r");
if (fp == NULL) if (fp == NULL)
{ {
PACKET_IO_LOG_ERROR("unable to open dumpfile list: %s", handle->dumpfile_path); PACKET_IO_LOG_ERROR("unable to open dumpfile list: %s", handle->dumpfile_path);
goto erro_out; goto erro_out;
} }
}
char line[PATH_MAX]; char line[PATH_MAX];
while (fgets(line, sizeof(line), fp)) while (ATOMIC_READ(&handle->io_thread_need_exit) == 0 && fgets(line, sizeof(line), fp))
{ {
if (line[0] == '#') if (line[0] == '#')
{ {
@@ -159,8 +168,11 @@ static void *dumpfile_thread(void *arg)
dumpfile_handler(handle, line); dumpfile_handler(handle, line);
} }
if (fp != stdin)
{
fclose(fp); fclose(fp);
} }
}
erro_out: erro_out:
PACKET_IO_LOG_STATE("dumpfile io thread processed all pcap files"); PACKET_IO_LOG_STATE("dumpfile io thread processed all pcap files");