+static int snort_read(user_data_t *ud){
+ instance_definition_t *id;
+
+ int fd;
+
+ struct stat sb;
+
+ /* mmap, char pointers */
+ char *p_start;
+
+ id = ud->data;
+ DEBUG("snort plugin: snort_read (instance = %s)", id->name);
+
+ fd = open(id->path, O_RDONLY);
+ if (fd == -1){
+ ERROR("snort plugin: Unable to open `%s'.", id->path);
+ return (-1);
+ }
+
+ if ((fstat(fd, &sb) != 0) || (!S_ISREG(sb.st_mode))){
+ ERROR("snort plugin: `%s' is not a file.", id->path);
+ close (fd);
+ return (-1);
+ }
+
+ if (sb.st_size == 0){
+ ERROR("snort plugin: `%s' is empty.", id->path);
+ close (fd);
+ return (-1);
+ }
+
+ p_start = mmap(/* addr = */ NULL, sb.st_size, PROT_READ, MAP_SHARED, fd,
+ /* offset = */ 0);
+ if (p_start == MAP_FAILED){
+ ERROR("snort plugin: mmap error");
+ close (fd);
+ return (-1);
+ }
+
+ snort_read_buffer (id, p_start, (size_t) sb.st_size);
+
+ /* Done with mmap and file pointer */
+ close(fd);
+ munmap(p_start, sb.st_size);
+ return (0);
+}
+