First code for SIGHUP reconfiguration. It still doesn't work fine. More in TODO.
--- a/TODO.txt Sun May 14 21:13:42 2006 +0200
+++ b/TODO.txt Sun May 14 21:35:47 2006 +0200
@@ -3,8 +3,13 @@
* establir els permisos del unix socket
* Implementar la sortida UDP.
+ Done.
* Implementar el HUP al kernel - rellegir la configuració.
+ This requires asynchronous receiving in the kernel. If not, how? !!!
* Implementar catxé de log-file amb SIGUSR1 associat. (De veritat?!)
I won't do that for this release.
* Implementar una mort neta dels childs (SIGTERM) i el kernel.
Done in kernel and in_unix. The others die quite fine.
+
+* The childs should control SIGINT. Otherwise, they become killed on Control-C
+ under an xterm.
--- a/syslog_kernel.c Sun May 14 21:13:42 2006 +0200
+++ b/syslog_kernel.c Sun May 14 21:35:47 2006 +0200
@@ -34,6 +34,7 @@
} child[END_CHILDS];
static int childs_alive = 0;
+static bool reconfig = false;
/* Prototypes */
static void term_childs();
@@ -87,6 +88,11 @@
term_childs();
}
+static void reconfig_handler(int parameter)
+{
+ reconfig = true;
+}
+
static int run_program(const char * restrict programname,
const char * restrict parameter1, const int comm_pipe[])
@@ -214,6 +220,9 @@
/* Output to screen */
fprintf(stderr, "Received: %s\n",missatge);
+
+ /* Output to file */
+ /* The \0 end is not written */
do
{
res_w = write(output, missatge, res_r);
@@ -256,6 +265,9 @@
}
else /* End of read: res_r -1 or 0 */
break;
+
+ if (reconfig == true)
+ break;
}
if (res_r == -1)
@@ -287,6 +299,7 @@
program_child_handler(child_handler);
program_handler(SIGTERM, term_handler);
program_handler(SIGINT, term_handler);
+ program_handler(SIGUSR1, reconfig_handler);
}
static void term_childs()
@@ -336,19 +349,23 @@
install_signal_handlers();
- init_config();
-
- res = init_out_udp();
- if (res == -2)
- fprintf(stderr, "UDP output not in configuration.\n");
- else if (res == -1)
- fprintf(stderr, "error setting up the UDP output.\n");
+ do
+ {
+ reconfig = false;
+ init_config();
- kernel_loop();
+ res = init_out_udp();
+ if (res == -2)
+ fprintf(stderr, "UDP output not in configuration.\n");
+ else if (res == -1)
+ fprintf(stderr, "error setting up the UDP output.\n");
- term_childs();
+ kernel_loop();
- wait_childs_die();
-
- close_out_udp();
+ term_childs();
+
+ wait_childs_die();
+ close_out_udp();
+ }
+ while(reconfig == true);
}