pilerimport now handles correctly the case if the file is not readable

This commit is contained in:
SJ 2012-05-23 16:42:58 +02:00
parent f7d0e270ee
commit f6ef989171

View File

@ -8,6 +8,7 @@
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h> #include <dirent.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
@ -21,7 +22,7 @@ extern int optind;
int import_message(char *filename, struct session_data *sdata, struct __data *data, struct __config *cfg){ int import_message(char *filename, struct session_data *sdata, struct __data *data, struct __config *cfg){
int rc=ERR; int rc=ERR, fd;
char *rule; char *rule;
struct stat st; struct stat st;
struct _state state; struct _state state;
@ -44,7 +45,7 @@ int import_message(char *filename, struct session_data *sdata, struct __data *da
else { else {
if(stat(filename, &st) != 0){ if(stat(filename, &st) != 0){
printf("cannot read: %s\n", filename); printf("cannot stat() %s\n", filename);
return rc; return rc;
} }
@ -53,6 +54,13 @@ int import_message(char *filename, struct session_data *sdata, struct __data *da
return rc; return rc;
} }
fd = open(filename, O_RDONLY);
if(fd == -1){
printf("cannot open %s\n", filename);
return rc;
}
close(fd);
snprintf(sdata->filename, SMALLBUFSIZE-1, "%s", filename); snprintf(sdata->filename, SMALLBUFSIZE-1, "%s", filename);
sdata->tot_len = st.st_size; sdata->tot_len = st.st_size;