]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/main.c
New version of TDB code, borrowed from samba.
[ppp.git] / pppd / main.c
index ffeaca09a91f5f639a1212ae5dec04bef6bf69c4..862a2d4bafc63e4b8fd6abb7522cd0f983043386 100644 (file)
@@ -66,7 +66,7 @@
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#define RCSID  "$Id: main.c,v 1.146 2004/11/12 11:21:41 paulus Exp $"
+#define RCSID  "$Id: main.c,v 1.147 2004/11/13 12:02:22 paulus Exp $"
 
 #include <stdio.h>
 #include <ctype.h>
@@ -481,14 +481,8 @@ main(argc, argv)
        /*
         * Open the loopback channel and set it up to be the ppp interface.
         */
-#ifdef USE_TDB
-       tdb_writelock(pppdb);
-#endif
        fd_loop = open_ppp_loopback();
        set_ifunit(1);
-#ifdef USE_TDB
-       tdb_writeunlock(pppdb);
-#endif
        /*
         * Configure the interface and mark it up, etc.
         */
@@ -1923,6 +1917,41 @@ script_unsetenv(var)
 #endif
 }
 
+/*
+ * Any arbitrary string used as a key for locking the database.
+ * It doesn't matter what it is as long as all pppds use the same string.
+ */
+#define PPPD_LOCK_KEY  "pppd lock"
+
+/*
+ * lock_db - get an exclusive lock on the TDB database.
+ * Used to ensure atomicity of various lookup/modify operations.
+ */
+void lock_db()
+{
+#ifdef USE_TDB
+       TDB_DATA key;
+
+       key.dptr = PPPD_LOCK_KEY;
+       key.dsize = strlen(key.dptr);
+       tdb_chainlock(pppdb, key);
+#endif
+}
+
+/*
+ * unlock_db - remove the exclusive lock obtained by lock_db.
+ */
+void unlock_db()
+{
+#ifdef USE_TDB
+       TDB_DATA key;
+
+       key.dptr = PPPD_LOCK_KEY;
+       key.dsize = strlen(key.dptr);
+       tdb_chainunlock(pppdb, key);
+#endif
+}
+
 #ifdef USE_TDB
 /*
  * update_db_entry - update our entry in the database.