ntdb: use NTDB_LOG_WARNING level for failed open() without O_CREAT.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 18 Jun 2012 13:00:28 +0000 (22:30 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 19 Jun 2012 03:38:06 +0000 (05:38 +0200)
This is a fairly common pattern in Samba, and if we log an error on
every open it spams the logs.  On the other hand, other errors are
potentially more serious, so we still use NTDB_LOG_ERROR on them.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
lib/ntdb/ntdb.h
lib/ntdb/open.c

index f64b2f4a1b6e98a40e1dc84de1042912644c2c86..f2b80023cdeb6787b3613ebd0d698fa69ed160c8 100644 (file)
@@ -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,
index 8dce4ce6f2a0f336b6fec1f9b143badea929805f..56b504b5c0b38fc9bc52a1407aee74e35105aff0 100644 (file)
@@ -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));