Report open error for missing trace directory

This commit is contained in:
Rodrigo Arias 2023-07-26 13:51:35 +02:00
parent f8c6b7c7c0
commit f08595b3a7
2 changed files with 15 additions and 0 deletions

View File

@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Don't rely on /tmp or $TMPDIR in tests.
- Fix misleading message in version check.
- Fix error message when opening missing trace directories
## [1.2.1] - 2022-07-25

View File

@ -4,10 +4,12 @@
#define _XOPEN_SOURCE 500
#include "trace.h"
#include <dirent.h>
#include <ftw.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "ovni.h"
#include "path.h"
#include "stream.h"
@ -125,6 +127,18 @@ trace_load(struct trace *trace, const char *tracedir)
return -1;
}
/* Try to open the directory to catch permission errors */
DIR *dir = opendir(tracedir);
if (dir == NULL) {
err("cannot open \"%s\":", tracedir);
return -1;
}
if (closedir(dir) != 0) {
err("closedir failed:");
return -1;
}
/* Search recursively all streams in the trace directory */
if (nftw(tracedir, cb_nftw, 50, 0) != 0) {
err("nftw failed");