X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Fmain.c;h=862a2d4bafc63e4b8fd6abb7522cd0f983043386;hb=13f0a771fd659bc3e0752eee48439b497cf27dae;hp=ffeaca09a91f5f639a1212ae5dec04bef6bf69c4;hpb=1b458f6ef62fc571335686ac60dbfad8875e83a3;p=ppp.git diff --git a/pppd/main.c b/pppd/main.c index ffeaca0..862a2d4 100644 --- a/pppd/main.c +++ b/pppd/main.c @@ -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 #include @@ -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.