- Timestamp:
- Oct 17, 2003, 9:51:17 PM (21 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
owl.c
r27c3a93 r2a2bb60 21 21 #include <sys/stat.h> 22 22 #include "owl.h" 23 24 #if OWL_STDERR_REDIR 25 #include <sys/ioctl.h> 26 int stderr_replace(void); 27 void stderr_redirect(int rfd); 28 #endif 23 29 24 30 static const char fileIdent[] = "$Id$"; … … 42 48 ZNotice_t notice; 43 49 #endif 50 #if OWL_STDERR_REDIR 51 int newstderr; 52 #endif 44 53 45 54 argcsave=argc; … … 136 145 #endif 137 146 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 138 153 139 154 /* create the owl directory, in case it does not exist */ … … 530 545 owl_function_makemsg("Unable to handle keypress"); 531 546 } 547 548 #if OWL_STDERR_REDIR 549 stderr_redirect(newstderr); 550 #endif 551 532 552 } 533 553 } … … 552 572 fprintf(stderr, " -t set the tty name\n"); 553 573 } 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. */ 581 int 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 */ 598 void 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 */
Note: See TracChangeset
for help on using the changeset viewer.