Changeset 4d9e311c


Ignore:
Timestamp:
Aug 12, 2012, 9:11:23 PM (12 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.9
Children:
ea0c453, 54d9b42, a8c55b5, 7c539a8
Parents:
0a9ffc5
git-author:
David Benjamin <davidben@mit.edu> (08/12/12 18:08:20)
git-committer:
David Benjamin <davidben@mit.edu> (08/12/12 21:11:23)
Message:
Don't do the stderr redirect hack if !isatty(2)

stderr has already been redirected, so there's no point. This way if
barnowl crashes, we have some hope of recovering the stderr by
redirecting it to a file first. The pipe hack is still evil, but this is
somewhat less insane.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • owl.c

    r8135737 r4d9e311c  
    1212#include <sys/stat.h>
    1313#include <locale.h>
     14#include <unistd.h>
    1415
    1516#if OWL_STDERR_REDIR
     
    427428  if (0 != pipe(pipefds)) {
    428429    perror("pipe");
    429     owl_function_debugmsg("stderr_replace: pipe FAILED\n");
     430    owl_function_debugmsg("stderr_replace: pipe FAILED");
    430431    return -1;
    431432  }
    432     owl_function_debugmsg("stderr_replace: pipe: %d,%d\n", pipefds[0], pipefds[1]);
    433   if (-1 == dup2(pipefds[1], 2 /*stderr*/)) {
    434     owl_function_debugmsg("stderr_replace: dup2 FAILED (%s)\n", strerror(errno));
     433    owl_function_debugmsg("stderr_replace: pipe: %d,%d", pipefds[0], pipefds[1]);
     434  if (-1 == dup2(pipefds[1], STDERR_FILENO)) {
     435    owl_function_debugmsg("stderr_replace: dup2 FAILED (%s)", strerror(errno));
    435436    perror("dup2");
    436437    return -1;
     
    514515#if OWL_STDERR_REDIR
    515516  /* Do this only after we've started curses up... */
    516   owl_function_debugmsg("startup: doing stderr redirection");
    517   channel = g_io_channel_unix_new(stderr_replace());
    518   g_io_add_watch(channel, G_IO_IN | G_IO_HUP | G_IO_ERR, &stderr_redirect_handler, NULL);
    519   g_io_channel_unref(channel);
     517  if (isatty(STDERR_FILENO)) {
     518    owl_function_debugmsg("startup: doing stderr redirection");
     519    channel = g_io_channel_unix_new(stderr_replace());
     520    g_io_add_watch(channel, G_IO_IN | G_IO_HUP | G_IO_ERR, &stderr_redirect_handler, NULL);
     521    g_io_channel_unref(channel);
     522  }
    520523#endif
    521524
Note: See TracChangeset for help on using the changeset viewer.