r20403 - gnucash/trunk/src - Bug #644556: Running the test as root happened to remove /dev/null. Check for this and also fix the respective test.
Christian Stimming
cstim at code.gnucash.org
Sat Mar 12 10:47:15 EST 2011
Author: cstim
Date: 2011-03-12 10:47:15 -0500 (Sat, 12 Mar 2011)
New Revision: 20403
Trac: http://svn.gnucash.org/trac/changeset/20403
Modified:
gnucash/trunk/src/backend/xml/gnc-backend-xml.c
gnucash/trunk/src/libqof/qof/qoflog.c
gnucash/trunk/src/libqof/qof/test/test-qof.c
Log:
Bug #644556: Running the test as root happened to remove /dev/null. Check for this and also fix the respective test.
Additionally, it turned out the log system never gave notice about
a log output file that was unwritable. Added an appropriate CRITICAL
error message.
Modified: gnucash/trunk/src/backend/xml/gnc-backend-xml.c
===================================================================
--- gnucash/trunk/src/backend/xml/gnc-backend-xml.c 2011-03-12 15:47:02 UTC (rev 20402)
+++ gnucash/trunk/src/backend/xml/gnc-backend-xml.c 2011-03-12 15:47:15 UTC (rev 20403)
@@ -684,6 +684,9 @@
rc = g_stat(datafile, &statbuf);
if (rc == 0)
{
+ /* We must never chmod the file /dev/null */
+ g_assert(safe_strcmp(tmp_name, "/dev/null") != 0);
+
/* Use the permissions from the original data file */
if (g_chmod(tmp_name, statbuf.st_mode) != 0)
{
Modified: gnucash/trunk/src/libqof/qof/qoflog.c
===================================================================
--- gnucash/trunk/src/libqof/qof/qoflog.c 2011-03-12 15:47:02 UTC (rev 20402)
+++ gnucash/trunk/src/libqof/qof/qoflog.c 2011-03-12 15:47:15 UTC (rev 20403)
@@ -139,6 +139,7 @@
void
qof_log_init_filename(const gchar* log_filename)
{
+ gboolean warn_about_missing_permission = FALSE;
if (log_table == NULL)
log_table = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, NULL);
@@ -160,14 +161,20 @@
* still isn't open. So we open normally with the file name and that's it. */
fout = fopen(fname, "wb");
#else
+ /* We must not overwrite /dev/null */
+ g_assert(safe_strcmp(log_filename, "/dev/null") != 0);
+
/* Windows prevents renaming of open files, so the next command silently fails there
* No problem, the filename on Winows will simply have the random characters */
g_rename(fname, log_filename);
fout = fdopen(fd, "w");
#endif
+ if (!fout)
+ warn_about_missing_permission = TRUE;
}
else
{
+ warn_about_missing_permission = TRUE;
fout = stderr;
}
g_free(fname);
@@ -179,6 +186,11 @@
// @@fixme really, the userdata is a struct { log_table, fout, previous_handler }
if (previous_handler == NULL)
previous_handler = g_log_set_default_handler(log4glib_handler, log_table);
+
+ if (warn_about_missing_permission)
+ {
+ g_critical("Cannot open log output file \"%s\", using stderr.", log_filename);
+ }
}
void
@@ -257,10 +269,12 @@
{
if (g_ascii_strcasecmp("stderr", log_to_filename) == 0)
{
+ qof_log_init();
qof_log_set_file(stderr);
}
else if (g_ascii_strcasecmp("stdout", log_to_filename) == 0)
{
+ qof_log_init();
qof_log_set_file(stdout);
}
else
Modified: gnucash/trunk/src/libqof/qof/test/test-qof.c
===================================================================
--- gnucash/trunk/src/libqof/qof/test/test-qof.c 2011-03-12 15:47:02 UTC (rev 20402)
+++ gnucash/trunk/src/libqof/qof/test/test-qof.c 2011-03-12 15:47:15 UTC (rev 20403)
@@ -35,7 +35,7 @@
{
g_type_init(); /* Initialize the GObject system */
g_test_init ( &argc, &argv, NULL ); /* initialize test program */
- qof_log_init_filename_special("/dev/null"); /* Init the log system */
+ qof_log_init_filename_special("stderr"); /* Init the log system */
g_test_bug_base("https://bugzilla.gnome.org/show_bug.cgi?id="); /* init the bugzilla URL */
test_suite_qofbook();
More information about the gnucash-changes
mailing list