tdb2: Hand error code to logging function.
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 31 Aug 2011 04:25:15 +0000 (13:55 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 31 Aug 2011 04:25:15 +0000 (13:55 +0930)
Since we've deprecated tdb_error() function (and it didn't work right
from inside the logging function anyway, since we didn't set
tdb->ecode yet) we need to hand it to the log function.

ccan/tdb2/private.h
ccan/tdb2/tdb.c
ccan/tdb2/tdb2.h
ccan/tdb2/test/logging.c
ccan/tdb2/test/logging.h
ccan/tdb2/test/run-seed.c
ccan/tdb2/tools/growtdb-bench.c
ccan/tdb2/tools/speed.c
ccan/tdb2/tools/tdb2tool.c
ccan/tdb2/tools/tdb2torture.c

index b84c2f980db36252d6df496fcb00e12dc87619fa..4da73723e3fe77e9e3fbf611dd9b36ef70dedfd5 100644 (file)
@@ -343,6 +343,7 @@ struct tdb_context {
        /* Logging function */
        void (*log_fn)(struct tdb_context *tdb,
                       enum tdb_log_level level,
+                      enum TDB_ERROR ecode,
                       const char *message,
                       void *data);
        void *log_data;
index a2d36b373c4b7d875aeb45e477366a2ae3371972..7484695d7ab9a8724eb178e82bf3e1a9e52a58e2 100644 (file)
@@ -431,11 +431,11 @@ enum TDB_ERROR COLD tdb_logerr(struct tdb_context *tdb,
        va_end(ap);
 
        if (len < 0) {
-               tdb->log_fn(tdb, TDB_LOG_ERROR,
+               tdb->log_fn(tdb, TDB_LOG_ERROR, TDB_ERR_OOM,
                            "out of memory formatting message:", tdb->log_data);
-               tdb->log_fn(tdb, level, fmt, tdb->log_data);
+               tdb->log_fn(tdb, level, ecode, fmt, tdb->log_data);
        } else {
-               tdb->log_fn(tdb, level, message, tdb->log_data);
+               tdb->log_fn(tdb, level, ecode, message, tdb->log_data);
                free(message);
        }
        errno = saved_errno;
index 01413f206c8b99aa85cd2cc611d21f72982e2d32..5643ef4f8a1e2aeae9736dc8a18fbe29380b7ca8 100644 (file)
@@ -704,6 +704,7 @@ struct tdb_attribute_log {
        struct tdb_attribute_base base; /* .attr = TDB_ATTRIBUTE_LOG */
        void (*fn)(struct tdb_context *tdb,
                   enum tdb_log_level level,
+                  enum TDB_ERROR ecode,
                   const char *message,
                   void *data);
        void *data;
index 4857a4bfad7896e50272e52ab3ff0ab84e0d12a7..0712cc00a621db816c5e4377958bf10db841486b 100644 (file)
@@ -15,12 +15,14 @@ union tdb_attribute tap_log_attr = {
 
 void tap_log_fn(struct tdb_context *tdb,
                enum tdb_log_level level,
+               enum TDB_ERROR ecode,
                const char *message, void *priv)
 {
        if (suppress_logging)
                return;
 
-       diag("tdb log level %u: %s%s", level, log_prefix, message);
+       diag("tdb log level %u: %s: %s%s",
+            level, tdb_errorstr(ecode), log_prefix, message);
        if (log_last)
                free(log_last);
        log_last = strdup(message);
index 0fd59ba6bb921ed0a4e70fddda2c00aa69d24de3..2dfea145c3370a8dc046448a65ee46774b150a70 100644 (file)
@@ -12,5 +12,6 @@ extern char *log_last;
 
 void tap_log_fn(struct tdb_context *tdb,
                enum tdb_log_level level,
+               enum TDB_ERROR ecode,
                const char *message, void *priv);
 #endif /* TDB2_TEST_LOGGING_H */
index c07ec9a82c81d4ef3ce5014b25007c3b7cd5afb2..94a139414c7f9d86e4b7483b54fd9493b97be4ce 100644 (file)
@@ -14,6 +14,7 @@ static int log_count = 0;
 /* Normally we get a log when setting random seed. */
 static void my_log_fn(struct tdb_context *tdb,
                      enum tdb_log_level level,
+                     enum TDB_ERROR ecode,
                      const char *message, void *priv)
 {
        log_count++;
index ee36a7c5374d807444b2ca0b929842146bed4c65..205ff86e42e48ad459907724f1544d7bed15a461 100644 (file)
 
 static void logfn(struct tdb_context *tdb,
                  enum tdb_log_level level,
+                 enum TDB_ERROR ecode,
                  const char *message,
                  void *data)
 {
-       fprintf(stderr, "tdb:%s:%s\n", tdb_name(tdb), message);
+       fprintf(stderr, "tdb:%s:%s:%s\n",
+               tdb_name(tdb), tdb_errorstr(ecode), message);
 }
 
 int main(int argc, char *argv[])
index 3222465a71265d42f7ea9d51e5a6830af765e54d..ccb5ae349d894f43d57ce0349b280d6539713e7d 100644 (file)
@@ -126,11 +126,14 @@ static void dump_and_clear_stats(struct tdb_context **tdb,
        *tdb = tdb_open("/tmp/speed.tdb", flags, O_RDWR, 0, attr);
 }
 
-static void tdb_log(struct tdb_context *tdb, enum tdb_log_level level,
-                   const char *message, void *data)
+static void tdb_log(struct tdb_context *tdb,
+                   enum tdb_log_level level,
+                   enum TDB_ERROR ecode,
+                   const char *message,
+                   void *data)
 {
-       fputs(message, stderr);
-       putc('\n', stderr);
+       fprintf(stderr, "tdb:%s:%s:%s\n",
+               tdb_name(tdb), tdb_errorstr(ecode), message);
 }
 
 int main(int argc, char *argv[])
index e7a064aa2488142b914991e3d8945ee0a36c4cdd..8073561baeba05d7535e64a78681a9f5194af5ab 100644 (file)
@@ -126,10 +126,14 @@ static double _end_timer(void)
               (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
 }
 
-static void tdb_log(struct tdb_context *tdb, enum tdb_log_level level,
-                   const char *message, void *priv)
+static void tdb_log(struct tdb_context *tdb,
+                   enum tdb_log_level level,
+                   enum TDB_ERROR ecode,
+                   const char *message,
+                   void *data)
 {
-       fputs(message, stderr);
+       fprintf(stderr, "tdb:%s:%s:%s\n",
+               tdb_name(tdb), tdb_errorstr(ecode), message);
 }
 
 /* a tdb tool for manipulating a tdb database */
index 4b8002cccace6a1f5f6c17a004b498c84129424c..29ecb6afd9dc4013967982ac8b9a8c5699d4d855 100644 (file)
@@ -42,10 +42,14 @@ static int count_pipe;
 static union tdb_attribute log_attr;
 static union tdb_attribute seed_attr;
 
-static void tdb_log(struct tdb_context *tdb, enum tdb_log_level level,
-                   const char *message, void *data)
+static void tdb_log(struct tdb_context *tdb,
+                   enum tdb_log_level level,
+                   enum TDB_ERROR ecode,
+                   const char *message,
+                   void *data)
 {
-       fputs(message, stdout);
+       printf("tdb:%s:%s:%s\n",
+              tdb_name(tdb), tdb_errorstr(ecode), message);
        fflush(stdout);
 #if 0
        {