Changeset 2244836


Ignore:
Timestamp:
Jun 22, 2011, 12:37:22 AM (13 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.8, release-1.9
Children:
a6a9ddb
Parents:
bbb7876
git-author:
David Benjamin <davidben@mit.edu> (05/24/11 01:42:07)
git-committer:
David Benjamin <davidben@mit.edu> (06/22/11 00:37:22)
Message:
Use g_io_add_watch in the stderr redirect

We may actually be able to put GIOChannel to good use here with
g_io_channel_read_line.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • owl.c

    rbbb7876 r2244836  
    450450
    451451/* Sends stderr (read from rfd) messages to the error console */
    452 void stderr_redirect_handler(const owl_io_dispatch *d, void *data)
     452gboolean stderr_redirect_handler(GIOChannel *source, GIOCondition condition, void *data)
    453453{
    454454  int navail, bread;
    455455  char buf[4096];
    456   int rfd = d->fd;
     456  int rfd = g_io_channel_unix_get_fd(source);
    457457  char *err;
    458458
    459   if (rfd<0) return;
     459  /* TODO: Use g_io_channel_read_line? We'd have to be careful about
     460   * blocking on the read. */
     461
     462  if (rfd<0) return TRUE;
    460463  if (-1 == ioctl(rfd, FIONREAD, &navail)) {
    461     return;
     464    return TRUE;
    462465  }
    463466  /*owl_function_debugmsg("stderr_redirect: navail = %d\n", navail);*/
    464   if (navail <= 0) return;
     467  if (navail <= 0) return TRUE;
    465468  if (navail > sizeof(buf)-1) {
    466469    navail = sizeof(buf)-1;
     
    468471  bread = read(rfd, buf, navail);
    469472  if (bread == -1)
    470     return;
     473    return TRUE;
    471474
    472475  err = g_strdup_printf("[stderr]\n%.*s", bread, buf);
     
    474477  owl_function_log_err(err);
    475478  g_free(err);
     479  return TRUE;
    476480}
    477481
     
    521525  /* Do this only after we've started curses up... */
    522526  owl_function_debugmsg("startup: doing stderr redirection");
    523   owl_select_add_io_dispatch(stderr_replace(), OWL_IO_READ, &stderr_redirect_handler, NULL, NULL);
     527  channel = g_io_channel_unix_new(stderr_replace());
     528  g_io_add_watch(channel, G_IO_IN | G_IO_HUP | G_IO_ERR, &stderr_redirect_handler, NULL);
     529  g_io_channel_unref(channel);
    524530#endif
    525531
Note: See TracChangeset for help on using the changeset viewer.