diff options
-rw-r--r-- | e-util/ChangeLog | 7 | ||||
-rw-r--r-- | e-util/e-logger.c | 44 |
2 files changed, 41 insertions, 10 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog index ce11387828..a6e4f80989 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,10 @@ +2008-06-09 Milan Crha <mcrha@redhat.com> + + ** Fix for bug #509595 + + * e-logger.c: (e_logger_get_logs): Do not crash if file does not + exists. Also be able to read lines more than 249 characters long. + 2008-06-08 Matthew Barnes <mbarnes@redhat.com> * e-logger.[ch]: Code cleanup. diff --git a/e-util/e-logger.c b/e-util/e-logger.c index a79793b045..9890cbd941 100644 --- a/e-util/e-logger.c +++ b/e-util/e-logger.c @@ -240,7 +240,6 @@ e_logger_get_logs (ELogger *logger, { FILE *fp; gchar buf[250]; - gboolean error = FALSE; g_return_if_fail (E_LOGGER (logger)); g_return_if_fail (func != NULL); @@ -248,17 +247,42 @@ e_logger_get_logs (ELogger *logger, /* Flush everything before we get the logs */ fflush (logger->priv->fp); fp = g_fopen (logger->priv->logfile, "r"); - while (!error || feof(fp)) { + + if (!fp) { + fprintf (stderr, "Cannot open log file '%s' for reading! No flush yet?\n", logger->priv->logfile ? logger->priv->logfile : "[null]"); + return; + } + + while (!feof (fp)) { gchar *tmp; - tmp = fgets (buf, 250, fp); + size_t len; + + tmp = fgets (buf, sizeof (buf), fp); if (!tmp) break; -#if 0 - if (strlen(tmp) == 249) { - /* FIXME: There may be more */ - } -#endif - func (tmp, data); + + len = strlen (tmp); + if (len > 0 && tmp [len - 1] != '\n' && !feof (fp)) { + /* there are more characters on a row than 249, so read them all */ + GString *str = g_string_sized_new (1024); + + g_string_append (str, tmp); + + while (!feof (fp) && len > 0 && tmp [len - 1] != '\n') { + tmp = fgets (buf, sizeof (buf), fp); + if (!tmp) + break; + + len = strlen (tmp); + g_string_append (str, tmp); + } + + func (str->str, data); + + g_string_free (str, TRUE); + } else + func (tmp, data); } - fclose(fp); + + fclose (fp); } |