Patch fixing error message bug in gnome-system-log
- From: Jack Grahl <mnvl16 yahoo co uk>
- To: gnome-utils-list gnome org
- Subject: Patch fixing error message bug in gnome-system-log
- Date: Thu, 06 Sep 2007 21:56:39 -0000
Hi there,
I have written a patch for the app gnome-system-log which fixes a reported bug; that if the program can't open a file, it gives the same error message as if it can't parse the file "X is not a log file" (bug #349756 on bugs.gnome.org). As modified, there is now a different error message if the file can't be opened.
The patch is against version 2.19, however there don't seem to be any recent changes so the patch should work just as well against the more recent versions. The patch introduces two new user message strings which need to be translated. I wasn't sure what to do about this - I have used the correct macro, it seems that the list of translatable strings is generated automatically??
Hope the patch can be applied, let me know if there are any issues or questions.
Yours, Jack Grahl
--- logrtns.c.orig 2007-08-23 10:25:18.000000000 +0100
+++ logrtns.c 2007-09-06 22:47:03.000000000 +0100
@@ -36,7 +36,7 @@
char *error_main = N_("One file or more could not be opened");
-static LogStats *log_stats_new (char *filename, gboolean show_error);
+static int log_stats_new (LogStats **stats_ref, char *filename, gboolean show_error);
/* File checking */
@@ -104,12 +104,13 @@
file_is_log (char *filename, gboolean show_error)
{
LogStats *stats;
+ int s;
if (filename == NULL)
return FALSE;
- stats = log_stats_new (filename, show_error);
- if (stats==NULL)
+ s = log_stats_new (&stats, filename, show_error);
+ if (s!=0)
return FALSE;
else {
g_free (stats);
@@ -303,11 +304,11 @@
/*
log_stats_new
Read the log and get some statistics from it.
- Returns NULL if the file is not a log.
+ Returns an non-zero error code if it cannot open or parse the file.
*/
-static LogStats *
-log_stats_new (char *filename, gboolean show_error)
+static int
+log_stats_new (LogStats** stats_ref, char *filename, gboolean show_error)
{
GnomeVFSResult result;
GnomeVFSFileInfo *info;
@@ -318,12 +319,12 @@
char *found_space;
if (filename == NULL)
- return NULL;
+ return 1;
/* Read first line and check that it is text */
result = gnome_vfs_open (&handle, filename, GNOME_VFS_OPEN_READ);
if (result != GNOME_VFS_OK) {
- return NULL;
+ return 2;
}
info = gnome_vfs_file_info_new ();
@@ -331,20 +332,20 @@
if (result != GNOME_VFS_OK || info->type != GNOME_VFS_FILE_TYPE_REGULAR) {
gnome_vfs_file_info_unref (info);
gnome_vfs_close (handle);
- return NULL;
+ return -1;
}
result = gnome_vfs_read (handle, buff, sizeof(buff), &size);
gnome_vfs_close (handle);
if (result != GNOME_VFS_OK) {
gnome_vfs_file_info_unref (info);
- return NULL;
+ return -1;
}
found_space = g_strstr_len (buff, 1024, " ");
if (found_space == NULL) {
gnome_vfs_file_info_unref (info);
- return NULL;
+ return -1;
}
stats = g_new (LogStats, 1);
@@ -352,7 +353,8 @@
stats->file_size = info->size;
gnome_vfs_file_info_unref (info);
- return (stats);
+ *stats_ref = stats;
+ return (0);
}
Log *
@@ -365,13 +367,14 @@
int i, size;
GList *days;
Log *log;
+ int err;
- stats = log_stats_new (filename, show_error);
- if (stats == NULL) {
+ err = log_stats_new (&stats, filename, show_error);
+ if (err != 0) {
if (file_is_zipped (filename)) {
zipped_name = g_strdup_printf ("%s#gzip:", filename);
- stats = log_stats_new (filename, show_error);
- if (stats == NULL) {
+ err = log_stats_new (&stats, filename, show_error);
+ if (err != 0) {
opened = FALSE;
}
} else
@@ -379,8 +382,17 @@
}
if (opened == FALSE) {
+ switch( err ) {
+ case 2:
+ error_message = g_strdup_printf (_("File with no name"));
+ goto error;
+ case 1:
+ error_message = g_strdup_printf (_("Could not open file %s"), filename);
+ goto error;
+ default:
error_message = g_strdup_printf (_("%s is not a log file."), filename);
goto error;
+ }
}
log = g_new0 (Log, 1);
@@ -477,7 +489,7 @@
void log_stats_reload (Log *log)
{
g_free (log->stats);
- log->stats = log_stats_new (log->name, TRUE);
+ log_stats_new (&log->stats, log->name, TRUE);
}
/* log_read_new_lines */
---[end of patch]---
___________________________________________________________
Want ideas for reducing your carbon footprint? Visit Yahoo! For Good http://uk.promotions.yahoo.com/forgood/environment.html
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]