2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-25 06:05:25 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-25 06:05:25 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1997-11-25 06:05:25 +08:00
|
|
|
* (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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-07-16 20:49:04 +08:00
|
|
|
|
1999-02-21 07:20:54 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2006-06-17 00:21:35 +08:00
|
|
|
#define _GNU_SOURCE /* need the POSIX signal API */
|
2006-05-30 09:55:42 +08:00
|
|
|
|
1999-02-21 07:20:54 +08:00
|
|
|
#include <stdlib.h>
|
2018-02-08 10:01:39 +08:00
|
|
|
#include <string.h>
|
1999-02-21 07:20:54 +08:00
|
|
|
#ifdef HAVE_UNISTD_H
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <unistd.h>
|
1999-02-21 07:20:54 +08:00
|
|
|
#endif
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2013-10-15 07:58:39 +08:00
|
|
|
#include <gio/gio.h>
|
2018-02-08 10:52:54 +08:00
|
|
|
#include <glib/gstdio.h>
|
2000-07-16 20:49:04 +08:00
|
|
|
|
2018-02-13 07:11:44 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
|
|
|
#include <gegl.h>
|
|
|
|
|
2004-01-24 01:24:44 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2003-10-22 02:14:58 +08:00
|
|
|
|
2001-12-02 05:02:34 +08:00
|
|
|
#include "core/core-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-12-02 05:02:34 +08:00
|
|
|
#include "core/gimp.h"
|
2018-02-13 07:11:44 +08:00
|
|
|
#include "core/gimpdrawable.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
#include "core/gimpitem.h"
|
|
|
|
#include "core/gimpparamspecs.h"
|
|
|
|
|
2020-01-04 03:08:12 +08:00
|
|
|
#include "config/gimpcoreconfig.h"
|
|
|
|
|
2018-02-13 07:11:44 +08:00
|
|
|
#include "pdb/gimppdb.h"
|
2001-08-07 08:06:06 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "errors.h"
|
2020-08-02 15:52:34 +08:00
|
|
|
#include "gimp-log.h"
|
1999-09-28 01:58:10 +08:00
|
|
|
|
1999-10-05 03:26:07 +08:00
|
|
|
#ifdef G_OS_WIN32
|
app/appenv.h New file. Includes <math.h>. Move G_PI, RINT(), ROUND() etc
1999-09-01 Tor Lillqvist <tml@iki.fi>
* app/appenv.h
* libgimp/gimpmath.h: New file. Includes <math.h>. Move G_PI,
RINT(), ROUND() etc from app/appenv.h here, so plug-ins can
use them, too. Remove some commented-out old stuff in appenv.h.
* libgimp/gimp.h: Include gimpmath.h.
* libgimp/gimp.c (gimp_main): Win32: Don't install signal
handlers, we can't do anything useful in the handler ourselves
anyway (it would be nice to print out a backtrace, but that seems
pretty hard to do, even if not impossible). Let Windows inform the
user about the crash. If the plug-in was compiled with MSVC, and
the user also has it, she is offered a chance to start the
debugger automatically anyway.
* app/*several*.c: Include gimpmath.h for G_PI etc. Don't include
<math.h>, as gimpmath.h includes it.
* plug-ins/*/*many*.c: Include config.h. Don't include <math.h>.
Remove all the duplicated definitions of G_PI and rint(). Use
RINT() instead of rint().
* app/app_procs.[ch]: app_exit() takes a gboolean.
* app/batch.c
* app/commands.c
* app/interface.c: Call app_exit() with FALSE or TRUE.
* app/main.c (on_error): Call gimp_fatal_error. (main): Don't
install any signal handler on Win32 here, either.
* app/errors.c (gimp_fatal_error, gimp_terminate): Win32: Format
the message and call MessageBox with it. g_on_error_query doesn't
do anything useful on Win32, and printf'ing a message to stdout or
stderr doesn't do anything, either, in a windowing application.
1999-09-02 04:30:56 +08:00
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2003-09-10 00:47:59 +08:00
|
|
|
/* private variables */
|
|
|
|
|
2020-08-02 15:52:34 +08:00
|
|
|
static Gimp *the_errors_gimp = NULL;
|
|
|
|
static gboolean use_debug_handler = FALSE;
|
|
|
|
static GimpStackTraceMode stack_trace_mode = GIMP_STACK_TRACE_QUERY;
|
|
|
|
static gchar *full_prog_name = NULL;
|
|
|
|
static gchar *backtrace_file = NULL;
|
|
|
|
static gchar *backup_path = NULL;
|
|
|
|
static GFile *backup_file = NULL;
|
|
|
|
static GimpLogHandler log_domain_handler = 0;
|
|
|
|
static guint global_handler_id = 0;
|
2003-09-10 00:47:59 +08:00
|
|
|
|
2001-12-02 05:02:34 +08:00
|
|
|
|
|
|
|
/* local function prototypes */
|
|
|
|
|
2018-01-23 10:38:46 +08:00
|
|
|
static void gimp_message_log_func (const gchar *log_domain,
|
|
|
|
GLogLevelFlags flags,
|
|
|
|
const gchar *message,
|
|
|
|
gpointer data);
|
|
|
|
static void gimp_error_log_func (const gchar *domain,
|
|
|
|
GLogLevelFlags flags,
|
|
|
|
const gchar *message,
|
|
|
|
gpointer data) G_GNUC_NORETURN;
|
2001-12-02 05:02:34 +08:00
|
|
|
|
2018-01-23 10:38:46 +08:00
|
|
|
static G_GNUC_NORETURN void gimp_eek (const gchar *reason,
|
|
|
|
const gchar *message,
|
|
|
|
gboolean use_handler);
|
2001-12-02 05:02:34 +08:00
|
|
|
|
2006-09-10 00:36:15 +08:00
|
|
|
|
2001-12-02 05:02:34 +08:00
|
|
|
/* public functions */
|
|
|
|
|
2003-09-10 00:47:59 +08:00
|
|
|
void
|
2006-09-10 01:31:28 +08:00
|
|
|
errors_init (Gimp *gimp,
|
|
|
|
const gchar *_full_prog_name,
|
|
|
|
gboolean _use_debug_handler,
|
2018-01-27 04:20:52 +08:00
|
|
|
GimpStackTraceMode _stack_trace_mode,
|
|
|
|
const gchar *_backtrace_file)
|
2003-09-10 00:47:59 +08:00
|
|
|
{
|
2006-09-10 00:36:15 +08:00
|
|
|
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
2003-09-10 00:47:59 +08:00
|
|
|
g_return_if_fail (_full_prog_name != NULL);
|
2003-10-24 18:19:33 +08:00
|
|
|
g_return_if_fail (full_prog_name == NULL);
|
2003-09-10 00:47:59 +08:00
|
|
|
|
2004-02-05 08:34:50 +08:00
|
|
|
#ifdef GIMP_UNSTABLE
|
2005-11-04 19:08:02 +08:00
|
|
|
g_printerr ("This is a development version of GIMP. "
|
2006-04-12 20:49:29 +08:00
|
|
|
"Debug messages may appear here.\n\n");
|
2004-02-05 08:34:50 +08:00
|
|
|
#endif /* GIMP_UNSTABLE */
|
2003-10-22 02:14:58 +08:00
|
|
|
|
2006-09-10 00:36:15 +08:00
|
|
|
the_errors_gimp = gimp;
|
2003-09-10 00:47:59 +08:00
|
|
|
use_debug_handler = _use_debug_handler ? TRUE : FALSE;
|
|
|
|
stack_trace_mode = _stack_trace_mode;
|
|
|
|
full_prog_name = g_strdup (_full_prog_name);
|
2018-02-21 21:39:43 +08:00
|
|
|
|
|
|
|
/* Create parent directories for both the crash and backup files. */
|
|
|
|
backtrace_file = g_path_get_dirname (_backtrace_file);
|
2018-02-13 07:11:44 +08:00
|
|
|
backup_path = g_build_filename (gimp_directory (), "backups", NULL);
|
|
|
|
|
2018-02-21 21:39:43 +08:00
|
|
|
g_mkdir_with_parents (backtrace_file, S_IRUSR | S_IWUSR | S_IXUSR);
|
|
|
|
g_free (backtrace_file);
|
|
|
|
backtrace_file = g_strdup (_backtrace_file);
|
|
|
|
|
2018-02-13 07:11:44 +08:00
|
|
|
g_mkdir_with_parents (backup_path, S_IRUSR | S_IWUSR | S_IXUSR);
|
|
|
|
g_free (backup_path);
|
|
|
|
backup_path = g_build_filename (gimp_directory (), "backups",
|
|
|
|
"backup-XXX.xcf", NULL);
|
2003-05-29 19:34:30 +08:00
|
|
|
|
2020-07-30 21:53:54 +08:00
|
|
|
backup_file = g_file_new_for_path (backup_path);
|
|
|
|
|
2020-08-02 15:52:34 +08:00
|
|
|
log_domain_handler = gimp_log_set_handler (FALSE,
|
|
|
|
G_LOG_LEVEL_WARNING |
|
|
|
|
G_LOG_LEVEL_MESSAGE |
|
|
|
|
G_LOG_LEVEL_CRITICAL,
|
|
|
|
gimp_message_log_func, gimp);
|
|
|
|
|
2018-05-04 03:43:19 +08:00
|
|
|
global_handler_id = g_log_set_handler (NULL,
|
|
|
|
G_LOG_LEVEL_ERROR | G_LOG_FLAG_FATAL,
|
|
|
|
gimp_error_log_func, gimp);
|
removed the gimp_busy boolean, check whether user_installation is needed
2001-07-10 Michael Natterer <mitch@gimp.org>
* app/app_procs.[ch]: removed the gimp_busy boolean, check whether
user_installation is needed here, not in user_install.c, parse
gtkrc an friends only if(!no_interface), create the Gimp object
before parsing gimp's rc files an pas it to the parse functions,
many other cleanups.
* app/appenums.h: added MessageHandlerType and StackTraceMode.
* app/appenv.h: removed MessageHandlerType, declare all global
variables from main.c (no more hidden global stuff please).
* app/errors.[ch]: added the fatal message func here (from main.c),
removed the StackTraceMode enum.
* app/gimprc.[ch]: renamed functions to gimprc_*(), pass a Gimp
pointer to some functions.
* app/gimpunit.c
* app/unitrc.h: ok, this is ugly: renamed all functions to
_gimp_unit_*() and made them public. The unit list is part
of the Gimp object now, so pass a Gimp* to all functions.
* app/libgimp_glue.[ch]: added EEKy wrappers for all gimp_unit_*()
functions which are used by widgets.
* app/main.c: cleaned up the global variables, removed the fatal
message handler, call app_init() directly, not via the
user_install stuff, misc. cleanups.
* app/user_install.[ch]: removed the check if user_installation is
needed (done by app_procs.c now).
* app/core/gimp.[ch]: added the user_unit list and the "busy"
boolean. Moved gimp_[set|unset]_busy() here. Added
gimp_initialize() which is called after unitrc and gimprc are
parsed.
* app/batch.c
* app/colormaps.c
* app/devices.c
* app/disp_callbacks.c
* app/gdisplay_ops.c
* app/gimphelp.c
* app/module_db.c
* app/nav_window.c
* app/plug_in.c
* app/core/gimpcontext.c
* app/core/gimpdatafiles.c
* app/core/gimpimage-convert.c
* app/core/gimpimage-duplicate.c
* app/core/gimpimage.c
* app/core/gimpparasite.c
* app/core/gimpparasitelist.h
* app/gui/file-open-dialog.c
* app/gui/gui.[ch]
* app/gui/info-dialog.c
* app/gui/info-window.c
* app/gui/preferences-dialog.c
* app/gui/session.c
* app/gui/tips-dialog.c
* app/gui/toolbox.c
* app/tools/gimpblendtool.c
* app/tools/gimpbucketfilltool.c
* app/tools/gimpcolorpickertool.c
* app/tools/gimpfuzzyselecttool.c
* app/tools/gimptransformtool.c
* app/tools/tool_manager.c
* app/widgets/gimpcolorpanel.c
* app/widgets/gimpcursor.c
* app/xcf/xcf-load.c
* app/xcf/xcf-save.c
* app/xcf/xcf.c
* tools/pdbgen/Makefile.am
* tools/pdbgen/app.pl
* tools/pdbgen/enums.pl
* tools/pdbgen/pdb/image.pdb
* tools/pdbgen/pdb/message.pdb
* tools/pdbgen/pdb/unit.pdb
* app/pdb/image_cmds.c
* app/pdb/message_cmds.c
* app/pdb/unit_cmds.c: changed accordingly, minor cleanups.
2001-07-11 03:16:16 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2007-06-13 17:27:32 +08:00
|
|
|
void
|
|
|
|
errors_exit (void)
|
|
|
|
{
|
2020-08-02 15:52:34 +08:00
|
|
|
if (log_domain_handler)
|
|
|
|
{
|
|
|
|
gimp_log_remove_handler (log_domain_handler);
|
|
|
|
|
|
|
|
log_domain_handler = 0;
|
|
|
|
}
|
2018-05-04 03:43:19 +08:00
|
|
|
|
2020-08-02 15:52:34 +08:00
|
|
|
if (global_handler_id)
|
|
|
|
{
|
|
|
|
g_log_remove_handler (NULL, global_handler_id);
|
2018-05-04 03:43:19 +08:00
|
|
|
|
2020-08-02 15:52:34 +08:00
|
|
|
global_handler_id = 0;
|
|
|
|
}
|
2018-05-04 03:43:19 +08:00
|
|
|
|
2007-06-13 17:27:32 +08:00
|
|
|
the_errors_gimp = NULL;
|
2018-01-27 04:20:52 +08:00
|
|
|
|
|
|
|
if (backtrace_file)
|
|
|
|
g_free (backtrace_file);
|
2018-02-13 07:11:44 +08:00
|
|
|
if (full_prog_name)
|
|
|
|
g_free (full_prog_name);
|
|
|
|
if (backup_path)
|
|
|
|
g_free (backup_path);
|
2020-07-30 21:53:54 +08:00
|
|
|
if (backup_file)
|
|
|
|
g_object_unref (backup_file);
|
2007-06-13 17:27:32 +08:00
|
|
|
}
|
|
|
|
|
2018-03-23 02:29:35 +08:00
|
|
|
GList *
|
|
|
|
errors_recovered (void)
|
|
|
|
{
|
|
|
|
GList *recovered = NULL;
|
|
|
|
gchar *backup_path = g_build_filename (gimp_directory (), "backups", NULL);
|
|
|
|
GDir *backup_dir = NULL;
|
|
|
|
|
|
|
|
if ((backup_dir = g_dir_open (backup_path, 0, NULL)))
|
|
|
|
{
|
|
|
|
const gchar *file;
|
|
|
|
|
|
|
|
while ((file = g_dir_read_name (backup_dir)))
|
|
|
|
{
|
|
|
|
if (g_str_has_suffix (file, ".xcf"))
|
|
|
|
{
|
|
|
|
gchar *path = g_build_filename (backup_path, file, NULL);
|
|
|
|
|
|
|
|
if (g_file_test (path, G_FILE_TEST_IS_REGULAR) &&
|
|
|
|
! g_file_test (path, G_FILE_TEST_IS_SYMLINK))
|
|
|
|
{
|
|
|
|
/* A quick basic security check. It is not foolproof,
|
|
|
|
* but better than nothing to make sure we are not
|
|
|
|
* trying to read, then delete a folder or a symlink
|
|
|
|
* to a file outside the backup directory.
|
|
|
|
*/
|
|
|
|
recovered = g_list_append (recovered, path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_free (path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_dir_close (backup_dir);
|
|
|
|
}
|
|
|
|
g_free (backup_path);
|
|
|
|
|
|
|
|
return recovered;
|
|
|
|
}
|
|
|
|
|
removed the gimp_busy boolean, check whether user_installation is needed
2001-07-10 Michael Natterer <mitch@gimp.org>
* app/app_procs.[ch]: removed the gimp_busy boolean, check whether
user_installation is needed here, not in user_install.c, parse
gtkrc an friends only if(!no_interface), create the Gimp object
before parsing gimp's rc files an pas it to the parse functions,
many other cleanups.
* app/appenums.h: added MessageHandlerType and StackTraceMode.
* app/appenv.h: removed MessageHandlerType, declare all global
variables from main.c (no more hidden global stuff please).
* app/errors.[ch]: added the fatal message func here (from main.c),
removed the StackTraceMode enum.
* app/gimprc.[ch]: renamed functions to gimprc_*(), pass a Gimp
pointer to some functions.
* app/gimpunit.c
* app/unitrc.h: ok, this is ugly: renamed all functions to
_gimp_unit_*() and made them public. The unit list is part
of the Gimp object now, so pass a Gimp* to all functions.
* app/libgimp_glue.[ch]: added EEKy wrappers for all gimp_unit_*()
functions which are used by widgets.
* app/main.c: cleaned up the global variables, removed the fatal
message handler, call app_init() directly, not via the
user_install stuff, misc. cleanups.
* app/user_install.[ch]: removed the check if user_installation is
needed (done by app_procs.c now).
* app/core/gimp.[ch]: added the user_unit list and the "busy"
boolean. Moved gimp_[set|unset]_busy() here. Added
gimp_initialize() which is called after unitrc and gimprc are
parsed.
* app/batch.c
* app/colormaps.c
* app/devices.c
* app/disp_callbacks.c
* app/gdisplay_ops.c
* app/gimphelp.c
* app/module_db.c
* app/nav_window.c
* app/plug_in.c
* app/core/gimpcontext.c
* app/core/gimpdatafiles.c
* app/core/gimpimage-convert.c
* app/core/gimpimage-duplicate.c
* app/core/gimpimage.c
* app/core/gimpparasite.c
* app/core/gimpparasitelist.h
* app/gui/file-open-dialog.c
* app/gui/gui.[ch]
* app/gui/info-dialog.c
* app/gui/info-window.c
* app/gui/preferences-dialog.c
* app/gui/session.c
* app/gui/tips-dialog.c
* app/gui/toolbox.c
* app/tools/gimpblendtool.c
* app/tools/gimpbucketfilltool.c
* app/tools/gimpcolorpickertool.c
* app/tools/gimpfuzzyselecttool.c
* app/tools/gimptransformtool.c
* app/tools/tool_manager.c
* app/widgets/gimpcolorpanel.c
* app/widgets/gimpcursor.c
* app/xcf/xcf-load.c
* app/xcf/xcf-save.c
* app/xcf/xcf.c
* tools/pdbgen/Makefile.am
* tools/pdbgen/app.pl
* tools/pdbgen/enums.pl
* tools/pdbgen/pdb/image.pdb
* tools/pdbgen/pdb/message.pdb
* tools/pdbgen/pdb/unit.pdb
* app/pdb/image_cmds.c
* app/pdb/message_cmds.c
* app/pdb/unit_cmds.c: changed accordingly, minor cleanups.
2001-07-11 03:16:16 +08:00
|
|
|
void
|
2008-11-04 20:33:09 +08:00
|
|
|
gimp_fatal_error (const gchar *message)
|
removed the gimp_busy boolean, check whether user_installation is needed
2001-07-10 Michael Natterer <mitch@gimp.org>
* app/app_procs.[ch]: removed the gimp_busy boolean, check whether
user_installation is needed here, not in user_install.c, parse
gtkrc an friends only if(!no_interface), create the Gimp object
before parsing gimp's rc files an pas it to the parse functions,
many other cleanups.
* app/appenums.h: added MessageHandlerType and StackTraceMode.
* app/appenv.h: removed MessageHandlerType, declare all global
variables from main.c (no more hidden global stuff please).
* app/errors.[ch]: added the fatal message func here (from main.c),
removed the StackTraceMode enum.
* app/gimprc.[ch]: renamed functions to gimprc_*(), pass a Gimp
pointer to some functions.
* app/gimpunit.c
* app/unitrc.h: ok, this is ugly: renamed all functions to
_gimp_unit_*() and made them public. The unit list is part
of the Gimp object now, so pass a Gimp* to all functions.
* app/libgimp_glue.[ch]: added EEKy wrappers for all gimp_unit_*()
functions which are used by widgets.
* app/main.c: cleaned up the global variables, removed the fatal
message handler, call app_init() directly, not via the
user_install stuff, misc. cleanups.
* app/user_install.[ch]: removed the check if user_installation is
needed (done by app_procs.c now).
* app/core/gimp.[ch]: added the user_unit list and the "busy"
boolean. Moved gimp_[set|unset]_busy() here. Added
gimp_initialize() which is called after unitrc and gimprc are
parsed.
* app/batch.c
* app/colormaps.c
* app/devices.c
* app/disp_callbacks.c
* app/gdisplay_ops.c
* app/gimphelp.c
* app/module_db.c
* app/nav_window.c
* app/plug_in.c
* app/core/gimpcontext.c
* app/core/gimpdatafiles.c
* app/core/gimpimage-convert.c
* app/core/gimpimage-duplicate.c
* app/core/gimpimage.c
* app/core/gimpparasite.c
* app/core/gimpparasitelist.h
* app/gui/file-open-dialog.c
* app/gui/gui.[ch]
* app/gui/info-dialog.c
* app/gui/info-window.c
* app/gui/preferences-dialog.c
* app/gui/session.c
* app/gui/tips-dialog.c
* app/gui/toolbox.c
* app/tools/gimpblendtool.c
* app/tools/gimpbucketfilltool.c
* app/tools/gimpcolorpickertool.c
* app/tools/gimpfuzzyselecttool.c
* app/tools/gimptransformtool.c
* app/tools/tool_manager.c
* app/widgets/gimpcolorpanel.c
* app/widgets/gimpcursor.c
* app/xcf/xcf-load.c
* app/xcf/xcf-save.c
* app/xcf/xcf.c
* tools/pdbgen/Makefile.am
* tools/pdbgen/app.pl
* tools/pdbgen/enums.pl
* tools/pdbgen/pdb/image.pdb
* tools/pdbgen/pdb/message.pdb
* tools/pdbgen/pdb/unit.pdb
* app/pdb/image_cmds.c
* app/pdb/message_cmds.c
* app/pdb/unit_cmds.c: changed accordingly, minor cleanups.
2001-07-11 03:16:16 +08:00
|
|
|
{
|
2001-12-02 05:02:34 +08:00
|
|
|
gimp_eek ("fatal error", message, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1998-04-11 13:07:52 +08:00
|
|
|
|
|
|
|
void
|
2008-11-04 20:33:09 +08:00
|
|
|
gimp_terminate (const gchar *message)
|
1998-04-11 13:07:52 +08:00
|
|
|
{
|
2001-12-02 05:02:34 +08:00
|
|
|
gimp_eek ("terminated", message, use_debug_handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2006-09-10 01:31:28 +08:00
|
|
|
static void
|
|
|
|
gimp_message_log_func (const gchar *log_domain,
|
|
|
|
GLogLevelFlags flags,
|
|
|
|
const gchar *message,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2018-02-13 20:16:27 +08:00
|
|
|
Gimp *gimp = data;
|
|
|
|
GimpCoreConfig *config = gimp->config;
|
|
|
|
const gchar *msg_domain = NULL;
|
|
|
|
GimpMessageSeverity severity = GIMP_MESSAGE_WARNING;
|
|
|
|
gboolean gui_message = TRUE;
|
2018-02-13 00:20:53 +08:00
|
|
|
GimpDebugPolicy debug_policy;
|
2018-02-12 09:30:55 +08:00
|
|
|
|
|
|
|
/* All GIMP messages are processed under the same domain, but
|
|
|
|
* we need to keep the log domain information for third party
|
|
|
|
* messages.
|
|
|
|
*/
|
2020-09-22 23:52:32 +08:00
|
|
|
if (! log_domain ||
|
|
|
|
(! g_str_has_prefix (log_domain, "Gimp") &&
|
|
|
|
! g_str_has_prefix (log_domain, "LibGimp")))
|
2018-02-12 09:30:55 +08:00
|
|
|
msg_domain = log_domain;
|
2018-01-26 08:55:54 +08:00
|
|
|
|
2018-02-13 00:20:53 +08:00
|
|
|
/* If debug policy requires it, WARNING and CRITICAL errors must be
|
|
|
|
* routed for appropriate debugging.
|
|
|
|
*/
|
|
|
|
g_object_get (G_OBJECT (config),
|
|
|
|
"debug-policy", &debug_policy,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
switch (flags & G_LOG_LEVEL_MASK)
|
2018-01-23 10:38:46 +08:00
|
|
|
{
|
2018-02-13 00:20:53 +08:00
|
|
|
case G_LOG_LEVEL_WARNING:
|
2018-02-13 20:16:27 +08:00
|
|
|
severity = GIMP_MESSAGE_BUG_WARNING;
|
|
|
|
if (debug_policy > GIMP_DEBUG_POLICY_WARNING)
|
|
|
|
gui_message = FALSE;
|
2018-02-13 00:20:53 +08:00
|
|
|
break;
|
|
|
|
case G_LOG_LEVEL_CRITICAL:
|
2018-02-13 20:16:27 +08:00
|
|
|
severity = GIMP_MESSAGE_BUG_CRITICAL;
|
|
|
|
if (debug_policy > GIMP_DEBUG_POLICY_CRITICAL)
|
|
|
|
gui_message = FALSE;
|
2018-02-13 00:20:53 +08:00
|
|
|
break;
|
2018-01-23 10:38:46 +08:00
|
|
|
}
|
2006-09-10 01:31:28 +08:00
|
|
|
|
2018-02-13 20:16:27 +08:00
|
|
|
if (gimp && gui_message)
|
2006-09-10 01:31:28 +08:00
|
|
|
{
|
2018-02-12 09:30:55 +08:00
|
|
|
gimp_show_message (gimp, NULL, severity, msg_domain, message);
|
2006-09-10 01:31:28 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-13 00:42:23 +08:00
|
|
|
const gchar *reason = "Message";
|
|
|
|
|
|
|
|
gimp_enum_get_value (GIMP_TYPE_MESSAGE_SEVERITY, severity,
|
|
|
|
NULL, NULL, &reason, NULL);
|
app: make debugging preference finer-grained than a boolean.
Replacing the boolean property "generate-backtrace" by an enum
"debug-policy". This property allows one to choose whether to debug
WARNING, CRITICAL and FATAL (crashes), or CRITICAL and FATAL only, or
only FATAL, or finally nothing.
By default, a stable release will debug CRITICAL and crashes, and
unstable builds will start debugging at WARNINGs.
The reason for the settings is that if you stumble upon a reccurring bug
in your workflow (and this bug is not major enough for data corruption,
and "you can live with it"), you still have to wait for a new release.
At some point, you may want to disable getting a debug dialog, at least
temporarily. Oppositely, even when using a stable build, you may want to
obtain debug info for lesser issues, even WARNINGs, if you wish to help
the GIMP project.
It can be argued though whether the value GIMP_DEBUG_POLICY_NEVER is
really useful. There is nothing to gain from refusing debugging info
when the software crashed anyway. But I could still imagine that someone
is not interested in helping at all. It's sad but not like we are going
to force people to report. Let's just allow disabling the whole
debugging system.
2018-02-09 03:48:16 +08:00
|
|
|
|
|
|
|
g_printerr ("%s: %s-%s: %s\n",
|
|
|
|
gimp_filename_to_utf8 (full_prog_name),
|
|
|
|
log_domain, reason, message);
|
2006-09-10 01:31:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_error_log_func (const gchar *domain,
|
|
|
|
GLogLevelFlags flags,
|
|
|
|
const gchar *message,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gimp_fatal_error (message);
|
|
|
|
}
|
|
|
|
|
2001-12-02 05:02:34 +08:00
|
|
|
static void
|
|
|
|
gimp_eek (const gchar *reason,
|
|
|
|
const gchar *message,
|
|
|
|
gboolean use_handler)
|
|
|
|
{
|
2018-02-13 07:11:44 +08:00
|
|
|
GimpCoreConfig *config = the_errors_gimp->config;
|
|
|
|
gboolean eek_handled = FALSE;
|
|
|
|
GimpDebugPolicy debug_policy;
|
|
|
|
GList *iter;
|
|
|
|
gint num_idx;
|
|
|
|
gint i = 0;
|
2018-01-26 08:55:54 +08:00
|
|
|
|
|
|
|
/* GIMP has 2 ways to handle termination signals and fatal errors: one
|
|
|
|
* is the stack trace mode which is set at start as command line
|
|
|
|
* option --stack-trace-mode, this won't change for the length of the
|
|
|
|
* session and outputs a trace in terminal; the other is set in
|
|
|
|
* preferences, outputs a trace in a GUI and can change anytime during
|
|
|
|
* the session.
|
|
|
|
* The GUI backtrace has priority if it is set.
|
|
|
|
*/
|
|
|
|
g_object_get (G_OBJECT (config),
|
app: make debugging preference finer-grained than a boolean.
Replacing the boolean property "generate-backtrace" by an enum
"debug-policy". This property allows one to choose whether to debug
WARNING, CRITICAL and FATAL (crashes), or CRITICAL and FATAL only, or
only FATAL, or finally nothing.
By default, a stable release will debug CRITICAL and crashes, and
unstable builds will start debugging at WARNINGs.
The reason for the settings is that if you stumble upon a reccurring bug
in your workflow (and this bug is not major enough for data corruption,
and "you can live with it"), you still have to wait for a new release.
At some point, you may want to disable getting a debug dialog, at least
temporarily. Oppositely, even when using a stable build, you may want to
obtain debug info for lesser issues, even WARNINGs, if you wish to help
the GIMP project.
It can be argued though whether the value GIMP_DEBUG_POLICY_NEVER is
really useful. There is nothing to gain from refusing debugging info
when the software crashed anyway. But I could still imagine that someone
is not interested in helping at all. It's sad but not like we are going
to force people to report. Let's just allow disabling the whole
debugging system.
2018-02-09 03:48:16 +08:00
|
|
|
"debug-policy", &debug_policy,
|
2018-01-26 08:55:54 +08:00
|
|
|
NULL);
|
|
|
|
|
2018-01-27 06:47:11 +08:00
|
|
|
/* Let's just always output on stdout at least so that there is a
|
|
|
|
* trace if the rest fails. */
|
2018-04-09 12:08:48 +08:00
|
|
|
g_printerr ("%s: %s: %s\n", full_prog_name, reason, message);
|
removed the gimp_busy boolean, check whether user_installation is needed
2001-07-10 Michael Natterer <mitch@gimp.org>
* app/app_procs.[ch]: removed the gimp_busy boolean, check whether
user_installation is needed here, not in user_install.c, parse
gtkrc an friends only if(!no_interface), create the Gimp object
before parsing gimp's rc files an pas it to the parse functions,
many other cleanups.
* app/appenums.h: added MessageHandlerType and StackTraceMode.
* app/appenv.h: removed MessageHandlerType, declare all global
variables from main.c (no more hidden global stuff please).
* app/errors.[ch]: added the fatal message func here (from main.c),
removed the StackTraceMode enum.
* app/gimprc.[ch]: renamed functions to gimprc_*(), pass a Gimp
pointer to some functions.
* app/gimpunit.c
* app/unitrc.h: ok, this is ugly: renamed all functions to
_gimp_unit_*() and made them public. The unit list is part
of the Gimp object now, so pass a Gimp* to all functions.
* app/libgimp_glue.[ch]: added EEKy wrappers for all gimp_unit_*()
functions which are used by widgets.
* app/main.c: cleaned up the global variables, removed the fatal
message handler, call app_init() directly, not via the
user_install stuff, misc. cleanups.
* app/user_install.[ch]: removed the check if user_installation is
needed (done by app_procs.c now).
* app/core/gimp.[ch]: added the user_unit list and the "busy"
boolean. Moved gimp_[set|unset]_busy() here. Added
gimp_initialize() which is called after unitrc and gimprc are
parsed.
* app/batch.c
* app/colormaps.c
* app/devices.c
* app/disp_callbacks.c
* app/gdisplay_ops.c
* app/gimphelp.c
* app/module_db.c
* app/nav_window.c
* app/plug_in.c
* app/core/gimpcontext.c
* app/core/gimpdatafiles.c
* app/core/gimpimage-convert.c
* app/core/gimpimage-duplicate.c
* app/core/gimpimage.c
* app/core/gimpparasite.c
* app/core/gimpparasitelist.h
* app/gui/file-open-dialog.c
* app/gui/gui.[ch]
* app/gui/info-dialog.c
* app/gui/info-window.c
* app/gui/preferences-dialog.c
* app/gui/session.c
* app/gui/tips-dialog.c
* app/gui/toolbox.c
* app/tools/gimpblendtool.c
* app/tools/gimpbucketfilltool.c
* app/tools/gimpcolorpickertool.c
* app/tools/gimpfuzzyselecttool.c
* app/tools/gimptransformtool.c
* app/tools/tool_manager.c
* app/widgets/gimpcolorpanel.c
* app/widgets/gimpcursor.c
* app/xcf/xcf-load.c
* app/xcf/xcf-save.c
* app/xcf/xcf.c
* tools/pdbgen/Makefile.am
* tools/pdbgen/app.pl
* tools/pdbgen/enums.pl
* tools/pdbgen/pdb/image.pdb
* tools/pdbgen/pdb/message.pdb
* tools/pdbgen/pdb/unit.pdb
* app/pdb/image_cmds.c
* app/pdb/message_cmds.c
* app/pdb/unit_cmds.c: changed accordingly, minor cleanups.
2001-07-11 03:16:16 +08:00
|
|
|
|
2018-01-27 06:47:11 +08:00
|
|
|
#if ! defined (G_OS_WIN32) || defined (HAVE_EXCHNDL)
|
|
|
|
|
2001-12-02 05:02:34 +08:00
|
|
|
if (use_handler)
|
2000-05-11 05:21:23 +08:00
|
|
|
{
|
2018-01-26 09:17:13 +08:00
|
|
|
#ifndef GIMP_CONSOLE_COMPILATION
|
app: make debugging preference finer-grained than a boolean.
Replacing the boolean property "generate-backtrace" by an enum
"debug-policy". This property allows one to choose whether to debug
WARNING, CRITICAL and FATAL (crashes), or CRITICAL and FATAL only, or
only FATAL, or finally nothing.
By default, a stable release will debug CRITICAL and crashes, and
unstable builds will start debugging at WARNINGs.
The reason for the settings is that if you stumble upon a reccurring bug
in your workflow (and this bug is not major enough for data corruption,
and "you can live with it"), you still have to wait for a new release.
At some point, you may want to disable getting a debug dialog, at least
temporarily. Oppositely, even when using a stable build, you may want to
obtain debug info for lesser issues, even WARNINGs, if you wish to help
the GIMP project.
It can be argued though whether the value GIMP_DEBUG_POLICY_NEVER is
really useful. There is nothing to gain from refusing debugging info
when the software crashed anyway. But I could still imagine that someone
is not interested in helping at all. It's sad but not like we are going
to force people to report. Let's just allow disabling the whole
debugging system.
2018-02-09 03:48:16 +08:00
|
|
|
if (debug_policy != GIMP_DEBUG_POLICY_NEVER &&
|
2018-02-21 21:39:43 +08:00
|
|
|
! the_errors_gimp->no_interface &&
|
|
|
|
backtrace_file)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
2018-02-08 10:52:54 +08:00
|
|
|
FILE *fd;
|
|
|
|
gboolean has_backtrace = TRUE;
|
|
|
|
|
2018-01-27 23:43:43 +08:00
|
|
|
/* If GUI backtrace enabled (it is disabled by default), it
|
2018-01-26 08:55:54 +08:00
|
|
|
* takes precedence over the command line argument.
|
|
|
|
*/
|
2018-01-27 23:43:43 +08:00
|
|
|
#ifdef G_OS_WIN32
|
2018-02-04 21:09:22 +08:00
|
|
|
const gchar *gimpdebug = "gimp-debug-tool-" GIMP_TOOL_VERSION ".exe";
|
2018-01-28 22:12:10 +08:00
|
|
|
#elif defined (PLATFORM_OSX)
|
2018-02-04 21:09:22 +08:00
|
|
|
const gchar *gimpdebug = "gimp-debug-tool-" GIMP_TOOL_VERSION;
|
2018-01-28 22:12:10 +08:00
|
|
|
#else
|
2018-02-04 21:09:22 +08:00
|
|
|
const gchar *gimpdebug = LIBEXECDIR "/gimp-debug-tool-" GIMP_TOOL_VERSION;
|
2018-01-27 23:43:43 +08:00
|
|
|
#endif
|
2020-01-04 03:08:12 +08:00
|
|
|
gchar *args[9] = { (gchar *) gimpdebug, full_prog_name, NULL,
|
2018-01-27 04:20:52 +08:00
|
|
|
(gchar *) reason, (gchar *) message,
|
2020-01-04 03:08:12 +08:00
|
|
|
backtrace_file, the_errors_gimp->config->last_known_release,
|
|
|
|
NULL, NULL };
|
2018-01-26 08:55:54 +08:00
|
|
|
gchar pid[16];
|
2020-01-04 03:08:12 +08:00
|
|
|
gchar timestamp[16];
|
2018-01-26 08:55:54 +08:00
|
|
|
|
|
|
|
g_snprintf (pid, 16, "%u", (guint) getpid ());
|
|
|
|
args[2] = pid;
|
|
|
|
|
2020-05-19 21:56:27 +08:00
|
|
|
g_snprintf (timestamp, 16, "%"G_GINT64_FORMAT, the_errors_gimp->config->last_release_timestamp);
|
2020-01-04 03:08:12 +08:00
|
|
|
args[7] = timestamp;
|
|
|
|
|
2018-02-08 10:52:54 +08:00
|
|
|
#ifndef G_OS_WIN32
|
|
|
|
/* On Win32, the trace has already been processed by ExcHnl
|
|
|
|
* and is waiting for us in a text file.
|
|
|
|
*/
|
|
|
|
fd = g_fopen (backtrace_file, "w");
|
2018-02-22 19:35:43 +08:00
|
|
|
has_backtrace = gimp_stack_trace_print ((const gchar *) full_prog_name,
|
2018-02-09 08:57:03 +08:00
|
|
|
fd, NULL);
|
2018-02-08 10:52:54 +08:00
|
|
|
fclose (fd);
|
|
|
|
#endif
|
|
|
|
|
2018-01-26 08:55:54 +08:00
|
|
|
/* We don't care about any return value. If it fails, too
|
|
|
|
* bad, we just won't have any stack trace.
|
|
|
|
* We still need to use the sync() variant because we have
|
|
|
|
* to keep GIMP up long enough for the debugger to get its
|
|
|
|
* trace.
|
2018-01-25 21:32:39 +08:00
|
|
|
*/
|
2018-02-08 10:52:54 +08:00
|
|
|
if (has_backtrace &&
|
|
|
|
g_file_test (backtrace_file, G_FILE_TEST_IS_REGULAR) &&
|
2018-01-27 23:43:43 +08:00
|
|
|
g_spawn_async (NULL, args, NULL,
|
|
|
|
G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL | G_SPAWN_STDOUT_TO_DEV_NULL,
|
|
|
|
NULL, NULL, NULL, NULL))
|
|
|
|
eek_handled = TRUE;
|
2018-01-26 08:55:54 +08:00
|
|
|
}
|
2018-01-27 06:47:11 +08:00
|
|
|
#endif /* !GIMP_CONSOLE_COMPILATION */
|
|
|
|
|
|
|
|
#ifndef G_OS_WIN32
|
|
|
|
if (! eek_handled)
|
2018-01-26 08:55:54 +08:00
|
|
|
{
|
|
|
|
switch (stack_trace_mode)
|
|
|
|
{
|
|
|
|
case GIMP_STACK_TRACE_NEVER:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_STACK_TRACE_QUERY:
|
|
|
|
{
|
|
|
|
sigset_t sigset;
|
|
|
|
|
|
|
|
sigemptyset (&sigset);
|
|
|
|
sigprocmask (SIG_SETMASK, &sigset, NULL);
|
|
|
|
|
2018-05-13 19:49:33 +08:00
|
|
|
if (the_errors_gimp)
|
|
|
|
gimp_gui_ungrab (the_errors_gimp);
|
|
|
|
|
2018-02-22 19:35:43 +08:00
|
|
|
gimp_stack_trace_query ((const gchar *) full_prog_name);
|
2018-01-26 08:55:54 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_STACK_TRACE_ALWAYS:
|
|
|
|
{
|
|
|
|
sigset_t sigset;
|
|
|
|
|
|
|
|
sigemptyset (&sigset);
|
|
|
|
sigprocmask (SIG_SETMASK, &sigset, NULL);
|
|
|
|
|
2018-02-22 19:35:43 +08:00
|
|
|
gimp_stack_trace_print ((const gchar *) full_prog_name,
|
2018-02-09 08:57:03 +08:00
|
|
|
stdout, NULL);
|
2018-01-26 08:55:54 +08:00
|
|
|
}
|
|
|
|
break;
|
2006-04-12 20:49:29 +08:00
|
|
|
|
2018-01-26 08:55:54 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-04-12 20:49:29 +08:00
|
|
|
}
|
2018-01-27 06:47:11 +08:00
|
|
|
#endif /* ! G_OS_WIN32 */
|
2000-05-11 05:21:23 +08:00
|
|
|
}
|
2018-01-27 06:47:11 +08:00
|
|
|
#endif /* ! G_OS_WIN32 || HAVE_EXCHNDL */
|
2000-07-16 20:49:04 +08:00
|
|
|
|
2018-01-27 06:47:11 +08:00
|
|
|
#if defined (G_OS_WIN32) && ! defined (GIMP_CONSOLE_COMPILATION)
|
2000-07-16 20:49:04 +08:00
|
|
|
/* g_on_error_* don't do anything reasonable on Win32. */
|
2018-01-27 06:47:11 +08:00
|
|
|
if (! eek_handled && ! the_errors_gimp->no_interface)
|
|
|
|
MessageBox (NULL, g_strdup_printf ("%s: %s", reason, message),
|
|
|
|
full_prog_name, MB_OK|MB_ICONERROR);
|
|
|
|
#endif
|
2000-07-16 20:49:04 +08:00
|
|
|
|
2018-02-13 07:11:44 +08:00
|
|
|
/* Let's try to back-up all unsaved images!
|
|
|
|
* It is not 100%: when I tested with various bugs created on purpose,
|
|
|
|
* I had cases where saving failed. I am not sure if this is because
|
|
|
|
* of some memory management along the way to XCF saving or some other
|
|
|
|
* messed up state of GIMP, but this is normal not to expect too much
|
|
|
|
* during a crash.
|
|
|
|
* Nevertheless in various test cases, I had successful backups XCF of
|
|
|
|
* the work in progress. Yeah!
|
|
|
|
*/
|
2018-02-21 21:39:43 +08:00
|
|
|
if (backup_path)
|
|
|
|
{
|
2018-06-18 01:39:37 +08:00
|
|
|
/* increase the busy counter, so XCF saving calling
|
|
|
|
* gimp_set_busy() and gimp_unset_busy() won't call the GUI
|
|
|
|
* layer and do whatever windowing system calls to set cursors.
|
|
|
|
*/
|
|
|
|
the_errors_gimp->busy++;
|
|
|
|
|
2018-02-21 21:39:43 +08:00
|
|
|
/* The index of 'XXX' in backup_path string. */
|
|
|
|
num_idx = strlen (backup_path) - 7;
|
|
|
|
|
|
|
|
iter = gimp_get_image_iter (the_errors_gimp);
|
|
|
|
for (; iter && i < 1000; iter = iter->next)
|
|
|
|
{
|
|
|
|
GimpImage *image = iter->data;
|
2018-02-13 07:11:44 +08:00
|
|
|
|
2018-02-21 21:39:43 +08:00
|
|
|
if (! gimp_image_is_dirty (image))
|
|
|
|
continue;
|
2018-02-13 07:11:44 +08:00
|
|
|
|
2018-02-21 21:39:43 +08:00
|
|
|
/* This is a trick because we want to avoid any memory
|
|
|
|
* allocation when the process is abnormally terminated.
|
|
|
|
* We just assume that you'll never have more than 1000 images
|
|
|
|
* open (which is already far fetched).
|
|
|
|
*/
|
|
|
|
backup_path[num_idx + 2] = '0' + (i % 10);
|
|
|
|
backup_path[num_idx + 1] = '0' + ((i/10) % 10);
|
|
|
|
backup_path[num_idx] = '0' + ((i/100) % 10);
|
|
|
|
|
|
|
|
/* Saving. */
|
|
|
|
gimp_pdb_execute_procedure_by_name (the_errors_gimp->pdb,
|
|
|
|
gimp_get_user_context (the_errors_gimp),
|
|
|
|
NULL, NULL,
|
|
|
|
"gimp-xcf-save",
|
2020-07-30 20:17:02 +08:00
|
|
|
GIMP_TYPE_RUN_MODE, GIMP_RUN_NONINTERACTIVE,
|
|
|
|
GIMP_TYPE_IMAGE, image,
|
|
|
|
G_TYPE_INT, 0,
|
|
|
|
GIMP_TYPE_OBJECT_ARRAY, NULL,
|
2020-07-30 21:53:54 +08:00
|
|
|
G_TYPE_FILE, backup_file,
|
2018-02-21 21:39:43 +08:00
|
|
|
G_TYPE_NONE);
|
2020-07-30 21:53:54 +08:00
|
|
|
g_rename (g_file_peek_path (backup_file), backup_path);
|
2018-02-21 21:39:43 +08:00
|
|
|
i++;
|
|
|
|
}
|
2018-02-13 07:11:44 +08:00
|
|
|
}
|
|
|
|
|
2003-10-10 18:02:34 +08:00
|
|
|
exit (EXIT_FAILURE);
|
1998-04-11 13:07:52 +08:00
|
|
|
}
|