X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Ftdb.c;h=bdc58288da023b489983b994b1cc53b126de6e97;hb=HEAD;hp=8a563f88b9a62b8aedc2ea504f8f8b22afdddb95;hpb=ab4d4992050ec171e1c72d661a3457efc8e7c141;p=ppp.git diff --git a/pppd/tdb.c b/pppd/tdb.c index 8a563f8..ecbee1f 100644 --- a/pppd/tdb.c +++ b/pppd/tdb.c @@ -60,8 +60,11 @@ #include #include #include + +#include "pppd-private.h" #include "tdb.h" #include "spinlock.h" +#include "pathnames.h" #define TDB_MAGIC_FOOD "TDB file\n" #define TDB_VERSION (0x26011967 + 6) @@ -930,7 +933,7 @@ static int tdb_new_database(TDB_CONTEXT *tdb, int hash_size) /* We make it up in memory, then write it out if not internal */ size = sizeof(struct tdb_header) + (hash_size+1)*sizeof(tdb_off); - if (!(newdb = calloc(size, 1))) + if (!(newdb = calloc(1, size))) return TDB_ERRCODE(TDB_ERR_OOM, -1); /* Fill in the header */ @@ -1728,7 +1731,12 @@ TDB_CONTEXT *tdb_open_ex(const char *name, int hash_size, int tdb_flags, goto internal; } +again: if ((tdb->fd = open(name, open_flags, mode)) == -1) { + if ((open_flags & O_CREAT) && errno == ENOENT && + mkdir_recursive(PPP_PATH_VARRUN) == 0) + goto again; + TDB_LOG((tdb, 5, "tdb_open_ex: could not open file %s: %s\n", name, strerror(errno))); goto fail; /* errno set by open(2) */