# HG changeset patch # User J. Ali Harlow # Date 1446491098 0 # Node ID a53fcb7804680c18c57a9d17d2220b7658fa0390 # Parent 3ee18a3a0f58984e7201d1718a41f73156ae7bb3 Use google-breakpad as an exception handler diff -r 3ee18a3a0f58 -r a53fcb780468 app-manager/app-manager.c --- a/app-manager/app-manager.c Mon Nov 02 19:01:50 2015 +0000 +++ b/app-manager/app-manager.c Mon Nov 02 19:04:58 2015 +0000 @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include "app-manager.h" @@ -244,6 +245,7 @@ ShowWindow(GetConsoleWindow(),SW_HIDE); } #endif + plover_exception_handler_init(); razor_set_lua_loader("posix",luaopen_posix); razor_set_lua_loader("whelk",luaopen_whelk); if (!gtk_init_with_args(&argc,&argv,NULL,options,NULL,&err)) diff -r 3ee18a3a0f58 -r a53fcb780468 configure.ac --- a/configure.ac Mon Nov 02 19:01:50 2015 +0000 +++ b/configure.ac Mon Nov 02 19:04:58 2015 +0000 @@ -1,7 +1,7 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. -AC_INIT([plover],[0.5],[ali@juiblex.co.uk]) +AC_INIT([plover],[0.5.1],[ali@juiblex.co.uk]) AC_PREREQ(2.59) AC_CONFIG_AUX_DIR([config]) AC_CONFIG_SRCDIR([plover/plover.h]) @@ -70,9 +70,9 @@ # increment CURRENT and set AGE and REVISION to 0. # - If the interface is the same as the previous version, increment REVISION. # -lt_current=3 +lt_current=4 lt_revision=0 -lt_age=0 +lt_age=1 LIBPLOVER_LT_VERSION_INFO="$lt_current:$lt_revision:$lt_age" AC_SUBST(LIBPLOVER_LT_VERSION_INFO) @@ -88,6 +88,7 @@ # Checks for programs. ################################################## AC_PROG_CC +AC_PROG_CXX AC_LIBTOOL_WIN32_DLL AC_PROG_LIBTOOL PKG_PROG_PKG_CONFIG @@ -163,6 +164,22 @@ fi AC_SUBST([FETCH_LIBS]) LIBS="$save_LIBS" +AC_ARG_WITH([breakpad], + [AS_HELP_STRING([--with-breakpad], + [produce minidumps on crash @<:@default=check@:>@])], + [],[with_breakpad=check]) +if test "$with_breakpad" != no; then + PKG_CHECK_MODULES([BREAKPAD],[breakpad-client], + [have_breakpad="yes";REQUIREMENTS="$REQUIREMENTS x11"],[have_breakpad="no"]) + if test "$have_breakpad" = yes; then + AC_DEFINE([HAVE_BREAKPAD],[1],[Define if breakpad is available.]) + elif test "$with_breakpad" = yes; then + AC_MSG_ERROR([$BREAKPAD_PKG_ERRORS]) + fi +else + have_breakpad="no" +fi +AM_CONDITIONAL([HAVE_BREAKPAD],[test $have_breakpad = yes]) ################################################## # Checks for library functions. diff -r 3ee18a3a0f58 -r a53fcb780468 plover-open/plover-open.c --- a/plover-open/plover-open.c Mon Nov 02 19:01:50 2015 +0000 +++ b/plover-open/plover-open.c Mon Nov 02 19:04:58 2015 +0000 @@ -164,6 +164,7 @@ ShowWindow(GetConsoleWindow(),SW_HIDE); } #endif + plover_exception_handler_init(); razor_set_lua_loader("posix",luaopen_posix); razor_set_lua_loader("whelk",luaopen_whelk); if (!gtk_init_with_args(&argc,&argv,NULL,options,NULL,&err)) diff -r 3ee18a3a0f58 -r a53fcb780468 plover/Makefile.am --- a/plover/Makefile.am Mon Nov 02 19:01:50 2015 +0000 +++ b/plover/Makefile.am Mon Nov 02 19:04:58 2015 +0000 @@ -1,4 +1,5 @@ AM_CFLAGS=-g $(LIBPLOVER_CFLAGS) +AM_CXXFLAGS=-g $(LIBPLOVER_CFLAGS) LIBS=$(LIBPLOVER_LIBS) INCLUDES=-I$(top_srcdir) AM_LDFLAGS=-no-undefined -version-info $(LIBPLOVER_LT_VERSION_INFO) @@ -7,7 +8,8 @@ lib_LTLIBRARIES=libplover.la libplover_la_SOURCES=$(pkginclude_HEADERS) util.c import-yum.c razor.c comps.c \ - log.c vector.c transaction.c package.c packageset.c repository.c + log.c vector.c transaction.c package.c packageset.c repository.c \ + exception-handler.cpp pkgconfigdir=$(libdir)/pkgconfig pkgconfig_DATA=plover.pc diff -r 3ee18a3a0f58 -r a53fcb780468 plover/exception-handler.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plover/exception-handler.cpp Mon Nov 02 19:04:58 2015 +0000 @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2015 J. Ali Harlow + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include "plover/plover.h" +#if defined(HAVE_BREAKPAD) && defined(WIN32) +#include +#include +#endif + +extern "C" { + +#if defined(HAVE_BREAKPAD) && defined(WIN32) +static google_breakpad::ExceptionHandler *plover_exception_handler=NULL; +#endif + +void plover_exception_handler_init(void) +{ +#if defined(HAVE_BREAKPAD) && defined(WIN32) + gchar *path; + WCHAR *dump_path; + if (!plover_exception_handler) + { + path=plover_get_reports_directory(); + dump_path=(WCHAR *)g_utf8_to_utf16(path,-1,NULL,NULL,NULL); + g_free(path); + plover_exception_handler=new + google_breakpad::ExceptionHandler(dump_path,NULL,NULL,NULL, + google_breakpad::ExceptionHandler::HANDLER_ALL,MiniDumpWithDataSegs, + NULL,NULL); + g_free(dump_path); + } +#endif /* HAVE_BREAKPAD && WIN32 */ +} + +} // extern "C" diff -r 3ee18a3a0f58 -r a53fcb780468 plover/plover.h --- a/plover/plover.h Mon Nov 02 19:01:50 2015 +0000 +++ b/plover/plover.h Mon Nov 02 19:04:58 2015 +0000 @@ -7,6 +7,8 @@ #include #include +G_BEGIN_DECLS + #define PLOVER_GENERAL_ERROR RAZOR_ERROR_DOMAIN('P','l','v',0) #define PLOVER_SCRIPTLET_ERROR RAZOR_ERROR_DOMAIN('P','l','v',1) #define PLOVER_RAZOR_ERROR plover_razor_error_quark() @@ -61,6 +63,8 @@ gchar *plover_default_prefix_for_vendor(const char *vendor); gchar *plover_pre_install_prefix(void); +void plover_purge_reports(const char *path); +gchar *plover_get_reports_directory(void); char *plover_get_program_directory(const char *argv0); GQuark plover_razor_error_quark(void); GQuark plover_posix_error_quark(void); @@ -92,6 +96,7 @@ const char *id); int plover_log_open(const char *path); +void plover_exception_handler_init(void); struct plover_vector *plover_vector_new(void); struct plover_vector *plover_vector_dup(struct plover_vector *old); @@ -102,4 +107,6 @@ char *plover_vector_format_for_display(struct plover_vector *vector); void plover_vector_free(struct plover_vector *vector); +G_END_DECLS + #endif /* __PLOVER_H__ */ diff -r 3ee18a3a0f58 -r a53fcb780468 plover/util.c --- a/plover/util.c Mon Nov 02 19:01:50 2015 +0000 +++ b/plover/util.c Mon Nov 02 19:04:58 2015 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, 2011, 2014 J. Ali Harlow + * Copyright (C) 2009, 2011, 2014, 2015 J. Ali Harlow * * 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 @@ -24,6 +24,8 @@ #include #include #endif +#include +#include #include "config.h" #include "plover.h" @@ -106,6 +108,124 @@ #endif } +#define MAX_REPORTS 12 + +struct plover_util_file { + gchar *name; + time_t mtime; +}; + +static int plover_util_compare_files(gconstpointer a,gconstpointer b) +{ + struct plover_util_file *fa=(struct plover_util_file *)a; + struct plover_util_file *fb=(struct plover_util_file *)b; + return fa->mtime-fb->mtime; +} + +/* + * Limit the number of reports to MAX_REPORTS + */ + +void plover_purge_reports(const char *path) +{ + const char *name; + GStatBuf sbuf; + int count=0; + GDir *d; + GError *err=NULL; + GList *files=NULL; + struct plover_util_file *file; + d=g_dir_open(path,0,&err); + if (!d) + { + if (g_error_matches(err,G_FILE_ERROR,G_FILE_ERROR_NOENT)) + g_mkdir_with_parents(path,0777); + return; + } + while(count<=MAX_REPORTS && g_dir_read_name(d)) + count++; + if (count>MAX_REPORTS) + { + g_dir_rewind(d); + while((name=g_dir_read_name(d))) + { + file=g_new(struct plover_util_file,1); + file->name=g_build_filename(path,name,NULL); + if (!g_stat(file->name,&sbuf)) + file->mtime=sbuf.st_mtime; + else + file->mtime=0; + files=g_list_prepend(files,file); + } + files=g_list_sort(files,plover_util_compare_files); + while(files) + { + file=(struct plover_util_file *)files->data; + if (count>MAX_REPORTS) + { + count--; + g_remove(file->name); + } + g_free(file->name); + g_free(file); + files=g_list_delete_link(files,files); + } + } + g_dir_close(d); +} + +gchar *plover_get_reports_directory(void) +{ + gchar *path=NULL; +#ifdef WIN32 + HKEY key; + DWORD rtype,nb; + int len; + long retval; + gunichar2 *str2; + char *dir; + retval=RegOpenKeyW(HKEY_LOCAL_MACHINE,L"Software\\Plover",&key); + if (SUCCEEDED(retval)) + { + nb=200; + str2=malloc(nb); + retval=RegQueryValueExW(key,L"Reports",0,&rtype,(void *)str2,&nb); + if (retval==ERROR_MORE_DATA) + { + g_free(str2); + str2=malloc(nb); + retval=RegQueryValueExW(key,L"Reports",0,NULL,(void *)str2,&nb); + } + if (SUCCEEDED(retval) && rtype==REG_SZ) + { + len=nb/2; + if (!str2[len-1]) /* Cope with unterminated strings */ + len--; + path=g_utf16_to_utf8(str2,len,NULL,NULL,NULL); + } + RegCloseKey(key); + g_free(str2); + } + if (!path) + { + WCHAR wpath[MAX_PATH]; + retval=SHGetFolderPathW(NULL,CSIDL_COMMON_APPDATA,NULL, + SHGFP_TYPE_CURRENT,wpath); + if (SUCCEEDED(retval)) + dir=g_utf16_to_utf8((const gunichar2 *)wpath,-1,NULL,NULL,NULL); + else + dir=g_strdup( + "C:\\Documents and Settings\\All Users\\Application Data"); + path=g_build_filename(dir,"plover","reports",NULL); + g_free(dir); + } +#else + path=g_strdup("/var/lib/plover/reports"); +#endif + plover_purge_reports(path); + return path; +} + /* * Get the directory containing the program executable. */ diff -r 3ee18a3a0f58 -r a53fcb780468 pre-inst/pre-inst.c --- a/pre-inst/pre-inst.c Mon Nov 02 19:01:50 2015 +0000 +++ b/pre-inst/pre-inst.c Mon Nov 02 19:04:58 2015 +0000 @@ -473,6 +473,7 @@ ShowWindow(GetConsoleWindow(),SW_HIDE); } #endif + plover_exception_handler_init(); if (argc>1 && !strcmp(argv[1],"-u")) { success=pre_uninstall(); diff -r 3ee18a3a0f58 -r a53fcb780468 setup/setup.c --- a/setup/setup.c Mon Nov 02 19:01:50 2015 +0000 +++ b/setup/setup.c Mon Nov 02 19:04:58 2015 +0000 @@ -112,6 +112,7 @@ int main(int argc,char **argv) { GError *error=NULL; + plover_exception_handler_init(); razor_set_lua_loader("posix",luaopen_posix); razor_set_lua_loader("whelk",luaopen_whelk); if (argc>1 && !strcmp(argv[1],"-u")) diff -r 3ee18a3a0f58 -r a53fcb780468 update/update.c --- a/update/update.c Mon Nov 02 19:01:50 2015 +0000 +++ b/update/update.c Mon Nov 02 19:04:58 2015 +0000 @@ -72,6 +72,7 @@ int main(int argc,char **argv) { + plover_exception_handler_init(); razor_set_lua_loader("posix",luaopen_posix); razor_set_lua_loader("whelk",luaopen_whelk); update(argv[0]);