/* ******************************************************************************* * Copyright (c) 1997 Martin Poole * ******************************************************************************* ** ** WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! ** ** Any changes to be made to this file should first be checked with ** mplib1 source control for library integrity. ** ** mplib1 source control can be reached at mplib1@quatermass.co.uk ** * * $Source: /home/cvs/cvsroot/onelan/onelan/src/mplib1/libsrc/daemonloop.c,v $ * $Author: mpoole $ * $Date: 2002/10/07 09:37:38 $ * $Revision: 1.2 $ * Purpose : * ******************************************************************************* * * Change History * * $Log: daemonloop.c,v $ * Revision 1.2 2002/10/07 09:37:38 mpoole * Initial checkin of mplib1-3.1.0 * * Revision 1.1 2002/10/07 09:36:55 mpoole * Initial checkin of mplib1-3.1.0 * * ******************************************************************************* */ #ident "$Header: /home/cvs/cvsroot/onelan/onelan/src/mplib1/libsrc/daemonloop.c,v 1.2 2002/10/07 09:37:38 mpoole Exp $" /* ------------------------------------------------------------------ Include files ------------------------------------------------------------------ */ #include #include #include #include #include /* ------------------------------------------------------------------ structures / defines ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ Code starts here ------------------------------------------------------------------ */ int mp_daemon_loop( int(*poll_func)(int), int(*u1_func)(int), int(*u2_func)(int), int(*int_func)(int), int(*term_func)(int), int flags ) { int rv=0,t,poll_period; /* This function provides a standard daemon loop. It sleeps for the specified period (unless awoken early), and then calls the relevant dispatch function. Any dispatch function that returns non-zero causes the loop to exit. The dispatch function called will have two parameters. The first if the signal that caused the call (or zero), the second, the return value from the sleep call */ do { poll_period = get_config_int( "POLL_PERIOD" ); if (poll_period<1) poll_period=60; switch(t=check_signalling()) { case SIGINT : if (int_func) rv = (*int_func)( t ); else rv = t; break; case SIGTERM : if (term_func) rv = (*term_func)( t ); else rv = t; break; case SIGUSR1 : if (u1_func) rv = (*u1_func)( t ); else rv = 0; break; case SIGUSR2 : if (u2_func) rv = (*u2_func)( t ); else rv = 0; break; case SIGHUP : restart_files(); break; default : rv = poll_func( 0 ); break; } if (rv==0) t = mp_daemon_sleep( poll_period ); }while (rv==0); return(rv); } /* -- End of File -- */