# # # add_file "tests/t_pidfile_log_permissions.at" # content [dc4860c8b4eac27bbfddb9d3f16b14aafa2ad76b] # # patch "ChangeLog" # from [0f9eacffd4e80cf7f2e259d955e7ca106ff5c1a9] # to [f1b4f72fbde66dcea6a9d181cd27734fe9d3a435] # # patch "commands.cc" # from [efe7626fa7994ffcd89c71dd0bebfabb15d2cde0] # to [cde2422b6cf5dc41933fa697f6eb646cf5b8e350] # # patch "testsuite.at" # from [050da6d98d9f856078d7d0853e0cd9f6d5bc0600] # to [c019357dd13a84621e8991449c87ab04ebc47b95] # # patch "ui.cc" # from [e96508ed97ba6d356ebd6d7eca65883e614918f5] # to [4ab9ddcb20dd0800d73564d34c3d13384c99d18a] # ============================================================ --- tests/t_pidfile_log_permissions.at dc4860c8b4eac27bbfddb9d3f16b14aafa2ad76b +++ tests/t_pidfile_log_permissions.at dc4860c8b4eac27bbfddb9d3f16b14aafa2ad76b @@ -0,0 +1,33 @@ +AT_SETUP([pid file and log handles open failures]) +MTN_SETUP + +# --log should fail if it can't open the file. +AT_CHECK(touch inaccessible.log) +AT_CHECK(chmod 000 inaccessible.log) +AT_CHECK(MTN --log=inaccessible.log status, [1], [ignore], [ignore]) + +# and it should fail if the specified file is read only. +AT_CHECK(touch ro.log) +AT_CHECK(chmod 400 ro.log) +AT_CHECK(MTN --log=ro.log status, [1], [ignore], [ignore]) + +# it should also fail if the a parent directory of the file is not +# accessible. +AT_CHECK(mkdir noaccess) +AT_CHECK(chmod 100 noaccess) +AT_CHECK(MTN --log=noaccess/my.log status, [1], [ignore], [ignore]) + +NETSYNC_SETUP + +# --pid-file checks that the file doesn't exist. check that we fail if we +# can't create the specified file. +AT_CHECK(MTN serve --pid-file=noaccess/my.pid --bind=127.0.0.1:$_PORT testbranch, [1], [ignore], [ignore]) + +# no need to kill the server--if the test succeeded the server must have +# failed to start. + +AT_CHECK(chmod 600 inaccessible.log ro.log noaccess) +AT_CHECK(rm -f inaccessible.log ro.log) +AT_CHECK(rmdir noaccess) + +AT_CLEANUP ============================================================ --- ChangeLog 0f9eacffd4e80cf7f2e259d955e7ca106ff5c1a9 +++ ChangeLog f1b4f72fbde66dcea6a9d181cd27734fe9d3a435 @@ -1,3 +1,12 @@ +2006-04-12 Matthew Gregan + + * tests/t_pidfile_log_permissions.at: New test to check that we + fail properly if the specified pid or log file could not be + opened. Thanks to Matthew Nicholson for the bug report. + * testsuite.at: Add it. + * ui.cc (user_interface::redirect_log_to): Check that file is open. + * commands.cc (pid_file::pid_file): Ditto. + 2006-04-11 Nathaniel Smith * UPGRADE: Add a note that all certs will be re-issued, and all ============================================================ --- commands.cc efe7626fa7994ffcd89c71dd0bebfabb15d2cde0 +++ commands.cc cde2422b6cf5dc41933fa697f6eb646cf5b8e350 @@ -324,6 +324,7 @@ if (path.empty()) return; require_path_is_nonexistent(path, F("pid file '%s' already exists") % path); + E(file.is_open(), F("failed to create pid file '%s'") % path); file.open(path.as_external().c_str()); file << get_process_id() << endl; file.flush(); ============================================================ --- testsuite.at 050da6d98d9f856078d7d0853e0cd9f6d5bc0600 +++ testsuite.at c019357dd13a84621e8991449c87ab04ebc47b95 @@ -872,3 +872,5 @@ m4_include(tests/t_pidfile.at) m4_include(tests/t_rosterify_empty_manifest.at) m4_include(tests/t_netsync_no_include.at) +m4_include(tests/t_pidfile_log_permissions.at) + ============================================================ --- ui.cc e96508ed97ba6d356ebd6d7eca65883e614918f5 +++ ui.cc 4ab9ddcb20dd0800d73564d34c3d13384c99d18a @@ -429,6 +429,7 @@ if (filestr.is_open()) filestr.close(); filestr.open(filename.as_external().c_str(), ofstream::out | ofstream::app); + E(filestr.is_open(), F("failed to open log file '%s'") % filename); clog.rdbuf(filestr.rdbuf()); }