From 408dfd68823ae7fff4c67229dc71c054c8d1652d Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 9 Nov 2007 17:41:15 +0000 Subject: [PATCH] print error messages on file not found 2007-11-09 Paolo Bonzini * libgst/input.c: Return false if file cannot be opened by gst_process_file, and set errno appropriately. * libgst/files.c: Use errno on return from gst_process_file. * main.c: Use errno on return from gst_process_file. * gst-tool.c: Use errno on return from gst_process_file. git-archimport-id: bonzini@gnu.org--2004b/smalltalk--devo--2.2--patch-630 --- doc/gst.texi | 4 +++- gst-tool.c | 21 ++++++++++++++------- libgst/ChangeLog | 8 ++++++++ libgst/files.c | 3 ++- libgst/input.c | 9 +++++++-- main.c | 8 ++++++-- 6 files changed, 40 insertions(+), 13 deletions(-) diff --git a/doc/gst.texi b/doc/gst.texi index 71389f5c..5c32a058 100644 --- a/doc/gst.texi +++ b/doc/gst.texi @@ -4315,7 +4315,9 @@ char **argv; if (result != 0) exit (result < 0 ? 1 : result); - gst_process_file ("@var{source-file}", GST_DIR_KERNEL_SYSTEM); + if (!gst_process_file ("@var{source-file}", GST_DIR_KERNEL_SYSTEM)) + perror ("gst: couldn't load `@var{source-file}'"); + gst_invoke_hook (GST_ABOUT_TO_QUIT); exit (0); @} diff --git a/gst-tool.c b/gst-tool.c index 028d74b5..dfa3099f 100644 --- a/gst-tool.c +++ b/gst-tool.c @@ -61,6 +61,7 @@ #include #include #include +#include const char *program_name; const char *kernel_dir; @@ -355,23 +356,26 @@ main(int argc, const char **argv) { int smalltalk_argc; const char **smalltalk_argv; + const char *executable_name; int i; int result; - program_name = strrchr (argv[0], '/'); - if (program_name) - program_name++; + executable_name = strrchr (argv[0], '/'); + if (executable_name) + executable_name++; else - program_name = argv[0]; + executable_name = argv[0]; /* Check if used in the build tree. */ - if (!strcmp (program_name, "gst-tool") - || !strcmp (program_name, "lt-gst-tool")) + if (!strcmp (executable_name, "gst-tool") + || !strcmp (executable_name, "lt-gst-tool")) { argv++, argc--; program_name = argv[0]; flags |= GST_IGNORE_USER_FILES; } + else + program_name = executable_name; for (i = 0; ; i++) if (!tools[i].name) @@ -411,7 +415,10 @@ main(int argc, const char **argv) if (result != 0) exit (result < 0 ? 1 : result); - gst_process_file (tools[i].script, GST_DIR_KERNEL_SYSTEM); + if (!gst_process_file (tools[i].script, GST_DIR_KERNEL_SYSTEM)) + fprintf (stderr, "%s: Couldn't open kernel file `%s': %s\n", + executable_name, tools[i].script, strerror (errno)); + gst_invoke_hook (GST_ABOUT_TO_QUIT); exit (0); } diff --git a/libgst/ChangeLog b/libgst/ChangeLog index 3aa31d7e..2e8a1a72 100644 --- a/libgst/ChangeLog +++ b/libgst/ChangeLog @@ -1,3 +1,11 @@ +2007-11-09 Paolo Bonzini + + * libgst/input.c: Return false if file cannot be opened by + gst_process_file, and set errno appropriately. + * libgst/files.c: Use errno on return from gst_process_file. + * main.c: Use errno on return from gst_process_file. + * gst-tool.c: Use errno on return from gst_process_file. + 2007-10-25 Paolo Bonzini * libgst/re.c: Call init_re from exported functions. diff --git a/libgst/files.c b/libgst/files.c index 0fefb573..5c316a5b 100644 --- a/libgst/files.c +++ b/libgst/files.c @@ -565,7 +565,8 @@ load_standard_files (void) { if (!_gst_process_file (fileName, GST_DIR_KERNEL)) { - _gst_errorf ("can't find system file '%s'", fileName); + _gst_errorf ("couldn't load system file '%s': %s", fileName, + strerror (errno)); _gst_errorf ("image bootstrap failed, use option --kernel-directory"); return 1; } diff --git a/libgst/input.c b/libgst/input.c index 148e9a5f..256fbf68 100644 --- a/libgst/input.c +++ b/libgst/input.c @@ -844,8 +844,12 @@ _gst_process_file (const char *fileName, enum gst_file_dir dir) f = _gst_find_file (fileName, dir); if (!f) - return false; + { + errno = ENOENT; + return false; + } + errno = 0; fd = _gst_open_file (f, "r"); if (fd != -1) { @@ -857,10 +861,11 @@ _gst_process_file (const char *fileName, enum gst_file_dir dir) _gst_parse_stream (false); _gst_pop_stream (true); _gst_set_undeclared (old); + errno = 0; } xfree (f); - return (true); + return (fd != -1); } diff --git a/main.c b/main.c index b7c6cb4d..3beec65d 100644 --- a/main.c +++ b/main.c @@ -62,6 +62,7 @@ #include #include #include +#include #ifdef ENABLE_DISASSEMBLER #define TRUE_FALSE_ALREADY_DEFINED @@ -381,13 +382,16 @@ main(int argc, const char **argv) else { + errno = 0; if (!gst_process_file (file->file_name, file->kernel_path ? GST_DIR_BASE : GST_DIR_ABS)) { if (file->kernel_path) - fprintf (stderr, "gst: Couldn't open kernel file %s\n", file->file_name); + fprintf (stderr, "gst: Couldn't open kernel file `%s': %s\n", + file->file_name, strerror (errno)); else - fprintf (stderr, "gst: Couldn't open file %s\n", file->file_name); + fprintf (stderr, "gst: Couldn't open file `%s': %s\n", + file->file_name, strerror (errno)); } } }