From 08380ae64ec3d29f1335ce1d1a4a7b601be7903d Mon Sep 17 00:00:00 2001 From: Srinivasa Ragavan Date: Wed, 5 Dec 2007 15:11:26 +0000 Subject: ** Add basic support for crash recovery 2007-12-05 Srinivasa Ragavan ** Add basic support for crash recovery * apps_evolution_shell.schemas.in: Keys to recover and recovery dialog. * e-shell.c: (e_shell_quit): Delete the lock while quitting. * main.c: (show_recovery_warning), (idle_cb): Create lock and also show the warning dialog. svn path=/trunk/; revision=34652 --- e-util/ChangeLog | 7 +++++++ e-util/e-util.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ e-util/e-util.h | 4 ++++ 3 files changed, 60 insertions(+) (limited to 'e-util') diff --git a/e-util/ChangeLog b/e-util/ChangeLog index 06a841a3d7..1cd661efc8 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,10 @@ +2007-12-05 Srinivasa Ragavan + + * e-util.c: (get_lock_filename), (e_file_lock_create), + (e_file_lock_destroy), (e_file_lock_exists): Add utility functions for + startup-running lock create, check and delete. + * e-util.h: + 2007-12-04 Milan Crha ** Part of fix for bug #500210 diff --git a/e-util/e-util.c b/e-util/e-util.c index 625c617a8b..b1634bcfff 100644 --- a/e-util/e-util.c +++ b/e-util/e-util.c @@ -1017,3 +1017,52 @@ e_file_get_save_path (void) return (uri); } +/* Evolution Locks for crash recovery */ + +#define LOCK_FILE ".running" + +static const gchar * +get_lock_filename (void) +{ + static gchar *filename = NULL; + + if (G_UNLIKELY (filename == NULL)) + filename = g_build_filename (g_get_home_dir (), ".evolution", LOCK_FILE, NULL); + + return filename; +} + +gboolean +e_file_lock_create () +{ + const char *fname = get_lock_filename (); + gboolean status = FALSE; + + int fd = g_creat (fname, S_IRUSR|S_IWUSR); + if (fd == -1){ + g_warning ("Lock file '%s' creation failed, error %d\n", fname, errno); + } else { + status = TRUE; + close (fd); + } + + return status; +} + +void +e_file_lock_destroy () +{ + const char *fname = get_lock_filename (); + + if (g_unlink (fname) == -1){ + g_warning ("Lock destroy: failed to unlink file '%s'!",fname); + } +} + +gboolean +e_file_lock_exists () +{ + const char *fname = get_lock_filename (); + + return g_file_test (fname, G_FILE_TEST_EXISTS); +} diff --git a/e-util/e-util.h b/e-util/e-util.h index e3774c5852..b37f2abdb5 100644 --- a/e-util/e-util.h +++ b/e-util/e-util.h @@ -111,6 +111,10 @@ void e_file_update_save_path (gchar *uri, gboolean free); gchar * e_file_get_save_path (void); +gboolean e_file_lock_create (); +void e_file_lock_destroy (); +gboolean e_file_lock_exists (); + #ifdef __cplusplus } #endif /* __cplusplus */ -- cgit