gimp/app/errors.c

503 lines
16 KiB
C
Raw Normal View History

/* GIMP - The GNU Image Manipulation Program
1997-11-25 06:05:25 +08:00
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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
* 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
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1997-11-25 06:05:25 +08:00
*/
#include "config.h"
#define _GNU_SOURCE /* need the POSIX signal API */
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
1997-11-25 06:05:25 +08:00
#include <unistd.h>
#endif
1997-11-25 06:05:25 +08:00
#include <gio/gio.h>
#include <glib/gstdio.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "libgimpbase/gimpbase.h"
#include "core/core-types.h"
#include "core/gimp.h"
#include "core/gimpdrawable.h"
#include "core/gimpimage.h"
#include "core/gimpitem.h"
#include "core/gimpparamspecs.h"
#include "pdb/gimppdb.h"
1997-11-25 06:05:25 +08:00
#include "errors.h"
app/Makefile.am app/gimphelp.[ch] new files 1999-09-27 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/gimphelp.[ch] * app/gimpui.[ch]: new files * app/interface.[ch] * app/preferences_dialog.[ch] The GIMP Help System part 1: Press "F1" in any dialog to pop up the help page for this dialog. Moved the widget constructors from preferences_dialog.[ch] and the query boxes from interface.[ch] to gimpui.[ch]. The dialog constructors take a help_func and a help_data parameter and install the "F1" accelerator which emits the new "help" signal. The "help" signal callback calls help_func(help_data) which finally has to call gimp_help() which in turn invokes the help browser. Still have to find a proper way to (1) prevent "F1" being assigned to some menu item and (2) to catch "F1" while browsing the menu trees in order to pop up the help for the selected item. * app/menus.c: a <Toolbox>/File/Help... menu item. * app/commands.[ch]: a command callback for the "Help..." menu item. * app/gimprc.[ch]: new boolean gimprc variable "use_help". * app/info_dialog.[ch]: pass a help function and data to the info dialog constructor. * app/tools.[ch]: store the tools help page names in the tool info structure. Export a special tools_help_func() which shows the help page for the active tool. * app/[all files calling a dialog constructor]: pass the dialog's help page to the constructor. Most dialogs are now created by gimp_dialog_new() which also sets up the action_area and the WM delete event callback, so I removed the resp. code from these files. Fixed some minor bugs and did some other stuff but didn't change any logic except dialog creation. * plug-ins/helpbrowser/helpbrowser.c: don't try to call a running help browser and don't install any menu path (all done in app/gimphelp.[ch] now).
1999-09-28 01:58:10 +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
/* private variables */
static const gchar * const log_domains[] =
{
"Gimp",
"Gimp-Actions",
"Gimp-Base",
"Gimp-Composite",
"Gimp-Config",
"Gimp-Core",
"Gimp-Dialogs",
"Gimp-Display",
"Gimp-File",
"Gimp-GEGL",
"Gimp-GUI",
"Gimp-Menus",
"Gimp-Operations",
"Gimp-PDB",
"Gimp-Paint",
"Gimp-Paint-Funcs",
"Gimp-Plug-In",
"Gimp-Text",
"Gimp-Tools",
"Gimp-Vectors",
"Gimp-Widgets",
"Gimp-XCF",
"LibGimpBase",
"LibGimpColor",
"LibGimpConfig",
"LibGimpMath",
"LibGimpModule",
"LibGimpThumb",
"LibGimpWidgets"
};
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 guint log_domain_handler_ids[G_N_ELEMENTS (log_domains)];
static guint gegl_handler_id = 0;
static guint global_handler_id = 0;
/* local function prototypes */
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;
static G_GNUC_NORETURN void gimp_eek (const gchar *reason,
const gchar *message,
gboolean use_handler);
/* public functions */
void
errors_init (Gimp *gimp,
const gchar *_full_prog_name,
gboolean _use_debug_handler,
GimpStackTraceMode _stack_trace_mode,
const gchar *_backtrace_file)
{
gint i;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (_full_prog_name != NULL);
g_return_if_fail (full_prog_name == NULL);
#ifdef GIMP_UNSTABLE
g_printerr ("This is a development version of GIMP. "
"Debug messages may appear here.\n\n");
#endif /* GIMP_UNSTABLE */
the_errors_gimp = gimp;
use_debug_handler = _use_debug_handler ? TRUE : FALSE;
stack_trace_mode = _stack_trace_mode;
full_prog_name = g_strdup (_full_prog_name);
/* Create parent directories for both the crash and backup files. */
backtrace_file = g_path_get_dirname (_backtrace_file);
backup_path = g_build_filename (gimp_directory (), "backups", NULL);
g_mkdir_with_parents (backtrace_file, S_IRUSR | S_IWUSR | S_IXUSR);
g_free (backtrace_file);
backtrace_file = g_strdup (_backtrace_file);
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);
for (i = 0; i < G_N_ELEMENTS (log_domains); i++)
log_domain_handler_ids[i] = g_log_set_handler (log_domains[i],
G_LOG_LEVEL_WARNING |
G_LOG_LEVEL_MESSAGE |
G_LOG_LEVEL_CRITICAL,
gimp_message_log_func, gimp);
gegl_handler_id = g_log_set_handler ("GEGL",
G_LOG_LEVEL_WARNING |
G_LOG_LEVEL_MESSAGE |
G_LOG_LEVEL_CRITICAL,
gimp_message_log_func, gimp);
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
void
errors_exit (void)
{
gint i;
for (i = 0; i < G_N_ELEMENTS (log_domains); i++)
g_log_remove_handler (log_domains[i], log_domain_handler_ids[i]);
g_log_remove_handler ("GEGL", gegl_handler_id);
g_log_remove_handler (NULL, global_handler_id);
the_errors_gimp = NULL;
if (backtrace_file)
g_free (backtrace_file);
if (full_prog_name)
g_free (full_prog_name);
if (backup_path)
g_free (backup_path);
}
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
bumped minimum required version of GLib to 2.18.0. 2008-11-04 Sven Neumann <sven@sven> * configure.in: bumped minimum required version of GLib to 2.18.0. * INSTALL: document the updated dependency. * app/core/gimp.[ch]: introduced gimp_message_literal(), a variant of gimp_message() that takes a literal string. * app/errors.[ch]: removed format arguments from gimp_fatal_error() and gimp_terminate() and let them take a literal string instead. * app/tools/gimptool.[ch]: introduced gimp_tool_message_literal(), a variant of gimp_tool_message() that takes a literal string. * app/actions/documents-commands.c * app/actions/drawable-commands.c * app/actions/edit-commands.c * app/actions/error-console-commands.c * app/actions/file-commands.c * app/actions/gradients-commands.c * app/actions/image-commands.c * app/actions/layers-commands.c * app/actions/palettes-commands.c * app/actions/plug-in-commands.c * app/actions/select-commands.c * app/actions/vectors-commands.c * app/config/gimprc.c * app/core/gimp-modules.c * app/core/gimp-parasites.c * app/core/gimp-templates.c * app/core/gimp-units.c * app/core/gimpchannel.c * app/core/gimpcontainer-filter.c * app/core/gimpdrawable-bucket-fill.c * app/core/gimpimage-convert.c * app/core/gimpimage-merge.c * app/core/gimpimage.c * app/core/gimpimagefile.c * app/core/gimplayer-floating-sel.c * app/core/gimplayer.c * app/core/gimpselection.c * app/dialogs/convert-dialog.c * app/dialogs/dialogs.c * app/dialogs/palette-import-dialog.c * app/dialogs/preferences-dialog.c * app/dialogs/quit-dialog.c * app/dialogs/stroke-dialog.c * app/display/gimpdisplayshell-dnd.c * app/file/file-open.c * app/file/file-procedure.c * app/file/file-save.c * app/file/file-utils.c * app/gegl/gimpcurvesconfig.c * app/gegl/gimplevelsconfig.c * app/gui/gui-message.c * app/gui/gui.c * app/gui/session.c * app/paint/gimpbrushcore.c * app/paint/gimpclone.c * app/paint/gimpheal.c * app/paint/gimpperspectiveclone.c * app/paint/gimpsourcecore.c * app/pdb/gimppdb-utils.c * app/pdb/gimpprocedure.c * app/plug-in/gimpplugin-message.c * app/plug-in/gimpplugin.c * app/plug-in/gimppluginmanager-restore.c * app/plug-in/gimppluginprocedure.c * app/text/gimptextlayer.c * app/tools/gimp-tools.c * app/tools/gimpaligntool.c * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpbucketfilltool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcolorpickertool.c * app/tools/gimpcurvestool.c * app/tools/gimpdesaturatetool.c * app/tools/gimpeditselectiontool.c * app/tools/gimpforegroundselecttool.c * app/tools/gimpfreeselecttool.c * app/tools/gimpgegltool.c * app/tools/gimphuesaturationtool.c * app/tools/gimpimagemaptool-settings.c * app/tools/gimpiscissorstool.c * app/tools/gimplevelstool.c * app/tools/gimpmeasuretool.c * app/tools/gimppainttool.c * app/tools/gimpposterizetool.c * app/tools/gimpselectiontool.c * app/tools/gimpsourcetool.c * app/tools/gimpthresholdtool.c * app/tools/gimptransformtool.c * app/tools/gimpvectortool.c * app/widgets/gimpactionview.c * app/widgets/gimpcontrollerlist.c * app/widgets/gimpcontrollers.c * app/widgets/gimpdataeditor.c * app/widgets/gimpdevices.c * app/widgets/gimpdnd-xds.c * app/widgets/gimperrordialog.c * app/widgets/gimphelp.c * app/widgets/gimpitemtreeview.c * app/widgets/gimppdbdialog.c * app/widgets/gimpsettingsbox.c * app/widgets/gimpvectorstreeview.c * app/widgets/gimpwidgets-utils.c * app/xcf/xcf-load.c * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/edit.pdb * tools/pdbgen/pdb/floating_sel.pdb * tools/pdbgen/pdb/image.pdb: use the _literal variants for g_set_error(), gimp_message() and gimp_tool_message(). * app/pdb/convert-cmds.c * app/pdb/edit-cmds.c * app/pdb/floating-sel-cmds.c * app/pdb/image-cmds.c: regenerated. svn path=/trunk/; revision=27548
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
{
gimp_eek ("fatal error", message, TRUE);
1997-11-25 06:05:25 +08:00
}
void
bumped minimum required version of GLib to 2.18.0. 2008-11-04 Sven Neumann <sven@sven> * configure.in: bumped minimum required version of GLib to 2.18.0. * INSTALL: document the updated dependency. * app/core/gimp.[ch]: introduced gimp_message_literal(), a variant of gimp_message() that takes a literal string. * app/errors.[ch]: removed format arguments from gimp_fatal_error() and gimp_terminate() and let them take a literal string instead. * app/tools/gimptool.[ch]: introduced gimp_tool_message_literal(), a variant of gimp_tool_message() that takes a literal string. * app/actions/documents-commands.c * app/actions/drawable-commands.c * app/actions/edit-commands.c * app/actions/error-console-commands.c * app/actions/file-commands.c * app/actions/gradients-commands.c * app/actions/image-commands.c * app/actions/layers-commands.c * app/actions/palettes-commands.c * app/actions/plug-in-commands.c * app/actions/select-commands.c * app/actions/vectors-commands.c * app/config/gimprc.c * app/core/gimp-modules.c * app/core/gimp-parasites.c * app/core/gimp-templates.c * app/core/gimp-units.c * app/core/gimpchannel.c * app/core/gimpcontainer-filter.c * app/core/gimpdrawable-bucket-fill.c * app/core/gimpimage-convert.c * app/core/gimpimage-merge.c * app/core/gimpimage.c * app/core/gimpimagefile.c * app/core/gimplayer-floating-sel.c * app/core/gimplayer.c * app/core/gimpselection.c * app/dialogs/convert-dialog.c * app/dialogs/dialogs.c * app/dialogs/palette-import-dialog.c * app/dialogs/preferences-dialog.c * app/dialogs/quit-dialog.c * app/dialogs/stroke-dialog.c * app/display/gimpdisplayshell-dnd.c * app/file/file-open.c * app/file/file-procedure.c * app/file/file-save.c * app/file/file-utils.c * app/gegl/gimpcurvesconfig.c * app/gegl/gimplevelsconfig.c * app/gui/gui-message.c * app/gui/gui.c * app/gui/session.c * app/paint/gimpbrushcore.c * app/paint/gimpclone.c * app/paint/gimpheal.c * app/paint/gimpperspectiveclone.c * app/paint/gimpsourcecore.c * app/pdb/gimppdb-utils.c * app/pdb/gimpprocedure.c * app/plug-in/gimpplugin-message.c * app/plug-in/gimpplugin.c * app/plug-in/gimppluginmanager-restore.c * app/plug-in/gimppluginprocedure.c * app/text/gimptextlayer.c * app/tools/gimp-tools.c * app/tools/gimpaligntool.c * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpbucketfilltool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcolorpickertool.c * app/tools/gimpcurvestool.c * app/tools/gimpdesaturatetool.c * app/tools/gimpeditselectiontool.c * app/tools/gimpforegroundselecttool.c * app/tools/gimpfreeselecttool.c * app/tools/gimpgegltool.c * app/tools/gimphuesaturationtool.c * app/tools/gimpimagemaptool-settings.c * app/tools/gimpiscissorstool.c * app/tools/gimplevelstool.c * app/tools/gimpmeasuretool.c * app/tools/gimppainttool.c * app/tools/gimpposterizetool.c * app/tools/gimpselectiontool.c * app/tools/gimpsourcetool.c * app/tools/gimpthresholdtool.c * app/tools/gimptransformtool.c * app/tools/gimpvectortool.c * app/widgets/gimpactionview.c * app/widgets/gimpcontrollerlist.c * app/widgets/gimpcontrollers.c * app/widgets/gimpdataeditor.c * app/widgets/gimpdevices.c * app/widgets/gimpdnd-xds.c * app/widgets/gimperrordialog.c * app/widgets/gimphelp.c * app/widgets/gimpitemtreeview.c * app/widgets/gimppdbdialog.c * app/widgets/gimpsettingsbox.c * app/widgets/gimpvectorstreeview.c * app/widgets/gimpwidgets-utils.c * app/xcf/xcf-load.c * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/edit.pdb * tools/pdbgen/pdb/floating_sel.pdb * tools/pdbgen/pdb/image.pdb: use the _literal variants for g_set_error(), gimp_message() and gimp_tool_message(). * app/pdb/convert-cmds.c * app/pdb/edit-cmds.c * app/pdb/floating-sel-cmds.c * app/pdb/image-cmds.c: regenerated. svn path=/trunk/; revision=27548
2008-11-04 20:33:09 +08:00
gimp_terminate (const gchar *message)
{
gimp_eek ("terminated", message, use_debug_handler);
}
/* private functions */
static void
gimp_message_log_func (const gchar *log_domain,
GLogLevelFlags flags,
const gchar *message,
gpointer data)
{
Gimp *gimp = data;
GimpCoreConfig *config = gimp->config;
const gchar *msg_domain = NULL;
GimpMessageSeverity severity = GIMP_MESSAGE_WARNING;
gboolean gui_message = TRUE;
GimpDebugPolicy debug_policy;
/* All GIMP messages are processed under the same domain, but
* we need to keep the log domain information for third party
* messages.
*/
if (! g_str_has_prefix (log_domain, "Gimp") &&
! g_str_has_prefix (log_domain, "LibGimp"))
msg_domain = log_domain;
/* 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)
{
case G_LOG_LEVEL_WARNING:
severity = GIMP_MESSAGE_BUG_WARNING;
if (debug_policy > GIMP_DEBUG_POLICY_WARNING)
gui_message = FALSE;
break;
case G_LOG_LEVEL_CRITICAL:
severity = GIMP_MESSAGE_BUG_CRITICAL;
if (debug_policy > GIMP_DEBUG_POLICY_CRITICAL)
gui_message = FALSE;
break;
}
if (gimp && gui_message)
{
gimp_show_message (gimp, NULL, severity, msg_domain, message);
}
else
{
const gchar *reason = "Message";
gimp_enum_get_value (GIMP_TYPE_MESSAGE_SEVERITY, severity,
NULL, NULL, &reason, NULL);
g_printerr ("%s: %s-%s: %s\n",
gimp_filename_to_utf8 (full_prog_name),
log_domain, reason, message);
}
}
static void
gimp_error_log_func (const gchar *domain,
GLogLevelFlags flags,
const gchar *message,
gpointer data)
{
gimp_fatal_error (message);
}
static void
gimp_eek (const gchar *reason,
const gchar *message,
gboolean use_handler)
{
GimpCoreConfig *config = the_errors_gimp->config;
gboolean eek_handled = FALSE;
GimpDebugPolicy debug_policy;
GList *iter;
gint num_idx;
gint i = 0;
/* 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),
"debug-policy", &debug_policy,
NULL);
/* Let's just always output on stdout at least so that there is a
* trace if the rest fails. */
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
#if ! defined (G_OS_WIN32) || defined (HAVE_EXCHNDL)
if (use_handler)
{
#ifndef GIMP_CONSOLE_COMPILATION
if (debug_policy != GIMP_DEBUG_POLICY_NEVER &&
! the_errors_gimp->no_interface &&
backtrace_file)
{
FILE *fd;
gboolean has_backtrace = TRUE;
/* If GUI backtrace enabled (it is disabled by default), it
* takes precedence over the command line argument.
*/
#ifdef G_OS_WIN32
const gchar *gimpdebug = "gimp-debug-tool-" GIMP_TOOL_VERSION ".exe";
#elif defined (PLATFORM_OSX)
const gchar *gimpdebug = "gimp-debug-tool-" GIMP_TOOL_VERSION;
#else
const gchar *gimpdebug = LIBEXECDIR "/gimp-debug-tool-" GIMP_TOOL_VERSION;
#endif
gchar *args[7] = { (gchar *) gimpdebug, full_prog_name, NULL,
(gchar *) reason, (gchar *) message,
backtrace_file, NULL };
gchar pid[16];
g_snprintf (pid, 16, "%u", (guint) getpid ());
args[2] = pid;
#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");
has_backtrace = gimp_stack_trace_print ((const gchar *) full_prog_name,
fd, NULL);
fclose (fd);
#endif
/* 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.
*/
if (has_backtrace &&
g_file_test (backtrace_file, G_FILE_TEST_IS_REGULAR) &&
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;
}
#endif /* !GIMP_CONSOLE_COMPILATION */
#ifndef G_OS_WIN32
if (! eek_handled)
{
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);
if (the_errors_gimp)
gimp_gui_ungrab (the_errors_gimp);
gimp_stack_trace_query ((const gchar *) full_prog_name);
}
break;
case GIMP_STACK_TRACE_ALWAYS:
{
sigset_t sigset;
sigemptyset (&sigset);
sigprocmask (SIG_SETMASK, &sigset, NULL);
gimp_stack_trace_print ((const gchar *) full_prog_name,
stdout, NULL);
}
break;
default:
break;
}
}
#endif /* ! G_OS_WIN32 */
}
#endif /* ! G_OS_WIN32 || HAVE_EXCHNDL */
#if defined (G_OS_WIN32) && ! defined (GIMP_CONSOLE_COMPILATION)
/* g_on_error_* don't do anything reasonable on Win32. */
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
/* 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!
*/
if (backup_path)
{
/* 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++;
/* 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;
GimpItem *item;
if (! gimp_image_is_dirty (image))
continue;
item = GIMP_ITEM (gimp_image_get_active_drawable (image));
/* 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",
GIMP_TYPE_RUN_MODE, GIMP_RUN_NONINTERACTIVE,
GIMP_TYPE_IMAGE_ID, gimp_image_get_id (image),
GIMP_TYPE_DRAWABLE_ID, gimp_item_get_id (item),
G_TYPE_STRING, backup_path,
G_TYPE_STRING, backup_path,
G_TYPE_NONE);
i++;
}
}
exit (EXIT_FAILURE);
}