summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/ntdb/ntdb.h2
-rw-r--r--lib/ntdb/open.c10
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/ntdb/ntdb.h b/lib/ntdb/ntdb.h
index f64b2f4a1b..f2b80023cd 100644
--- a/lib/ntdb/ntdb.h
+++ b/lib/ntdb/ntdb.h
@@ -727,6 +727,8 @@ struct ntdb_attribute_base {
* @NTDB_LOG_WARNING: used for informational messages on issues which
* are unusual but handled by NTDB internally, such
* as a failure to mmap or failure to open /dev/urandom.
+ * It's also used when ntdb_open() fails without O_CREAT
+ * because a file does not exist.
*/
enum ntdb_log_level {
NTDB_LOG_ERROR,
diff --git a/lib/ntdb/open.c b/lib/ntdb/open.c
index 8dce4ce6f2..56b504b5c0 100644
--- a/lib/ntdb/open.c
+++ b/lib/ntdb/open.c
@@ -517,9 +517,17 @@ _PUBLIC_ struct ntdb_context *ntdb_open(const char *name, int ntdb_flags,
ntdb->file->map_size = 0;
if ((ntdb->file->fd = open(name, open_flags, mode)) == -1) {
+ enum ntdb_log_level lvl;
/* errno set by open(2) */
saved_errno = errno;
- ntdb_logerr(ntdb, NTDB_ERR_IO, NTDB_LOG_ERROR,
+
+ /* Probing for files like this is a common pattern. */
+ if (!(open_flags & O_CREAT) && errno == ENOENT) {
+ lvl = NTDB_LOG_WARNING;
+ } else {
+ lvl = NTDB_LOG_ERROR;
+ }
+ ntdb_logerr(ntdb, NTDB_ERR_IO, lvl,
"ntdb_open: could not open file %s: %s",
name, strerror(errno));