101 lines
3.0 KiB
C
101 lines
3.0 KiB
C
/*
|
|
|
|
chart.c -- Part of Chart-generator for the weatherstation
|
|
|
|
Copyright (C) 2006 Jan Losinski
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <sys/types.h>
|
|
#include <sys/wait.h>
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
#include <signal.h>
|
|
#include <string.h>
|
|
|
|
#include "definitions.h"
|
|
#include "config.h"
|
|
#include "chart.h"
|
|
|
|
static void exit_sig_handler(int);
|
|
|
|
config global_opts;
|
|
|
|
int main(int argc, char *argv[]){
|
|
DEBUGOUT1("Programm gestartet\n");
|
|
|
|
if(signal(SIGABRT, exit_sig_handler) == SIG_ERR)
|
|
exit_error(ERROR_SEIINST);
|
|
DEBUGOUT1("Signalhandler zum beenden per SIGABRT installiert\n");
|
|
if(signal(SIGINT, exit_sig_handler) == SIG_ERR)
|
|
exit_error(ERROR_SEIINST);
|
|
DEBUGOUT1("Signalhandler zum beenden per SIGINT installiert\n");
|
|
if(signal(SIGQUIT, exit_sig_handler) == SIG_ERR)
|
|
exit_error(ERROR_SEIINST);
|
|
DEBUGOUT1("Signalhandler zum beenden per SIGQUIT installiert\n");
|
|
if(signal(SIGTERM, exit_sig_handler) == SIG_ERR)
|
|
exit_error(ERROR_SEIINST);
|
|
DEBUGOUT1("Signalhandler zum beenden per SIGTERM installiert\n");
|
|
|
|
read_config(DEFAULT_CONFIG_FILE, 1);
|
|
|
|
/* Debug-Ausgaben, um zu sehen, ob die Optionen richtig gesetzt werden */
|
|
DEBUGOUT1("\nOptionen:\n");
|
|
DEBUGOUT2(" cfg_location = %s\n", global_opts.image_cfg_location);
|
|
DEBUGOUT2(" fork = %i\n", global_opts.fork);
|
|
|
|
DEBUGOUT1("\nPostgres:\n");
|
|
DEBUGOUT2(" Host: = %s\n",global_opts.pg_host);
|
|
DEBUGOUT2(" User: = %s\n",global_opts.pg_user);
|
|
DEBUGOUT2(" Pass: = %s\n",global_opts.pg_pass);
|
|
DEBUGOUT2(" Datenbank = %s\n",global_opts.pg_database);
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|
|
|
|
|
|
/* Diese Funktion beendet das Programm mit einer Fehlermeldung. */
|
|
void exit_error(char* err){
|
|
DEBUGOUT1("\nEtwas unschoenes ist passiert\n");
|
|
if(errno != 0){
|
|
perror("Fehler");
|
|
}
|
|
write(STDOUT_FILENO, err, strlen(err));
|
|
exit(1);
|
|
}
|
|
|
|
/* Wird bei Beendigungssignalen ausgefuehrt */
|
|
static void exit_sig_handler(int signr){
|
|
#ifdef DEBUG
|
|
DEBUGOUT1("\n");
|
|
switch (signr){
|
|
case SIGABRT:
|
|
DEBUGOUT1("SIGABRT Interupt erhalten!\n");
|
|
case SIGTERM:
|
|
DEBUGOUT1("SIGTERM Interupt erhalten!\n");
|
|
case SIGQUIT:
|
|
DEBUGOUT1("SIGQUIT Interupt erhalten!\n");
|
|
case SIGINT:
|
|
DEBUGOUT1("SIGINT Interupt erhalten!\n");
|
|
}
|
|
#endif
|
|
DEBUGOUT1("Beende Programm...\n");
|
|
exit(0);
|
|
}
|