RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  [email protected]
  Module: rpm                              Date:   17-Oct-2009 18:29:03
  Branch: HEAD                             Handle: 2009101716290200

  Modified files:
    rpm/rpmdb               logio.c logio.src logio_rec.c

  Log:
    - dbi: test cases for content ctor/dtor.

  Summary:
    Revision    Changes     Path
    1.4         +318 -80    rpm/rpmdb/logio.c
    1.8         +1  -0      rpm/rpmdb/logio.src
    1.8         +43 -0      rpm/rpmdb/logio_rec.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/rpmdb/logio.c
  ============================================================================
  $ cvs diff -u -r1.3 -r1.4 logio.c
  --- rpm/rpmdb/logio.c 12 Oct 2009 17:07:26 -0000      1.3
  +++ rpm/rpmdb/logio.c 17 Oct 2009 16:29:02 -0000      1.4
  @@ -12,6 +12,39 @@
   
   #include "debug.h"
   
  +static int _debug = 0;
  +
  +static const char *home = "HOME";
  +static const char * dir = "DIR";
  +static const char * file = "FILE";
  +static mode_t _mode = 0755;
  +
  +static int
  +verify(const char * fn, mode_t mode)
  +{
  +    struct stat sb;
  +    int rc;
  +    sb.st_mode = 0;
  +    rc = Lstat(fn, &sb)
  +     ? errno
  +     : (sb.st_mode == mode ? 0 : -1);
  +if (_debug)
  +fprintf(stderr, "<-- %s(%s,0%o) st_mode 0%o rc %d\n", __FUNCTION__, fn, 
mode, sb.st_mode, rc);
  +    return rc;
  +}
  +
  +static int
  +Creat(const char * fn, mode_t mode, const char * s)
  +{
  +    size_t ns = strlen(s) + 1;
  +    FD_t fd = Fopen(fn, "w");
  +    int rc = 0;
  +    (void) Fwrite(s, 1, ns, fd);
  +    (void) Fclose(fd);
  +    (void) Chmod(fn, mode & 0777);
  +    return rc;
  +}
  +
   /*
    * Sample application dispatch function to handle user-specified log record
    * types.
  @@ -25,10 +58,16 @@
       LOGCOPY_32(dbenv->env, &rectype, dbt->data);
   
       switch (rectype) {
  +    case DB_logio_Creat:
  +     return logio_Creat_recover(dbenv, dbt, lsn, op);
       case DB_logio_Mkdir:
        return logio_Mkdir_recover(dbenv, dbt, lsn, op);
  +    case DB_logio_Rename:
  +     return logio_Rename_recover(dbenv, dbt, lsn, op);
       case DB_logio_Rmdir:
        return logio_Rmdir_recover(dbenv, dbt, lsn, op);
  +    case DB_logio_Unlink:
  +     return logio_Unlink_recover(dbenv, dbt, lsn, op);
       default:
        /* We've hit an unexpected, allegedly user-defined record type.  */
        dbenv->errx(dbenv, "Unexpected log record type encountered");
  @@ -73,68 +112,22 @@
   }
   
   static int
  -verify(const char * DN, mode_t mode)
  +testMkdir(DB_ENV * dbenv, const char * DN, mode_t mode)
   {
  -    struct stat sb;
  -    if (Lstat(DN, &sb))
  -     return errno;
  -    return (sb.st_mode == mode ? 0 : -1);
  -}
  -
  -static const char *home = "HOME";
  -static const char * dir = "DIR";
  -static mode_t mode = 0755;
  -
  -static struct poptOption _optionsTable[] = {
  -
  -  { "home", 'h', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT,  &home, 0,
  -     N_("Specify DIR for database environment"), N_("DIR") },
  -
  - { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmioAllPoptTable, 0,
  -     N_("Common options for all rpmio executables:"), NULL },
  -
  -  POPT_AUTOALIAS
  -  POPT_AUTOHELP
  -  POPT_TABLEEND
  -};
  -
  -static struct poptOption *optionsTable = &_optionsTable[0];
  -
  -int
  -main(int argc, char *argv[])
  -{
  -    poptContext optCon = rpmioInit(argc, argv, optionsTable);
  -    const char * DN = rpmGetPath(home, "/", dir, NULL);
  -    DB_ENV *dbenv;
  +    const char * msg;
       DB_TXN *txn;
       DB_LSN lsn;
       DBT DNdbt = {0};
       int ret;
  -    int ec = EXIT_FAILURE;   /* assume failure */
  -
  -    if (verify(home, S_IFDIR|mode) == ENOENT)
  -     (void) Mkdir(home, mode);
  -
  -    if ((ret = open_env(home, NULL, &dbenv)) != 0)
  -     goto exit;
   
  -   /*
  -    * Remember, always log actions before you execute them!
  -    * Since this log record is describing a file system operation and
  -    * we have no control over when file system operations go to disk,
  -    * we need to flush the log record immediately to ensure that the
  -    * log record is on disk before the operation it describes.  The
  -    * flush would not be necessary were we doing an operation into the
  -    * BDB mpool and using LSNs that mpool knew about.
  -    */
  -    printf("INIT: Mkdir transaction logged and directory created: ");
  +    msg = "INIT: Mkdir transaction logged and directory created";
       if ((ret = dbenv->txn_begin(dbenv, NULL, &txn, 0)) != 0) {
        dbenv->err(dbenv, ret, "txn_begin");
        goto exit;
       }
  +    memset(&lsn, 0, sizeof(lsn));
       DNdbt.data = (void *)DN;
       DNdbt.size = strlen(DN) + 1;     /* trailing NUL too */
  -    memset(&lsn, 0, sizeof(lsn));
       if ((ret = logio_Mkdir_log(dbenv, txn, &lsn, DB_FLUSH, &DNdbt, mode)) != 
0) {
        dbenv->err(dbenv, ret, "Mkdir_log");
        goto exit;
  @@ -143,24 +136,23 @@
        dbenv->err(dbenv, errno, "Mkdir");
        goto exit;
       }
  -    printf("%s\n", (verify(DN, S_IFDIR|mode) == 0 ? "ok" : "FAIL"));
  +    fprintf(stderr, "%s: %s\n", msg, (verify(DN, mode) == 0 ? "ok" : 
"FAIL"));
   
  -    printf("TEST: directory is removed by transaction abort: ");
  +    msg = "TEST: directory is removed by transaction abort";
       if ((ret = txn->abort(txn)) != 0) {
        dbenv->err(dbenv, ret, "TXN->abort");
        goto exit;
       }
  -    printf("%s\n", (verify(DN, S_IFDIR|mode) == ENOENT ? "ok" : "FAIL"));
  +    fprintf(stderr, "%s: %s\n", msg, (verify(DN, mode) == ENOENT ? "ok" : 
"FAIL"));
   
  -    /* Repeat, with a commit this time. */
  -    printf("INIT: Mkdir transaction logged and directory created: ");
  -    DNdbt.data = (void *)DN;
  -    DNdbt.size = strlen(DN) + 1;
  +    msg = "INIT: Mkdir transaction logged and directory created";
       if ((ret = dbenv->txn_begin(dbenv, NULL, &txn, 0)) != 0) {
        dbenv->err(dbenv, ret, "DB_ENV->txn_begin");
        goto exit;
       }
       memset(&lsn, 0, sizeof(lsn));
  +    DNdbt.data = (void *)DN;
  +    DNdbt.size = strlen(DN) + 1;
       if ((ret = logio_Mkdir_log(dbenv, txn, &lsn, 0, &DNdbt, mode)) != 0) {
        dbenv->err(dbenv, ret, "Mkdir_log");
        goto exit;
  @@ -169,17 +161,17 @@
        dbenv->err(dbenv, errno, "Mkdir");
        goto exit;
       }
  -    printf("%s\n", (verify(DN, S_IFDIR|mode) == 0 ? "ok" : "FAIL"));
  +    fprintf(stderr, "%s: %s\n", msg, (verify(DN, mode) == 0 ? "ok" : 
"FAIL"));
   
       /* Commit the transaction and verify that the creation persists. */
  -    printf("TEST: creation persists after transaction commit: ");
  +    msg = "TEST: creation persists after transaction commit";
       if ((ret = txn->commit(txn, 0)) != 0) {
        dbenv->err(dbenv, ret, "TXN->commit");
        goto exit;
       }
  -    printf("%s\n", (verify(DN, S_IFDIR|mode) == 0 ? "ok" : "FAIL"));
  +    fprintf(stderr, "%s: %s\n", msg, (verify(DN, mode) == 0 ? "ok" : 
"FAIL"));
   
  -    printf("INIT: Close dbenv and remove directory: ");
  +    msg = "INIT: Close dbenv and remove directory";
       if ((ret = dbenv->close(dbenv, 0)) != 0) {
        fprintf(stderr, "DB_ENV->close: %s\n", db_strerror(ret));
        goto exit;
  @@ -188,21 +180,34 @@
        fprintf(stderr, "%s: Rmdir failed with error %s", __progname,
            strerror(errno));
       }
  -    printf("%s\n", (verify(DN, S_IFDIR|mode) == ENOENT ? "ok" : "FAIL"));
  +    fprintf(stderr, "%s: %s\n", msg, (verify(DN, mode) == ENOENT ? "ok" : 
"FAIL"));
   
  -    printf("TEST: directory is re-created opening dbenv with DB_RECOVER: ");
  +    msg = "TEST: directory is re-created opening dbenv with DB_RECOVER";
       if ((ret = open_env(home, stderr, &dbenv)) != 0)
        goto exit;
  -    printf("%s\n", (verify(DN, S_IFDIR|mode) == 0 ? "ok" : "FAIL"));
  +    fprintf(stderr, "%s: %s\n", msg, (verify(DN, mode) == 0 ? "ok" : 
"FAIL"));
   
  -    printf("INIT: Rmdir transaction logged and directory removed: ");
  +exit:
  +    return ret;
  +}
  +
  +static int
  +testRmdir(DB_ENV * dbenv, const char * DN, mode_t mode)
  +{
  +    const char * msg;
  +    DB_TXN *txn;
  +    DB_LSN lsn;
  +    DBT DNdbt = {0};
  +    int ret;
  +
  +    msg = "INIT: Rmdir transaction logged and directory removed";
       if ((ret = dbenv->txn_begin(dbenv, NULL, &txn, 0)) != 0) {
        dbenv->err(dbenv, ret, "txn_begin");
        goto exit;
       }
  +    memset(&lsn, 0, sizeof(lsn));
       DNdbt.data = (void *)DN;
       DNdbt.size = strlen(DN) + 1;     /* trailing NUL too */
  -    memset(&lsn, 0, sizeof(lsn));
       if ((ret = logio_Rmdir_log(dbenv, txn, &lsn, DB_FLUSH, &DNdbt, mode)) != 
0) {
        dbenv->err(dbenv, ret, "Rmdir_log");
        goto exit;
  @@ -211,24 +216,24 @@
        dbenv->err(dbenv, errno, "Rmdir");
        goto exit;
       }
  -    printf("%s\n", (verify(DN, S_IFDIR|mode) == ENOENT ? "ok" : "FAIL"));
  +    fprintf(stderr, "%s: %s\n", msg, (verify(DN, mode) == ENOENT ? "ok" : 
"FAIL"));
   
  -    printf("TEST: directory is re-created by transaction abort: ");
  +    msg = "TEST: directory is re-created by transaction abort";
       if ((ret = txn->abort(txn)) != 0) {
        dbenv->err(dbenv, ret, "TXN->abort");
        goto exit;
       }
  -    printf("%s\n", (verify(DN, S_IFDIR|mode) == 0 ? "ok" : "FAIL"));
  +    fprintf(stderr, "%s: %s\n", msg, (verify(DN, mode) == 0 ? "ok" : 
"FAIL"));
   
       /* Repeat, with a commit this time. */
  -    printf("INIT: Rmdir transaction logged and directory removed: ");
  -    DNdbt.data = (void *)DN;
  -    DNdbt.size = strlen(DN) + 1;
  +    msg = "INIT: Rmdir transaction logged and directory removed";
       if ((ret = dbenv->txn_begin(dbenv, NULL, &txn, 0)) != 0) {
        dbenv->err(dbenv, ret, "DB_ENV->txn_begin");
        goto exit;
       }
       memset(&lsn, 0, sizeof(lsn));
  +    DNdbt.data = (void *)DN;
  +    DNdbt.size = strlen(DN) + 1;
       if ((ret = logio_Rmdir_log(dbenv, txn, &lsn, 0, &DNdbt, mode)) != 0) {
        dbenv->err(dbenv, ret, "Rmdir_log");
        goto exit;
  @@ -237,17 +242,16 @@
        dbenv->err(dbenv, errno, "Rmdir");
        goto exit;
       }
  -    printf("%s\n", (verify(DN, S_IFDIR|mode) == ENOENT ? "ok" : "FAIL"));
  +    fprintf(stderr, "%s: %s\n", msg, (verify(DN, mode) == ENOENT ? "ok" : 
"FAIL"));
   
  -    /* Commit the transaction and verify that the removal persists. */
  -    printf("TEST: removal persists after transaction commit: ");
  +    msg = "TEST: removal persists after transaction commit";
       if ((ret = txn->commit(txn, 0)) != 0) {
        dbenv->err(dbenv, ret, "TXN->commit");
        goto exit;
       }
  -    printf("%s\n", (verify(DN, S_IFDIR|mode) == ENOENT ? "ok" : "FAIL"));
  +    fprintf(stderr, "%s: %s\n", msg, (verify(DN, mode) == ENOENT ? "ok" : 
"FAIL"));
   
  -    printf("INIT: Close dbenv and create directory: ");
  +    msg = "INIT: Close dbenv and create directory";
       if ((ret = dbenv->close(dbenv, 0)) != 0) {
        fprintf(stderr, "DB_ENV->close: %s\n", db_strerror(ret));
        goto exit;
  @@ -256,20 +260,254 @@
        fprintf(stderr, "%s: Mkdir failed with error %s", __progname,
            strerror(errno));
       }
  -    printf("%s\n", (verify(DN, S_IFDIR|mode) == 0 ? "ok" : "FAIL"));
  +    fprintf(stderr, "%s: %s\n", msg, (verify(DN, mode) == 0 ? "ok" : 
"FAIL"));
   
  -    printf("TEST: directory is removed opening dbenv with DB_RECOVER: ");
  +    msg = "TEST: directory is removed opening dbenv with DB_RECOVER";
       if ((ret = open_env(home, stderr, &dbenv)) != 0)
        goto exit;
  -    printf("%s\n", (verify(DN, S_IFDIR|mode) == ENOENT ? "ok" : "FAIL"));
  +    fprintf(stderr, "%s: %s\n", msg, (verify(DN, mode) == ENOENT ? "ok" : 
"FAIL"));
  +
  +exit:
  +    return ret;
  +}
  +
  +static int
  +testCreat(DB_ENV * dbenv, const char * FN, mode_t mode)
  +{
  +    const char * msg;
  +    DB_TXN *txn;
  +    DB_LSN lsn;
  +    DBT FNdbt = {0};
  +    DBT Bdbt = {0};
  +    DBT Ddbt = {0};
  +    uint32_t dalgo = 0;
  +    int ret;
   
  +    msg = "INIT: Creat transaction logged and file created";
  +    if ((ret = dbenv->txn_begin(dbenv, NULL, &txn, 0)) != 0) {
  +     dbenv->err(dbenv, ret, "txn_begin");
  +     goto exit;
  +    }
  +    FNdbt.data = (void *)FN;
  +    FNdbt.size = strlen(FN) + 1;     /* trailing NUL too */
  +    Bdbt.data = (void *)FN;
  +    Bdbt.size = strlen(FN) + 1;
  +    memset(&lsn, 0, sizeof(lsn));
  +    if ((ret = logio_Creat_log(dbenv, txn, &lsn, DB_FLUSH, &FNdbt, mode, 
&Bdbt, &Ddbt, dalgo)) != 0) {
  +     dbenv->err(dbenv, ret, "Creat_log");
  +     goto exit;
  +    }
  +    if (Creat(FN, mode, FN) != 0) {
  +     dbenv->err(dbenv, errno, "Creat");
  +     goto exit;
  +    }
  +    fprintf(stderr, "%s: %s\n", msg, (verify(FN, mode) == 0 ? "ok" : 
"FAIL"));
  +
  +    msg = "TEST: file is removed by transaction abort";
  +    if ((ret = txn->abort(txn)) != 0) {
  +     dbenv->err(dbenv, ret, "TXN->abort");
  +     goto exit;
  +    }
  +    fprintf(stderr, "%s: %s\n", msg, (verify(FN, mode) == ENOENT ? "ok" : 
"FAIL"));
  +
  +    /* Repeat, with a commit this time. */
  +    msg = "INIT: Creat transaction logged and file created";
  +    if ((ret = dbenv->txn_begin(dbenv, NULL, &txn, 0)) != 0) {
  +     dbenv->err(dbenv, ret, "DB_ENV->txn_begin");
  +     goto exit;
  +    }
  +    memset(&lsn, 0, sizeof(lsn));
  +    FNdbt.data = (void *)FN;
  +    FNdbt.size = strlen(FN) + 1;
  +    Bdbt.data = (void *)FN;
  +    Bdbt.size = strlen(FN) + 1;
  +    if ((ret = logio_Creat_log(dbenv, txn, &lsn, 0, &FNdbt, mode, &Bdbt, 
&Ddbt, dalgo)) != 0) {
  +     dbenv->err(dbenv, ret, "Creat_log");
  +     goto exit;
  +    }
  +    if (Creat(FN, mode, FN) != 0) {
  +     dbenv->err(dbenv, errno, "Creat");
  +     goto exit;
  +    }
  +    fprintf(stderr, "%s: %s\n", msg, (verify(FN, mode) == 0 ? "ok" : 
"FAIL"));
  +
  +    /* Commit the transaction and verify that the creation persists. */
  +    msg = "TEST: creation persists after transaction commit";
  +    if ((ret = txn->commit(txn, 0)) != 0) {
  +     dbenv->err(dbenv, ret, "TXN->commit");
  +     goto exit;
  +    }
  +    fprintf(stderr, "%s: %s\n", msg, (verify(FN, mode) == 0 ? "ok" : 
"FAIL"));
  +
  +    msg = "INIT: Close dbenv and remove file";
       if ((ret = dbenv->close(dbenv, 0)) != 0) {
        fprintf(stderr, "DB_ENV->close: %s\n", db_strerror(ret));
        goto exit;
       }
  +    if (Unlink(FN) != 0) {
  +     fprintf(stderr, "%s: Unlink failed with error %s", __progname,
  +         strerror(errno));
  +    }
  +    fprintf(stderr, "%s: %s\n", msg, (verify(FN, mode) == ENOENT ? "ok" : 
"FAIL"));
  +
  +    msg = "TEST: file is re-created opening dbenv with DB_RECOVER";
  +    if ((ret = open_env(home, stderr, &dbenv)) != 0)
  +     goto exit;
  +    fprintf(stderr, "%s: %s\n", msg, (verify(FN, mode) == 0 ? "ok" : 
"FAIL"));
  +
  +exit:
  +    return ret;
  +}
  +
  +static int
  +testUnlink(DB_ENV * dbenv, const char * FN, mode_t mode)
  +{
  +    const char * msg;
  +    DB_TXN *txn;
  +    DB_LSN lsn;
  +    DBT FNdbt = {0};
  +    DBT Bdbt = {0};
  +    DBT Ddbt = {0};
  +    uint32_t dalgo = 0;
  +    int ret;
  +
  +    msg = "INIT: Unlink transaction logged and file removed";
  +    if ((ret = dbenv->txn_begin(dbenv, NULL, &txn, 0)) != 0) {
  +     dbenv->err(dbenv, ret, "txn_begin");
  +     goto exit;
  +    }
  +    FNdbt.data = (void *)FN;
  +    FNdbt.size = strlen(FN) + 1;     /* trailing NUL too */
  +    Bdbt.data = (void *)FN;
  +    Bdbt.size = strlen(FN) + 1;
  +    memset(&lsn, 0, sizeof(lsn));
  +    if ((ret = logio_Unlink_log(dbenv, txn, &lsn, DB_FLUSH, &FNdbt, mode, 
&Bdbt, &Ddbt, dalgo)) != 0) {
  +     dbenv->err(dbenv, ret, "Unlink_log");
  +     goto exit;
  +    }
  +    if (Unlink(FN) != 0) {
  +     dbenv->err(dbenv, errno, "Unlink");
  +     goto exit;
  +    }
  +    fprintf(stderr, "%s: %s\n", msg, (verify(FN, mode) == ENOENT ? "ok" : 
"FAIL"));
  +
  +    msg = "TEST: file is re-created by transaction abort";
  +    if ((ret = txn->abort(txn)) != 0) {
  +     dbenv->err(dbenv, ret, "TXN->abort");
  +     goto exit;
  +    }
  +    fprintf(stderr, "%s: %s\n", msg, (verify(FN, mode) == 0 ? "ok" : 
"FAIL"));
  +
  +    /* Repeat, with a commit this time. */
  +    msg = "INIT: Unlink transaction logged and file removed";
  +    if ((ret = dbenv->txn_begin(dbenv, NULL, &txn, 0)) != 0) {
  +     dbenv->err(dbenv, ret, "DB_ENV->txn_begin");
  +     goto exit;
  +    }
  +    memset(&lsn, 0, sizeof(lsn));
  +    FNdbt.data = (void *)FN;
  +    FNdbt.size = strlen(FN) + 1;
  +    Bdbt.data = (void *)FN;
  +    Bdbt.size = strlen(FN) + 1;
  +    if ((ret = logio_Unlink_log(dbenv, txn, &lsn, 0, &FNdbt, mode, &Bdbt, 
&Ddbt, dalgo)) != 0) {
  +     dbenv->err(dbenv, ret, "Unlink_log");
  +     goto exit;
  +    }
  +    if (Unlink(FN) != 0) {
  +     dbenv->err(dbenv, errno, "Unlink");
  +     goto exit;
  +    }
  +    fprintf(stderr, "%s: %s\n", msg, (verify(FN, mode) == ENOENT ? "ok" : 
"FAIL"));
  +
  +    msg = "TEST: removal persists after transaction commit";
  +    if ((ret = txn->commit(txn, 0)) != 0) {
  +     dbenv->err(dbenv, ret, "TXN->commit");
  +     goto exit;
  +    }
  +    fprintf(stderr, "%s: %s\n", msg, (verify(FN, mode) == ENOENT ? "ok" : 
"FAIL"));
  +
  +    msg = "INIT: Close dbenv and create file";
  +    if ((ret = dbenv->close(dbenv, 0)) != 0) {
  +     fprintf(stderr, "DB_ENV->close: %s\n", db_strerror(ret));
  +     goto exit;
  +    }
  +    if (Creat(FN, mode, FN) != 0) {
  +     fprintf(stderr, "%s: Creat failed with error %s", __progname,
  +         strerror(errno));
  +    }
  +    fprintf(stderr, "%s: %s\n", msg, (verify(FN, mode) == 0 ? "ok" : 
"FAIL"));
  +
  +    msg = "TEST: file is removed opening dbenv with DB_RECOVER";
  +    if ((ret = open_env(home, stderr, &dbenv)) != 0)
  +     goto exit;
  +    fprintf(stderr, "%s: %s\n", msg, (verify(FN, mode) == ENOENT ? "ok" : 
"FAIL"));
  +
  +exit:
  +    return ret;
  +}
  +
  +static struct poptOption _optionsTable[] = {
  +
  +  { "home", 'h', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT,  &home, 0,
  +     N_("Specify DIR for database environment"), N_("DIR") },
  +
  + { "debug", 'd', POPT_ARG_VAL,       &_debug, -1,            NULL, NULL },
  +
  + { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmioAllPoptTable, 0,
  +     N_("Common options for all rpmio executables:"), NULL },
  +
  +  POPT_AUTOALIAS
  +  POPT_AUTOHELP
  +  POPT_TABLEEND
  +};
  +
  +static struct poptOption *optionsTable = &_optionsTable[0];
  +
  +int
  +main(int argc, char *argv[])
  +{
  +    poptContext optCon = rpmioInit(argc, argv, optionsTable);
  +    const char * DN = rpmGetPath(home, "/", dir, NULL);
  +    const char * FN = rpmGetPath(home, "/", file, NULL);
  +    DB_ENV *dbenv;
  +    int ret;
  +    int ec = EXIT_FAILURE;   /* assume failure */
  +
  +    if (verify(home, S_IFDIR|_mode) == ENOENT)
  +     (void) Mkdir(home, _mode);
  +
  +    if ((ret = open_env(home, NULL, &dbenv)) != 0)
  +     goto exit;
  +
  +   /*
  +    * Remember, always log actions before you execute them!
  +    * Since this log record is describing a file system operation and
  +    * we have no control over when file system operations go to disk,
  +    * we need to flush the log record immediately to ensure that the
  +    * log record is on disk before the operation it describes.  The
  +    * flush would not be necessary were we doing an operation into the
  +    * BDB mpool and using LSNs that mpool knew about.
  +    */
  +
  +    if ((ret = testMkdir(dbenv, DN, (S_IFDIR|_mode))) != 0)
  +     goto exit;
  +    if ((ret = testRmdir(dbenv, DN, (S_IFDIR|_mode))) != 0)
  +     goto exit;
  +
  +    if ((ret = testCreat(dbenv, FN, (S_IFREG|_mode))) != 0)
  +     goto exit;
  +    if ((ret = testUnlink(dbenv, FN, (S_IFREG|_mode))) != 0)
  +     goto exit;
  +
  +    if ((ret = dbenv->close(dbenv, 0)) != 0) {
  +     fprintf(stderr, "DB_ENV->close: %s\n", db_strerror(ret));
  +     goto exit;
  +    }
  +
       ec = EXIT_SUCCESS;
   
   exit:
  +    FN = _free(FN);
       DN = _free(DN);
       optCon = rpmioFini(optCon);
       return ec;
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmdb/logio.src
  ============================================================================
  $ cvs diff -u -r1.7 -r1.8 logio.src
  --- rpm/rpmdb/logio.src       12 Oct 2009 23:05:39 -0000      1.7
  +++ rpm/rpmdb/logio.src       17 Oct 2009 16:29:02 -0000      1.8
  @@ -3,6 +3,7 @@
   INCLUDE #include <rpmio.h>
   INCLUDE #include "logio.h"
   INCLUDE #include "debug.h"
  +INCLUDE
   
   /*
    *     awk -f ./logio.awk \
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmdb/logio_rec.c
  ============================================================================
  $ cvs diff -u -r1.7 -r1.8 logio_rec.c
  --- rpm/rpmdb/logio_rec.c     17 Oct 2009 05:46:42 -0000      1.7
  +++ rpm/rpmdb/logio_rec.c     17 Oct 2009 16:29:02 -0000      1.8
  @@ -15,6 +15,18 @@
   #include "debug.h"
   
   #undef       DEBUG_RECOVER
  +static int _debug = 0;
  +
  +static const char * opnames[] = {
  +    "ABORT",
  +    "APPLY",
  +    "FIXME",
  +    "BACKWARD",
  +    "FORWARD",
  +    "OPENFILES",
  +    "POPENFILES",
  +    "PRINT"
  +};
   
   static int writeFile(const char * fn, mode_t mode,
                const DBT * content, const DBT * digest, uint32_t dalgo)
  @@ -26,6 +38,8 @@
       int ret = 0;
       int xx;
   
  +if (_debug)
  +fprintf(stderr, "--> %s(%s,0%o,%p,%p,%u)\n", __FUNCTION__, fn, mode, 
content, digest, dalgo);
       if (S_ISREG(mode)) {
        FD_t fd = Fopen(fn, "w.fdio");
        size_t nw;
  @@ -48,6 +62,7 @@
            digest = _free(digest);
        }
        (void) Fclose(fd);
  +     (void) Chmod(fn, mode);
        fd = NULL;
        if (nw != blen)
            ret = -1;
  @@ -68,6 +83,8 @@
       logio_Creat_args *argp = NULL;
       int ret = EINVAL;
   
  +if (_debug)
  +fprintf(stderr, "--> %s(%p,%p,%p,%s)\n", __FUNCTION__, dbenv, dbtp, lsnp, 
opnames[op&7]);
   #ifdef DEBUG_RECOVER
       (void)logio_Creat_print(dbenv, dbtp, lsnp, op);
   #endif
  @@ -127,6 +144,8 @@
       logio_Unlink_args *argp = NULL;
       int ret = EINVAL;
   
  +if (_debug)
  +fprintf(stderr, "--> %s(%p,%p,%p,%s)\n", __FUNCTION__, dbenv, dbtp, lsnp, 
opnames[op&7]);
   #ifdef DEBUG_RECOVER
       (void)logio_Unlink_print(dbenv, dbtp, lsnp, op);
   #endif
  @@ -186,6 +205,8 @@
       logio_Rename_args *argp = NULL;
       int ret = EINVAL;
   
  +if (_debug)
  +fprintf(stderr, "--> %s(%p,%p,%p,%s)\n", __FUNCTION__, dbenv, dbtp, lsnp, 
opnames[op&7]);
   #ifdef DEBUG_RECOVER
       (void)logio_Rename_print(dbenv, dbtp, lsnp, op);
   #endif
  @@ -239,6 +260,8 @@
       logio_Mkdir_args * argp = NULL;
       int ret = EINVAL;
   
  +if (_debug)
  +fprintf(stderr, "--> %s(%p,%p,%p,%s)\n", __FUNCTION__, dbenv, dbtp, lsnp, 
opnames[op&7]);
   #ifdef DEBUG_RECOVER
       logio_Mkdir_print(dbenv, dbtp, lsnp, op);
   #endif
  @@ -323,6 +346,8 @@
       logio_Rmdir_args *argp = NULL;
       int ret = EINVAL;
   
  +if (_debug)
  +fprintf(stderr, "--> %s(%p,%p,%p,%s)\n", __FUNCTION__, dbenv, dbtp, lsnp, 
opnames[op&7]);
   #ifdef DEBUG_RECOVER
       (void)logio_Rmdir_print(dbenv, dbtp, lsnp, op);
   #endif
  @@ -383,6 +408,8 @@
       logio_Lsetfilecon_args *argp = NULL;
       int ret = EINVAL;
   
  +if (_debug)
  +fprintf(stderr, "--> %s(%p,%p,%p,%s)\n", __FUNCTION__, dbenv, dbtp, lsnp, 
opnames[op&7]);
   #ifdef DEBUG_RECOVER
       (void)logio_Lsetfilecon_print(dbenv, dbtp, lsnp, op);
   #endif
  @@ -446,6 +473,8 @@
       logio_Chown_args *argp = NULL;
       int ret = EINVAL;
   
  +if (_debug)
  +fprintf(stderr, "--> %s(%p,%p,%p,%s)\n", __FUNCTION__, dbenv, dbtp, lsnp, 
opnames[op&7]);
   #ifdef DEBUG_RECOVER
       (void)logio_Chown_print(dbenv, dbtp, lsnp, op);
   #endif
  @@ -508,6 +537,8 @@
       logio_Lchown_args *argp = NULL;
       int ret = EINVAL;
   
  +if (_debug)
  +fprintf(stderr, "--> %s(%p,%p,%p,%s)\n", __FUNCTION__, dbenv, dbtp, lsnp, 
opnames[op&7]);
   #ifdef DEBUG_RECOVER
       (void)logio_Lchown_print(dbenv, dbtp, lsnp, op);
   #endif
  @@ -570,6 +601,8 @@
       logio_Chmod_args *argp = NULL;
       int ret = EINVAL;
   
  +if (_debug)
  +fprintf(stderr, "--> %s(%p,%p,%p,%s)\n", __FUNCTION__, dbenv, dbtp, lsnp, 
opnames[op&7]);
   #ifdef DEBUG_RECOVER
       (void)logio_Chmod_print(dbenv, dbtp, lsnp, op);
   #endif
  @@ -632,6 +665,8 @@
       logio_Utime_args *argp = NULL;
       int ret = EINVAL;
   
  +if (_debug)
  +fprintf(stderr, "--> %s(%p,%p,%p,%s)\n", __FUNCTION__, dbenv, dbtp, lsnp, 
opnames[op&7]);
   #ifdef DEBUG_RECOVER
       (void)logio_Utime_print(dbenv, dbtp, lsnp, op);
   #endif
  @@ -698,6 +733,8 @@
       logio_Symlink_args *argp = NULL;
       int ret = EINVAL;
   
  +if (_debug)
  +fprintf(stderr, "--> %s(%p,%p,%p,%s)\n", __FUNCTION__, dbenv, dbtp, lsnp, 
opnames[op&7]);
   #ifdef DEBUG_RECOVER
       (void)logio_Symlink_print(dbenv, dbtp, lsnp, op);
   #endif
  @@ -756,6 +793,8 @@
       logio_Link_args *argp = NULL;
       int ret = EINVAL;
   
  +if (_debug)
  +fprintf(stderr, "--> %s(%p,%p,%p,%s)\n", __FUNCTION__, dbenv, dbtp, lsnp, 
opnames[op&7]);
   #ifdef DEBUG_RECOVER
       (void)logio_Link_print(dbenv, dbtp, lsnp, op);
   #endif
  @@ -814,6 +853,8 @@
       logio_Mknod_args *argp = NULL;
       int ret = EINVAL;
   
  +if (_debug)
  +fprintf(stderr, "--> %s(%p,%p,%p,%s)\n", __FUNCTION__, dbenv, dbtp, lsnp, 
opnames[op&7]);
   #ifdef DEBUG_RECOVER
       (void)logio_Mknod_print(dbenv, dbtp, lsnp, op);
   #endif
  @@ -872,6 +913,8 @@
       logio_Mkfifo_args *argp = NULL;
       int ret = EINVAL;
   
  +if (_debug)
  +fprintf(stderr, "--> %s(%p,%p,%p,%s)\n", __FUNCTION__, dbenv, dbtp, lsnp, 
opnames[op&7]);
   #ifdef DEBUG_RECOVER
       (void)logio_Mkfifo_print(dbenv, dbtp, lsnp, op);
   #endif
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                [email protected]

Reply via email to