control: tag -1 +unreproducible
control: close -1

> In some software I'm using libgdbm=1.8.3-3. Some routine wants to use
> a gdbm file as a kind of non-memory-limited hash, so it tries to open
> some filename with GDBM_NEWDB.
>
> I wondered for some time why this routine gets old entries, until
> looking at an strace revealed that the open() call on the file has
> O_CREAT set, but not O_TRUNC - so no new database seems to be done!

I can't reproduce it. Here is my minimal working example:

        #include <gdbm.h>
        #include <stdlib.h>
        #include <stdio.h>
        #include <time.h>

        int
        main(void)
        {
                GDBM_FILE db = gdbm_open("store.db", 0, GDBM_NEWDB|GDBM_SYNC, 
0644, NULL);
                datum datum, key;
                if (!db) {
                        fprintf(stderr, "Failed to open database: %s", 
gdbm_strerror(gdbm_errno));
                        return 1;
                }
                datum.dptr = malloc(100);
                datum.dsize = snprintf(datum.dptr, 1000, "%d", (int) 
(time(NULL)));
                gdbm_store(db, datum, datum, GDBM_REPLACE);

                for (key = gdbm_firstkey(db); key.dptr; key = gdbm_nextkey(db, 
key)) {
                        printf("%s\n", key.dptr);
                }
                return 0;
        }

As I understand your report, this program every invokation would output
one more line then on previous. At least on my system, this program
outputs exacly one line -- current time. I linked this program with
libgdbm3_1.8.3-13.1. Same behaviour with libgdbm4.

Moreover, in gdbm-1.12 source there is following lines in src/gdbmopen.c:144

        case GDBM_NEWDB:
          dbf->desc = open (dbf->name, O_RDWR|O_CREAT|fbits, mode);
          need_trunc = TRUE;
          break;

I understand, that this bug is almost 10 years old. So with reasoning
above I close it instead of marking +moreinfo/+unreproducible. Feel free
to reopen if you still experience problems.

-- 
X-Web-Site: https://sinsekvu.github.io | Note that I process my email in batch,
Accept-Languages: eo,ru,en             | at most once every 24 hours. If matter
Accept: text/plain, text/x-diff        | is urgent, you have my phone number.

Attachment: pgpAuDcBzca2x.pgp
Description: PGP signature

Reply via email to