[PATCH xorg-gtest 2/2] Check if log file and old log file are writable before starting X server

Chase Douglas chase.douglas at canonical.com
Mon Jun 4 10:09:29 PDT 2012


On 05/29/2012 11:20 PM, Peter Hutterer wrote:
> On Fri, May 25, 2012 at 08:22:11AM -0700, Chase Douglas wrote:
>> Otherwise, the server will fail to start and it won't be obvious what
>> happened.
>>
>> Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
>> ---
>>  src/environment.cpp |   26 ++++++++++++++++++++++++++
>>  1 file changed, 26 insertions(+)
>>
>> diff --git a/src/environment.cpp b/src/environment.cpp
>> index 68e05ce..a3a8ead 100644
>> --- a/src/environment.cpp
>> +++ b/src/environment.cpp
>> @@ -36,6 +36,7 @@
>>  #include <csignal>
>>  #include <cstdlib>
>>  #include <cstring>
>> +#include <fstream>
>>  #include <iostream>
>>  #include <stdexcept>
>>  
>> @@ -114,6 +115,31 @@ void xorg::testing::Environment::SetUp() {
>>      throw std::runtime_error(message);
>>    }
>>  
>> +  /* The Xorg server won't start unless the log file and the old log file are
>> +   * writable. */
>> +  std::ofstream log_test;
>> +  log_test.open(d_->path_to_log_file.c_str(), std::ofstream::out);
>> +  log_test.close();
>> +  if (log_test.fail()) {
>> +    std::string message;
>> +    message += "X.org server log file ";
>> +    message += d_->path_to_log_file;
>> +    message += " is not writable.";
>> +    throw std::runtime_error(message);
>> +  }
>> +
>> +  std::string old_log_file = d_->path_to_log_file.c_str();
>> +  old_log_file += ".old";
>> +  log_test.open(old_log_file.c_str(), std::ofstream::out);
>> +  log_test.close();
>> +  if (log_test.fail()) {
>> +    std::string message;
>> +    message += "X.org old server log file ";
>> +    message += old_log_file;
>> +    message += " is not writable.";
>> +    throw std::runtime_error(message);
>> +  }
>> +
> 
> access(2) may be simpler?

At first glance, it looks like it would be simpler. However, access()
doesn't use the effective uid and gid, in case someone made a test suid,
and you have to check if a file exists before you can check if it is
writeable.

> Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net> anyhow though, it
> does the job

Thanks, both patches are now pushed.

-- Chase


More information about the xorg-devel mailing list