app.c revision 6050eb5ab4fa30a6e24da98fcaccb7e9f0b7d11c
/*
* Copyright (C) 1999 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#include <config.h>
#include <pthread.h>
#include <stddef.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include "../util.h" /* XXX */
static isc_eventlist_t on_run;
static isc_mutex_t lock;
#ifndef HAVE_SIGWAIT
static void
empty_action(int arg) {
(void)arg;
}
#endif
isc_app_start(void) {
int presult;
#ifndef HAVE_SIGWAIT
#endif
/*
* Start an ISC library application.
*/
#ifdef NEED_PTHREAD_INIT
/*
* BSDI 3.1 seg faults in pthread_sigmask() if we don't do this.
*/
presult = pthread_init();
if (presult != 0) {
"isc_app_start() pthread_init: %s",
return (ISC_R_UNEXPECTED);
}
#endif
if (result != ISC_R_SUCCESS)
return (result);
#ifndef HAVE_SIGWAIT
/*
* Install do-nothing handlers for SIGINT and SIGTERM.
*
* We install them now because BSDI 3.1 won't block
* the default actions, regardless of what we do with
* pthread_sigmask().
*/
"isc_app_run() SIGINT setup: %s",
return (ISC_R_UNEXPECTED);
}
"isc_app_run() SIGTERM setup: %s",
return (ISC_R_UNEXPECTED);
}
#endif
/*
* Block SIGINT and SIGTERM.
*
* If isc_app_start() is called from the main thread before any other
* threads have been created, then the pthread_sigmask() call below
* will result in all threads having SIGINT and SIGTERM blocked by
* default.
*/
if (sigemptyset(&sset) != 0 ||
"isc_app_start() sigsetops: %s",
return (ISC_R_UNEXPECTED);
}
if (presult != 0) {
"isc_app_start() pthread_sigmask: %s",
return (ISC_R_UNEXPECTED);
}
return (ISC_R_SUCCESS);
}
isc_app_run(void) {
int result;
#if 0
#endif
#ifdef HAVE_SIGWAIT
int sig;
#endif
/*
* Run an ISC library application.
*/
#if 0
/*
* Post any on-run events (in LIFO order).
*/
event = next_event) {
}
#endif
#ifdef HAVE_SIGWAIT
/*
* Wait for SIGINT or SIGTERM.
*/
if (sigemptyset(&sset) != 0 ||
"isc_app_run() sigsetops: %s",
return (ISC_R_UNEXPECTED);
}
#else
/*
* Block all signals except for SIGINT and SIGTERM, and then
* wait for one of them to occur.
*/
if (sigfillset(&sset) != 0 ||
"isc_app_run() sigsetops: %s",
return (ISC_R_UNEXPECTED);
}
#endif
return (ISC_R_SUCCESS);
}
isc_app_shutdown(void) {
/*
* Request application shutdown.
*/
if (shutdown_requested)
else
"isc_app_shutdown() kill: %s",
return (ISC_R_UNEXPECTED);
}
return (ISC_R_SUCCESS);
}
void
isc_app_finish(void) {
/*
* Finish an ISC library application.
*/
(void)isc_mutex_destroy(&lock);
}