aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYunchih Chen <yunchih.cat@gmail.com>2018-03-18 11:07:58 +0800
committerYunchih Chen <yunchih.cat@gmail.com>2018-03-18 11:07:58 +0800
commit3bff5a92132a97e872f7cdf1d2e26f26ccce772c (patch)
tree13cdec876d13aced3cd2b9efaa179946be63999d
parentbee96e970918ed4eec62609ba3823797329454fd (diff)
downloadnfcollect-3bff5a92132a97e872f7cdf1d2e26f26ccce772c.tar
nfcollect-3bff5a92132a97e872f7cdf1d2e26f26ccce772c.tar.gz
nfcollect-3bff5a92132a97e872f7cdf1d2e26f26ccce772c.tar.bz2
nfcollect-3bff5a92132a97e872f7cdf1d2e26f26ccce772c.tar.lz
nfcollect-3bff5a92132a97e872f7cdf1d2e26f26ccce772c.tar.xz
nfcollect-3bff5a92132a97e872f7cdf1d2e26f26ccce772c.tar.zst
nfcollect-3bff5a92132a97e872f7cdf1d2e26f26ccce772c.zip
Fix extraction storage fullpath
-rw-r--r--bin/nfextract.c21
-rw-r--r--include/common.h1
2 files changed, 16 insertions, 6 deletions
diff --git a/bin/nfextract.c b/bin/nfextract.c
index 00b285e..021cc9a 100644
--- a/bin/nfextract.c
+++ b/bin/nfextract.c
@@ -56,19 +56,25 @@ static void sig_handler(int signo) {
}
}
-static void extract_each(const char *filename) {
+static void extract_each(const char *storage_dir, const char *filename) {
nflog_state_t trunk;
- if (nfl_extract_worker(filename, &trunk) < 0)
+
+ // Build full path
+ char *fullpath = malloc(strlen(storage_dir) + strlen(filename) + 2);
+ sprintf(fullpath, "%s/%s", storage_dir, filename);
+
+ debug("Extracting storage file: %s", fullpath);
+ if (nfl_extract_worker(fullpath, &trunk) < 0)
return;
+ free(fullpath);
+
char output[1024];
for (int entry = 0; entry < trunk.header->n_entries; ++entry) {
nfl_format_output(output, trunk.store);
puts((char *)output);
free((char *)output);
}
-
- free((char *)filename);
}
static void extract_all(const char *storage_dir) {
@@ -82,6 +88,7 @@ static void extract_all(const char *storage_dir) {
while ((ep = readdir(dp))) {
index = nfl_storage_match_index(ep->d_name);
if (index >= 0) {
+ debug("Storage file %s matches with index %d", ep->d_name, index);
if (index >= MAX_TRUNK_ID) {
WARN(1, "Storage trunk file index "
"out of predefined range: %s",
@@ -96,9 +103,11 @@ static void extract_all(const char *storage_dir) {
closedir(dp);
- for (i = 0; i < max_index; ++i)
+ for (i = 0; i < max_index; ++i) {
if (trunk_files[i])
- extract_each(trunk_files[i]);
+ extract_each(storage_dir, trunk_files[i]);
+ free(trunk_files[i]);
+ }
}
int main(int argc, char *argv[]) {
diff --git a/include/common.h b/include/common.h
index bf40ad6..cfb454e 100644
--- a/include/common.h
+++ b/include/common.h
@@ -5,6 +5,7 @@ int nfl_check_file(FILE *f);
int nfl_check_dir(const char *storage_dir);
int nfl_storage_match_index(const char *fn);
const char *nfl_get_filename(const char *dir, int id);
+uint32_t nfl_get_filesize(FILE *f);
void nfl_cal_trunk(uint32_t total_size, uint32_t *trunk_cnt,
uint32_t *trunk_size);
void nfl_cal_entries(uint32_t trunk_size, uint32_t *entries_cnt);