Aquí os envío una pequeña aportación con unas funciones que ayudarán a depurar el proyecto. Index: src/slabot.c =================================================================== --- src/slabot.c (revisión: 52) +++ src/slabot.c (copia de trabajo) @@ -34,6 +34,7 @@ #include <config.h> #include "irc/irc.h" #include "common.h" +#include "debug.h" #define DEFAULT_NICK "Slabot" #define DEFAULT_PORT 6667 @@ -159,6 +160,8 @@ /* Aqui debe ir un bucle */ IrcServer * irc; irc = irc_server_new (server, port); + + debug_init (); irc_init (); irc_connect (irc, nick); @@ -168,6 +171,7 @@ irc_server_destroy (irc); + /* debug_end (); */ return 0; } Index: src/ChangeLog =================================================================== --- src/ChangeLog (revisión: 52) +++ src/ChangeLog (copia de trabajo) @@ -1,3 +1,10 @@ +2007-06-27 kmikc <[email protected]> + + * debug.c (debug_init): Inicializa el sistema de depurado. + (debug_end): Finaliza el sistema de depurado. + (pidfile_create): Crea el archivo /tmp/slabot.$UID con el PID del proceso. + (pidfile_remove): Borra el archivo con el PID. + 2007-06-27 iobrain <iobrain <[email protected]>> * debug.h: @@ -105,7 +112,7 @@ programa fallaba al hacer -V. Faltaba la entrada NULL en longopts. (main): La opcion V faltaba en el tercer argumento de getopt_long_only. -2007-06-24 KmIkC <[email protected]> +2007-06-24 kmikc <[email protected]> * slabot.c (notice_version): Crea el argumento --version para mostrar el aviso de Copyright. Index: src/debug.c =================================================================== --- src/debug.c (revisión: 52) +++ src/debug.c (copia de trabajo) @@ -26,4 +26,56 @@ * */ +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> + #include "debug.h" +#include "common.h" + +#define PATH_PIDFILE "/tmp/" + +static char * path = NULL; + +static void pidfile_create (); +static void pidfile_remove (); + +static void +pidfile_create () +{ + if (path != NULL) + pidfile_remove (); + + path = strbuild (PATH_PIDFILE "slabot.%d", PATH_PIDFILE, getuid ()); + + pid_t pid = getpid (); + FILE * file; + file = fopen (path, "wb"); + fwrite (&pid, sizeof (pid_t), 1, file); + + fclose (file); +} + +static void +pidfile_remove () +{ + if (path == NULL) + return; + + remove (path); + free (path); +} + +void +debug_init () +{ + atexit (debug_end); + + pidfile_create (); +} + +void +debug_end () +{ + pidfile_remove (); +} Index: src/debug.h =================================================================== --- src/debug.h (revisión: 52) +++ src/debug.h (copia de trabajo) @@ -29,9 +29,9 @@ #ifndef DEBUG_H #define DEBUG_H +void debug_init (); +void debug_end (); - - #endif /* not DEBUG_H */
participants (2)
-
iobrain -
KmIkC