X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Ftdb.c;h=8a563f88b9a62b8aedc2ea504f8f8b22afdddb95;hb=HEAD;hp=bdc58288da023b489983b994b1cc53b126de6e97;hpb=13f0a771fd659bc3e0752eee48439b497cf27dae;p=ppp.git diff --git a/pppd/tdb.c b/pppd/tdb.c index bdc5828..ecbee1f 100644 --- a/pppd/tdb.c +++ b/pppd/tdb.c @@ -46,6 +46,10 @@ * right time. Probably too hard -- the process just doesn't know. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include @@ -56,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) @@ -926,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 */ @@ -1724,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) */