* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#define RCSID "$Id: main.c,v 1.145 2004/11/12 10:30:51 paulus Exp $"
+#define RCSID "$Id: main.c,v 1.148 2004/11/13 12:05:48 paulus Exp $"
#include <stdio.h>
#include <ctype.h>
int fd_ppp = -1; /* fd for talking PPP */
int phase; /* where the link is at */
int kill_link;
+int asked_to_quit;
int open_ccp_flag;
int listen_time;
int got_sigusr2;
setup_signals();
+ create_linkpidfile(getpid());
+
waiting = 0;
/*
/*
* 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.
*/
add_fd(fd_loop);
for (;;) {
handle_events();
- if (kill_link && !persist)
+ if (asked_to_quit)
break;
if (get_loop_output())
break;
}
remove_fd(fd_loop);
- if (kill_link && !persist)
+ if (asked_to_quit)
break;
/*
while (phase != PHASE_DEAD) {
handle_events();
get_input();
- if (kill_link) {
- bundle_terminating = 1;
+ if (kill_link)
lcp_close(0, "User request");
+ if (asked_to_quit) {
+ bundle_terminating = 1;
if (phase == PHASE_MASTER)
mp_bundle_terminated();
}
}
}
- if (!persist || (maxfail > 0 && unsuccess >= maxfail))
+ if (!persist || asked_to_quit || (maxfail > 0 && unsuccess >= maxfail))
break;
if (demand)
if (got_sigterm) {
info("Terminating on signal %d", got_sigterm);
kill_link = 1;
+ asked_to_quit = 1;
persist = 0;
status = EXIT_USER_REQUEST;
got_sigterm = 0;
#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.