]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/tdb.c
pppd.8: Document netmask option
[ppp.git] / pppd / tdb.c
index bdc58288da023b489983b994b1cc53b126de6e97..ecbee1f7dcecde8501ba28cdd3f4fd5c0f32626e 100644 (file)
  * right time.  Probably too hard -- the process just doesn't know.
  */ 
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <fcntl.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <signal.h>
+
+#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) */