Github user danobi commented on a diff in the pull request:

    https://github.com/apache/trafficserver/pull/568#discussion_r59888075
  
    --- Diff: lib/ts/Diags.cc ---
    @@ -816,29 +820,39 @@ Diags::set_stdout_output(const char *_bind_stdout)
       if (strcmp(_bind_stdout, "") == 0)
         return false;
     
    -  if (stdout_log) {
    -    delete stdout_log;
    -    stdout_log = NULL;
    -  }
    -
    -  // create backing BaseLogFile for stdout
    -  stdout_log = new BaseLogFile(_bind_stdout);
    +  BaseLogFile *old_stdout_log = stdout_log;
    +  BaseLogFile *new_stdout_log = new BaseLogFile(_bind_stdout);
     
       // on any errors we quit
    -  if (!stdout_log || stdout_log->open_file() != 
BaseLogFile::LOG_FILE_NO_ERROR) {
    +  if (!new_stdout_log || new_stdout_log->open_file() != 
BaseLogFile::LOG_FILE_NO_ERROR) {
         fprintf(stderr, "[Warning]: unable to open file=%s to bind stdout 
to\n", _bind_stdout);
    -    delete stdout_log;
    +    fprintf(stderr, "[Warning]: stdout is currently not bound to 
anything\n");
    +    delete new_stdout_log;
    +    lock();
         stdout_log = NULL;
    +    unlock();
         return false;
       }
    -  if (!stdout_log->m_fp) {
    +  if (!new_stdout_log->m_fp) {
         fprintf(stderr, "[Warning]: file pointer for stdout %s = NULL\n", 
_bind_stdout);
    -    delete stdout_log;
    +    fprintf(stderr, "[Warning]: stdout is currently not bound to 
anything\n");
    +    delete new_stdout_log;
    +    lock();
         stdout_log = NULL;
    +    unlock();
         return false;
       }
     
    -  return rebind_stdout(fileno(stdout_log->m_fp));
    +  // now exchange the stdout_log pointer
    +  lock();
    +  stdout_log = new_stdout_log;
    +  bool ret = rebind_stdout(fileno(new_stdout_log->m_fp));
    --- End diff --
    
    It should be fine.
    
    At that point in code, `m_fp` is guaranteed to be pointing to some open 
file. If `rebind_stdout()` fails, it's because (1) `fileno()` failed or (2) 
`dup2()` failed. If either of those happen, then there's really nothing we can 
do about it (AFAICT). So ATS will just plod along without `stdout` or `stderr` 
being bound to anything. Fortunately nobody should be writing directly to 
either of those streams so we should be in reasonable shape even if 
`rebind_...()` fails. Hopefully the next time the log files roll the error will 
correct itself.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to