summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen W. Taylor <otaylor@fishsoup.net>2010-12-22 15:40:53 -0500
committerOwen W. Taylor <otaylor@fishsoup.net>2010-12-22 15:40:53 -0500
commit4a4d68e58b0dd22b8447b40c3e5264b9a3797426 (patch)
tree211106cb7049393afafe53c12d71e6e74a88f82d
parent26e8791a022b337a6902b0883a588970a45e9243 (diff)
downloadgobject-introspection-4a4d68e58b0dd22b8447b40c3e5264b9a3797426.tar.gz
Fix error handling when writing out typelib
Return a non-zero result when opening the output file fails and don't use g_error() for other failures when writing out the file, since such errors should not produce a core dump.
-rw-r--r--tools/compiler.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/tools/compiler.c b/tools/compiler.c
index 7432760a..e3c3c556 100644
--- a/tools/compiler.c
+++ b/tools/compiler.c
@@ -45,7 +45,7 @@ gboolean include_cwd = FALSE;
gboolean debug = FALSE;
gboolean verbose = FALSE;
-static void
+static gboolean
write_out_typelib (gchar *prefix,
GITypelib *typelib)
{
@@ -56,6 +56,7 @@ write_out_typelib (gchar *prefix,
GFile *tmp_file_obj;
gchar *tmp_filename;
GError *error = NULL;
+ gboolean success = FALSE;
if (output == NULL)
{
@@ -81,16 +82,16 @@ write_out_typelib (gchar *prefix,
if (file == NULL)
{
- g_fprintf (stderr, "failed to open '%s': %s\n",
- tmp_filename, g_strerror (errno));
- goto out;
+ g_fprintf (stderr, "failed to open '%s': %s\n",
+ tmp_filename, g_strerror (errno));
+ goto out;
}
}
written = fwrite (typelib->data, 1, typelib->len, file);
if (written < typelib->len) {
- g_error ("ERROR: Could not write the whole output: %s",
- strerror(errno));
+ g_fprintf (stderr, "ERROR: Could not write the whole output: %s",
+ strerror(errno));
goto out;
}
@@ -100,13 +101,17 @@ write_out_typelib (gchar *prefix,
{
if (!g_file_move (tmp_file_obj, file_obj, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error))
{
- g_error ("ERROR: failed to rename %s to %s: %s", tmp_filename, filename, error->message);
+ g_fprintf (stderr, "ERROR: failed to rename %s to %s: %s", tmp_filename, filename, error->message);
g_clear_error (&error);
+ goto out;
}
}
+ success = TRUE;
out:
g_free (filename);
g_free (tmp_filename);
+
+ return success;
}
GLogLevelFlags logged_levels;
@@ -210,7 +215,8 @@ main (int argc, char ** argv)
g_error ("Invalid typelib for module '%s': %s",
module->name, error->message);
- write_out_typelib (NULL, typelib);
+ if (!write_out_typelib (NULL, typelib))
+ return 1;
g_typelib_free (typelib);
typelib = NULL;
}