/*
** SellaNMS
** $Id: daemon.cxx,v 1.2 2006/01/24 07:08:10 sella Exp $
** Copyright (c) 2001-2005 Digital Genesis Software, LLC. All Rights Reserved.
** Released under the GPL Version 2 License.
** http://www.digitalgenesis.com
*/

#include "daemon.h"
#include "sella_nms.h"
#include <signal.h>

static const char rcsid[] = "$Id: daemon.cxx,v 1.2 2006/01/24 07:08:10 sella Exp $";

void sighandler(int sig) {
	switch (sig) {
		case SIGUSR1:
			LMSG("Caught SIGUSR1 - daemon");
			break;

		case SIGUSR2:
			LMSG("Caught SIGUSR2 - daemon");
			break;

		default:
			LMSG("Caught unknown signal - daemon");
	}
}

bool start() {
	SellaNMS *sella_nms = NULL;

	/* Install Signal Handlers */
	if (signal(SIGUSR1, &sighandler) == SIG_ERR) {
		LMSG("Failed to install signal handler for SIGUSR1.");
	}
	if (signal(SIGUSR2, &sighandler) == SIG_ERR) {
		LMSG("Failed to install signal handler for SIGUSR2.");
	}

	TRACE(TRACE_INTERNAL, "internal - start()");
	TRACE(TRACE_DEBUG, "debug - start()");
	TRACE(TRACE_CONFIG, "config - start()");

	if ((sella_nms = new SellaNMS()) != NULL) {
		if (sella_nms->readConfig() == SUCCESS) {
			sella_nms->execute();
		}

		SAFE_DELETE(sella_nms);
	} else {
		LMSG("Failed to allocate memory for SellaNMS().");

		return false;
	}

	return true;
}

const char* getName() {
	return "sella_nms";
}

const char* getDefaultConfigPath() {
	return "system";
}

const char* getProcTitle() {
	return getName();
}

const char* getDefaultConfigFile() {
	return DEFAULT_CONFIG_FILE;
}

const char* getDefaultPidFile() {
	return DEFAULT_PID_FILE;
}

const char* getDefaultStatFile() {
	return DEFAULT_STAT_FILE;
}

int getDefaultNiceness() {
	return DEFAULT_NICENESS;
}

/*
** Local Variables:
** c-basic-offset: 3
** tab-width: 3
** End:
** vim:
** vim: noet ts=3 sw=3
*/
