head 1.1; access; symbols; locks alexis:1.1; strict; comment @ * @; 1.1 date 97.01.31.14.43.34; author alexis; state Exp; branches; next ; desc @MILEPOST - MAY NOT WORK @ 1.1 log @Initial revision @ text @#include "pppld.h" /* for delayq defs */ #include /* for SIG* */ #include "pppld_utils.h" /* for DBG_* */ #include "pppld_ipc.h" /* for forward refs */ #include "pppld_msgids.h" /* for message ids */ #include "patchlevel.h" /* for forward ref */ #define REASON_UP 0 #define REASON_QUALITY 1 #define REASON_IDLE 2 #define REASON_HANGUP 3 #define REASON_REDIAL 4 #define QTEST_CMD "/home/alexis/dev/ppp/qtest" #define SNDMAIL_CMD "/home/alexis/dev/ppp/sndmail" #define GETMAIL_CMD "/home/alexis/dev/ppp/getmail" #define SNDNEWS_CMD "/home/alexis/dev/ppp/sndnews" #define GETNEWS_CMD "/home/alexis/dev/ppp/getnews" int reason_down; static char *rcs_id = "$Id$"; /* * Global data - idle check info */ int idlecheck_oldusecnt = -1; unsigned long idlecheck_oldusetim = 0; mhf_load_config() { debug(DBG_FUNCS, "mhf_load_config: sof"); state_cfgok = load_config("master.cfg", 0) ? 0 : 1; } mhf_info( int *info_requestp) { int i; long t = time(NULL); debug(DBG_FUNCS, "mhf_info: sof"); if (!(debug_level & DBG_INFO)) { debug_level |= DBG_INFO; debug(DBG_INFO, "turning info messages on"); } if (*info_requestp == 1) { info("STATES"); info("state_cfgok: %d", state_cfgok); info("state_curr: %d", state_curr); info("state_want: %d", state_want); info("state_done: %d", state_done); info("state_inipup: %d", state_inipup); info("state_donenx: %d", state_donenx); info("state_donemx: %d", state_donemx); info("state_quit: %d", state_quit); info("QUEUES"); info("delayq_top: %d", delayq_top); for (i=0; i idlecheck_oldusetim + idlecheck_timeout) { debug(DBG_IDLE, "mhf_exec_idle: idle and time limit expired!"); state_idle = 1; } else if (use == idlecheck_oldusecnt) { debug(DBG_IDLE, "mhf_exec_idle: idle"); } else { debug(DBG_IDLE, "mhf_exec_idle: not idle, saving current usage levels"); idlecheck_oldusetim = time(NULL); idlecheck_oldusecnt = use; } /* * Send a message to be acted on according to whether we have been idle * long enough or not. The code called could be incorporated here since * *this* function is so quick, but why bother? */ pppld_ipc_send_msg(svrmsginfdat, MSGTO_SVR, state_idle ? MSGID_NOK_IDLECHECK : MSGID_OK_IDLECHECK, NULL); } mhf_ok_idle() { debug(DBG_FUNCS, "mhf_ok_idle: sof"); if (idlecheck_timeout && state_curr) { debug(DBG_IDLE, "mhf_ok_idle: requeuing idle check for %d secs", idlecheck_interval); delaysendmsg(time(NULL)+idlecheck_interval, MSGID_EXEC_IDLECHECK, NULL); } else debug(DBG_IDLE, "mhf_ok_idle: NOT requeuing idle check"); } mhf_nok_idle() { debug(DBG_FUNCS, "mhf_nok_idle: sof"); /* no need to requeue the check message ... just let the idle process die */ state_want = 0; reason_down = REASON_IDLE; kill_pppd(); } mhf_unset_qualitycheck_interval() { int q = 0; debug(DBG_FUNCS, "mhf_unset_qualitycheck_interval: sof"); /* * That variable may be automatic since pppld_ipc_send_msg() really * has finished with the memory it's in when it exits. (It constructs * a text string from the args and dispatches the message. */ pppld_ipc_send_msg(svrmsginfdat, MSGTO_SVR, MSGID_SET_QUALITYCHECK, &q); } mhf_set_debug( int *debug_levelp) { debug(DBG_FUNCS, "mhf_set_debug: sof"); /* * Note that the mhf functions currently take integers as parameters * and that debug_level is a long. Really the parameter should be the * address of a union of int, unsigned long and char *. And the * mhf functions should extract the bit they want. But we'll leave * that for the time being. */ debug_level = (unsigned long) *debug_levelp; } mhf_set_qualitycheck_interval( int *new_qualitycheck_intervalp) { int old_qualitycheck_interval = qualitycheck_interval; int i; debug(DBG_FUNCS, "mhf_set_qualitycheck_interval: sof"); qualitycheck_interval = *new_qualitycheck_intervalp; /* * if we require a positive quality and we have a positive interval but * didn't have one already! ... and of course we're connected and * want to be ... */ if (qualitycheck_interval && !old_qualitycheck_interval && qualitycheck_minquality) { if (state_curr && state_want) pppld_ipc_send_msg(svrmsginfdat, MSGTO_SVR, MSGID_EXEC_QTEST, NULL); /* * if it is the toggling of the quality interval that should deactivate * the delayed queued quality checks then cancel them now */ } else if (qualitycheck_minquality) /* dequeuing could go here, instead od being in a separate function */ for (i=0; i