diff --git a/cronjob/chart/Makefile b/cronjob/chart/Makefile index 48a0d73..80ff0f8 100644 --- a/cronjob/chart/Makefile +++ b/cronjob/chart/Makefile @@ -6,7 +6,7 @@ LDFLAS = -o INCL = -I$$(pg_config --includedir) BIN_NAME = chart -OBJS = chart.o config.o +OBJS = chart.o config.o drawing/process_image.o CONF_NAME = chart.conf @@ -29,13 +29,14 @@ $(BIN_NAME): $(OBJS) @ echo Binary $(BIN_NAME) ist fertig! # Abhängigkeiten -chart.o: chart.c definitions.h config.h chart.h +chart.o: chart.c definitions.h config.h chart.h drawing/process_image.h config.o: config.c config.h definitions.h chart.h +drawing/process_image.o: drawing/process_image.c # Compillieren $(OBJS): - @ echo "Kompilliere: "$(CC) $(DEBUG) $(NOLOG) $(INCL) $(CFLAGS) $*.c - @ $(CC) $(DEBUG) $(NOLOG) $(INCL) $(CFLAGS) $*.c + @ echo "Kompilliere: "$(CC) -o $@ $(DEBUG) $(NOLOG) $(INCL) $(CFLAGS) $*.c + @ $(CC) -o $@ $(DEBUG) $(NOLOG) $(INCL) $(CFLAGS) $*.c # Programm mit debug-ausgabe bauen debug: diff --git a/cronjob/chart/chart.c b/cronjob/chart/chart.c index af4420a..fc94b49 100644 --- a/cronjob/chart/chart.c +++ b/cronjob/chart/chart.c @@ -32,11 +32,48 @@ #include "definitions.h" #include "config.h" #include "chart.h" +#include "drawing/process_image.h" +static int walk_image_cfg_list(); +static void wait_for_childs(); static void exit_sig_handler(int); config global_opts; + + +static int walk_image_cfg_list(){ + int has_forked = 0; + pid_t pid = 0; + image_cfg_list_ptr tmp_ptr = global_opts.image_cfg; + + for(; tmp_ptr; tmp_ptr = tmp_ptr->next){ + if(global_opts.fork){ + if((pid = fork()) == 0){ + process_image(tmp_ptr->image_cfg_file); + exit(EXIT_SUCCESS); + } + else if (pid == -1){ + exit_error(ERROR_FORK); + } + has_forked++; + DEBUGOUT2("Prozess %d angelegt\n",pid); + } else { + process_image(tmp_ptr->image_cfg_file); + } + } + return has_forked; +} + +static void wait_for_childs(){ + int ret_val; + pid_t pid; + while((pid = wait(&ret_val)) != -1){ + DEBUGOUT2("Prozess %d beendet\n", pid); + } +} + + int main(int argc, char *argv[]){ DEBUGOUT1("Programm gestartet\n"); @@ -66,6 +103,9 @@ int main(int argc, char *argv[]){ DEBUGOUT2(" Pass: = %s\n",global_opts.pg_pass); DEBUGOUT2(" Datenbank = %s\n",global_opts.pg_database); + if(walk_image_cfg_list()) + wait_for_childs(); + return EXIT_SUCCESS; } diff --git a/cronjob/chart/chart.conf b/cronjob/chart/chart.conf index 7c3e056..601afdf 100644 --- a/cronjob/chart/chart.conf +++ b/cronjob/chart/chart.conf @@ -1,7 +1,8 @@ fork yes -image_cfg bla image_cfg_location blub/ +image_cfg bla +image_cfg blo # Postgres-Einstellungen pg_host 141.30.228.39 diff --git a/cronjob/chart/definitions.h b/cronjob/chart/definitions.h index d4ce2d3..8b2747b 100644 --- a/cronjob/chart/definitions.h +++ b/cronjob/chart/definitions.h @@ -1,8 +1,6 @@ /* - weatherdeamon -- Weather Data Capture Program for the - 'ELV-PC-Wettersensor-Empfänger' - definitions.h -- Part of the weatherdeamon + definitions.h -- Part of Chart-generator for the weatherstation Copyright (C) 2006 Jan Losinski @@ -20,7 +18,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: process.c v 1.00 11 Aug 2006 losinski $ */ /* Default-Werte ----------------------------------------------------- */ @@ -37,6 +34,7 @@ /* Fehlermeldungen ------------------------------------------------------*/ #define ERROR_SEIINST "Signal-Fehler: Kann Signalhandler zum beenden nicht installieren\n" +#define ERROR_FORK "Fork-Fehler: Kann keinen neuen Prozess anlegen\n" /* Puffergrößen -------------------------------------------------------- */ diff --git a/cronjob/chart/drawing/process_image.c b/cronjob/chart/drawing/process_image.c new file mode 100644 index 0000000..e9220af --- /dev/null +++ b/cronjob/chart/drawing/process_image.c @@ -0,0 +1,29 @@ +/* + + process_image.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 +#include +#include "process_image.h" + +void process_image(char *image_cfg_file){ + printf("%s\n",image_cfg_file); + sleep(3); +} diff --git a/cronjob/chart/drawing/process_image.h b/cronjob/chart/drawing/process_image.h new file mode 100644 index 0000000..6f8e449 --- /dev/null +++ b/cronjob/chart/drawing/process_image.h @@ -0,0 +1,23 @@ +/* + + process_image.h -- 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. + +*/ + +void process_image(char *);