Changeset 2a2bb60


Ignore:
Timestamp:
Oct 17, 2003, 9:51:17 PM (20 years ago)
Author:
Erik Nygren <nygren@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
e8b95f8
Parents:
27c3a93
Message:
2.0.9-pre-3
	Added testing feature for capturing stderr messages
	        from commands and displaying them in the errors buffer.
		This feature is disabled by default.
		Enable in owl.h with:  OWL_STDERR_REDIR 1
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r27c3a93 r2a2bb60  
    11$Id$
    22
     32.0.9-pre-3
     4        Added testing feature for capturing stderr messages
     5                from commands and displaying them in the errors buffer.
     6                This feature is disabled by default.
     7                Enable in owl.h with:  OWL_STDERR_REDIR 1
     8       
    392.0.9-pre-2
    410        Better reporting of perl errors (both into the errqueue
  • functions.c

    rec6ff52 r2a2bb60  
    19721972  FILE *p;
    19731973
     1974#if OWL_STDERR_REDIR
     1975  redirect = " < /dev/null";
     1976#endif
     1977
    19741978  if (argc<2) {
    19751979    owl_function_error("Wrong number of arguments to the exec command");
  • owl.c

    r27c3a93 r2a2bb60  
    2121#include <sys/stat.h>
    2222#include "owl.h"
     23
     24#if OWL_STDERR_REDIR
     25#include <sys/ioctl.h>
     26int stderr_replace(void);
     27void stderr_redirect(int rfd);
     28#endif
    2329
    2430static const char fileIdent[] = "$Id$";
     
    4248  ZNotice_t notice;
    4349#endif
     50#if OWL_STDERR_REDIR
     51  int newstderr;
     52#endif
    4453
    4554  argcsave=argc;
     
    136145#endif
    137146  owl_global_set_haveaim(&g);
     147
     148#if OWL_STDERR_REDIR
     149  /* Do this only after we've started curses up... */ 
     150  newstderr = stderr_replace();
     151#endif   
     152
    138153 
    139154  /* create the owl directory, in case it does not exist */
     
    530545      owl_function_makemsg("Unable to handle keypress");
    531546    }
     547
     548#if OWL_STDERR_REDIR
     549    stderr_redirect(newstderr);
     550#endif   
     551
    532552  }
    533553}
     
    552572  fprintf(stderr, "  -t      set the tty name\n");
    553573}
     574
     575
     576
     577#if OWL_STDERR_REDIR
     578
     579/* Replaces stderr with a pipe so that we can read from it.
     580 * Returns the fd of the pipe from which stderr can be read. */
     581int stderr_replace(void) {
     582  int pipefds[2];
     583  if (0 != pipe(pipefds)) {
     584    perror("pipe");
     585    owl_function_debugmsg("stderr_replace: pipe FAILED\n");
     586    return -1;
     587  }
     588    owl_function_debugmsg("stderr_replace: pipe: %d,%d\n", pipefds[0], pipefds[1]);
     589  if (-1 == dup2(pipefds[1], 2 /*stderr*/)) {
     590    owl_function_debugmsg("stderr_replace: dup2 FAILED (%s)\n", strerror(errno));
     591    perror("dup2");
     592    return -1;
     593  }
     594  return pipefds[0];
     595}
     596
     597/* Sends stderr (read from rfd) messages to a file */
     598void stderr_redirect(int rfd) {
     599  int navail, bread;
     600  char *buf;
     601  /*owl_function_debugmsg("stderr_redirect: called with rfd=%d\n", rfd);*/
     602  if (rfd<0) return;
     603  if (-1 == ioctl(rfd, FIONREAD, (void*)&navail)) {
     604    return;
     605  }
     606  /*owl_function_debugmsg("stderr_redirect: navail = %d\n", navail);*/
     607  if (navail<=0) return;
     608  if (navail>256) { navail = 256; }
     609  buf = owl_malloc(navail+1);
     610  bread = read(rfd, buf, navail);
     611  if (buf[navail-1] != '\0') {
     612    buf[navail] = '\0';
     613  }
     614  owl_function_error("Err: %s", buf);
     615  owl_free(buf);
     616}
     617
     618#endif /* OWL_STDERR_REDIR */
  • owl.h

    r27c3a93 r2a2bb60  
    1717#endif
    1818
    19 
    20 
    2119static const char owl_h_fileIdent[] = "$Id$";
    2220
    23 #define OWL_VERSION         2.0.9-pre-2
    24 #define OWL_VERSION_STRING "2.0.9-pre-2"
     21#define OWL_VERSION         2.0.9-pre-3
     22#define OWL_VERSION_STRING "2.0.9-pre-3"
     23
     24/* Feature that is being tested to redirect stderr through a pipe.
     25 * There may still be some portability problems with this. */
     26#define OWL_STDERR_REDIR 1
    2527
    2628#define OWL_DEBUG 0
  • zwrite.c

    r836ea3a3 r2a2bb60  
    154154      openline=owl_malloc(strlen(zsigproc)+40);
    155155      strcpy(openline, zsigproc);
     156#if !(OWL_STDERR_REDIR)
    156157      strcat(openline, " 2> /dev/null");
     158#endif
    157159      file=popen(openline, "r");
    158160      owl_free(openline);
Note: See TracChangeset for help on using the changeset viewer.