Better error checking and memory handling when in daemon mode.

This commit is contained in:
Frederic Culot 2009-07-27 21:02:55 +00:00
parent 4f0c71585d
commit 3509b7bb72
2 changed files with 28 additions and 13 deletions

View File

@ -3,7 +3,9 @@
* src/utils.c (free_user_data): new function * src/utils.c (free_user_data): new function
* src/dmon.c: work on allocating and freeing memory associated * src/dmon.c: work on allocating and freeing memory associated
with user data with user data + log problems related to data file access
* src/io.c (io_file_exist): new function
2009-07-26 Frederic Culot <frederic@culot.org> 2009-07-26 Frederic Culot <frederic@culot.org>

View File

@ -1,4 +1,4 @@
/* $calcurse: dmon.c,v 1.6 2009/07/27 19:35:09 culot Exp $ */ /* $calcurse: dmon.c,v 1.7 2009/07/27 21:02:55 culot Exp $ */
/* /*
* Calcurse - text-based organizer * Calcurse - text-based organizer
@ -61,12 +61,20 @@
#define DMON_ABRT(...) do { \ #define DMON_ABRT(...) do { \
DMON_LOG (__VA_ARGS__); \ DMON_LOG (__VA_ARGS__); \
if (kill (getpid (), SIGINT) < 0) \
{ \
DMON_LOG (_("Could not stop daemon properly: %s\n"), \
strerror (errno)); \
exit (EXIT_FAILURE); \ exit (EXIT_FAILURE); \
} \
} while (0) } while (0)
static unsigned data_loaded;
static void static void
dmon_sigs_hdlr (int sig) dmon_sigs_hdlr (int sig)
{ {
if (data_loaded)
free_user_data (); free_user_data ();
DMON_LOG (_("terminated at %s with signal %d\n"), nowstr (), sig); DMON_LOG (_("terminated at %s with signal %d\n"), nowstr (), sig);
@ -161,14 +169,19 @@ dmon_start (int parent_exit_status)
if (!io_dump_pid (path_dpid)) if (!io_dump_pid (path_dpid))
DMON_ABRT (_("Could not set lock file\n")); DMON_ABRT (_("Could not set lock file\n"));
io_check_file (path_conf, (int *)0); if (!io_file_exist (path_conf))
DMON_ABRT (_("Could not access \"%s\": %s\n"),
path_conf, strerror (errno));
custom_load_conf (&conf, 0); custom_load_conf (&conf, 0);
io_check_file (path_apts, (int *)0); if (!io_file_exist (path_apts))
DMON_ABRT (_("Could not access \"%s\": %s\n"),
path_apts, strerror (errno));
apoint_llist_init (); apoint_llist_init ();
recur_apoint_llist_init (); recur_apoint_llist_init ();
io_load_app (); io_load_app ();
data_loaded = 1;
for (;;) for (;;)
{ {
struct notify_app_s next; struct notify_app_s next;